public void T01_BasicBlock_Find()
{
string[] testvalues = { "test/1", "test/2", "test/3" };
byte[] databuffer;
// encode a buffer
{
MemoryStream ms = new MemoryStream();
// add some values to the block encoder
SegmentBlockBasicEncoder enc = new SegmentBlockBasicEncoder();
enc.setStream(ms);
for (int i = 0; i < testvalues.Length; i++) {
RecordKey tkey = new RecordKey().appendParsedKey(testvalues[i]);
RecordUpdate tupdate = RecordUpdate.WithPayload("data: " + testvalues[i]);
enc.add(tkey, tupdate);
}
enc.flush();
databuffer = ms.ToArray();
}
// test FindNext(key,equal_ok=true)
{
BlockAccessor rs = new BlockAccessor(databuffer);
SegmentBlockBasicDecoder decoder = new SegmentBlockBasicDecoder(rs);
for (int i = testvalues.Length -1; i >= 0; i--) {
RecordKey tkey = new RecordKey().appendParsedKey(testvalues[i]);
RecordUpdate tupdate = RecordUpdate.WithPayload("data: " + testvalues[i]);
KeyValuePair<RecordKey,RecordUpdate> row = decoder.FindNext(tkey, true);
Assert.AreEqual(tkey, row.Key, "record keys should match");
Assert.AreEqual(tupdate, row.Value, "record values should match:");
}
}
// test FindNext(key,equal_ok=false)
{
BlockAccessor rs = new BlockAccessor(databuffer);
SegmentBlockBasicDecoder decoder = new SegmentBlockBasicDecoder(rs);
for (int i = testvalues.Length - 2; i >= 0; i--) {
RecordKey tkey = new RecordKey().appendParsedKey(testvalues[i]);
RecordUpdate tupdate = RecordUpdate.WithPayload("data: " + testvalues[i]);
RecordKey fkey = new RecordKey().appendParsedKey(testvalues[i + 1]);
RecordUpdate fupdate = RecordUpdate.WithPayload("data: " + testvalues[i+1]);
KeyValuePair<RecordKey, RecordUpdate> row = decoder.FindNext(tkey, false);
Assert.AreEqual(fkey, row.Key, "findnext(,false) should find next key");
Assert.AreEqual(fupdate, row.Value, "findnext(,false) should finx next key (value was botched)");
}
// test for "next" after end of buffer, and we should get an exception
// test for "next" at beginning and we should get first
// test some random values in the middle
}
}