new DbusEventBuffer(TestDbusEventBuffer.getConfig(
100000, 100000, 100, 500, AllocationPolicy.HEAP_MEMORY, QueuePolicy.OVERWRITE_ON_WRITE,
AssertLevel.ALL));
log.info("verify iterators on empty buffers ");
final InternalEventIterator iter0 =
dbusBuf.acquireInternalIterator(dbusBuf.getHead(), dbusBuf.getTail(), null);
Assert.assertEquals(iter0.getCurrentPosition(), dbusBuf.getHead());
Assert.assertEquals(iter0._iteratorTail.getPosition(), dbusBuf.getTail());
Assert.assertNotNull(iter0.getIdentifier());
Assert.assertTrue(iter0.getIdentifier().startsWith(InternalEventIterator.class.getSimpleName()));
Assert.assertTrue(!iter0.hasNext());
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 1);
log.info("append a full window of events");
final DbusEventGenerator generator = new DbusEventGenerator();
final Vector<DbusEvent> events = new Vector<DbusEvent>();
generator.generateEvents(5, 5, 120, 39, events);
injectEventsInBuffer(dbusBuf, events, false);
log.info("verify we can read all events");
//old iterator has not changed
Assert.assertTrue(!iter0.hasNext());
log.info("verify new iterator");
InternalEventIterator iter1 =
dbusBuf.acquireInternalIterator(dbusBuf.getHead(), dbusBuf.getTail(), null);
Assert.assertEquals(iter1.getCurrentPosition(), dbusBuf.getHead());
Assert.assertEquals(iter1._iteratorTail.getPosition(), dbusBuf.getTail());
Assert.assertNotNull(iter1.getIdentifier());
Assert.assertTrue(iter1.getIdentifier().startsWith(InternalEventIterator.class.getSimpleName()));
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 2);
Assert.assertTrue(iter1.hasNext());
log.info("make sure we can read all events");
readAndCompareIteratorEvents(iter1, events, false);
log.info("add more windows");
final Vector<DbusEvent> events2 = new Vector<DbusEvent>();
final DbusEventGenerator generator2 = new DbusEventGenerator(1000);
generator2.generateEvents(50, 4, 180, 100, events2);
injectEventsInBuffer(dbusBuf, events2, false);
log.info("verify old iterators have not changed");
Assert.assertTrue(!iter0.hasNext());
Assert.assertTrue(!iter1.hasNext());
log.info("verify new iterator");
events.addAll(events2);
InternalEventIterator iter2 =
dbusBuf.acquireInternalIterator(dbusBuf.getHead(), dbusBuf.getTail(), null);
Assert.assertEquals(iter2.getCurrentPosition(), dbusBuf.getHead());
Assert.assertEquals(iter2._iteratorTail.getPosition(), dbusBuf.getTail());
Assert.assertNotNull(iter2.getIdentifier());
Assert.assertTrue(iter2.getIdentifier().startsWith(InternalEventIterator.class.getSimpleName()));
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 3);
Assert.assertTrue(iter2.hasNext());
log.info("make sure we can read all events");
readAndCompareIteratorEvents(iter2, events, false);
iter0.close();
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 2);
iter2.close();
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 1);
iter1.close();
Assert.assertEquals(dbusBuf._busyIteratorPool.size(), 0);
log.info("done");
}