dbuf.endEvents(i);
}
long minDbusEventBufferScn = dbuf.getMinScn();
long expectedScn = minDbusEventBufferScn;
DbusEventIterator eventIterator = dbuf.acquireIterator("eventIterator");
DbusEventInternalWritable e= null;
int state = 0; // searching for min scn
long entryNum = 1;
while (eventIterator.hasNext())
{
e = eventIterator.next();
if (state == 0 && (e.sequence() >= minDbusEventBufferScn))
{
state = 1; // found min scn
}
if (state == 1)
{
assertEquals(expectedScn, e.sequence());
long ts = e.timestampInNanos();
assertEquals(ts, timeStamp + entryNum*1000*1000);
byte[] eventBytes = new byte[e.valueLength()];
e.value().get(eventBytes);
assertEquals(eventBytes, testDataMap.get(entryNum).value.getBytes(Charset.defaultCharset()));
entryNum++;
e = eventIterator.next();
assertTrue(e.isEndOfPeriodMarker());
assertEquals(expectedScn, e.sequence());
expectedScn++;
}
}
dbuf.releaseIterator(eventIterator);
Assert.assertEquals(entryNum, numEntries);
// Reset the buffer with prevScn = 3, and verify
final long prevScn = 3;
dbuf.reset(prevScn);
assertTrue(dbuf.empty());
assertEquals(-1, dbuf.getMinScn());
assertEquals(prevScn, dbuf.getPrevScn());
testDataMap.clear();
long currentScn = prevScn;
// Add more events and make sure that the new events are in the buffer.
//dbuf.start(0);
valueLength = 25;
numEntries = 5;
// Now add entries to and make sure that they appear.
for (long i=1; i < numEntries; ++i)
{
// LOG.info("Iteration:"+i);
DbusEventKey key = new DbusEventKey(RngUtils.randomLong());
String value = RngUtils.randomString(valueLength);
dbuf.startEvents();
long ts = timeStamp + (i*1200*1000);
assertTrue(dbuf.appendEvent(key, pPartitionId, lPartitionId,ts, srcId, schemaId, value.getBytes(Charset.defaultCharset()), false));
testDataMap.put(i, new KeyValue(key, value));
dbuf.endEvents(currentScn + i);
}
minDbusEventBufferScn = dbuf.getMinScn();
assertEquals(minDbusEventBufferScn, prevScn+1);
expectedScn = minDbusEventBufferScn;
eventIterator = dbuf.acquireIterator("eventIterator2");
state = 0; // searching for min scn
entryNum = 1;
while (eventIterator.hasNext())
{
e = eventIterator.next();
if (state == 0)
{
if (e.sequence() >= minDbusEventBufferScn)
{
state = 1; // found min scn
}
}
if (state == 1)
{
assertEquals(expectedScn, e.sequence());
long ts = e.timestampInNanos();
assertEquals(ts, timeStamp + entryNum*1200*1000);
byte[] eventBytes = new byte[e.valueLength()];
e.value().get(eventBytes);
assertEquals(eventBytes, testDataMap.get(entryNum).value.getBytes(Charset.defaultCharset()));
entryNum++;
e = eventIterator.next();
assertTrue(e.isEndOfPeriodMarker());
assertEquals(expectedScn, e.sequence());
expectedScn++;
}
}