DbusEventBuffer.StaticConfig config = getConfig(1200, 500, 100, 500,
AllocationPolicy.MMAPPED_MEMORY, mmapDir.getAbsolutePath(), true);
DbusEventBuffer dbusBuf = new DbusEventBuffer(config);
DbusEventBufferReflector bufferReflector = new DbusEventBufferReflector(dbusBuf);
// BufferPositionParser parser = dbusBuf.getBufferPositionParser();
log.info("append initial events");
DbusEventGenerator generator = new DbusEventGenerator();
Vector<DbusEvent> events = new Vector<DbusEvent>();
generator.generateEvents(12, 2, 120, 39, events);
// add first window with 2 events
dbusBuf.start(-1);
int i=0;
addOneEvent(events.get(i++), dbusBuf, EventType.START);
addOneEvent(events.get(i++), dbusBuf, EventType.END);
checkEventsInBuffer(bufferReflector, 3); // 2 + 1(EOW)
// add first event of the second window
addOneEvent(events.get(i++), dbusBuf, EventType.START);
checkEventsInBuffer(bufferReflector, 3); // 2 + 1(EOW)
// now close the buffer
dbusBuf.closeBuffer(true);
checkEventsInBuffer(bufferReflector, 3); // 2 + 1(EOW)
// now add the end
try {
addOneEvent(events.get(i), dbusBuf, EventType.END);
} catch (Throwable ex) {
log.info("Got e: ", ex);
}
checkEventsInBuffer(bufferReflector, 3); // 2 + 1(EOW)
// create new buffer
dbusBuf = new DbusEventBuffer(config); // should load from mmap
bufferReflector = new DbusEventBufferReflector(dbusBuf);
checkEventsInBuffer(bufferReflector, 3); // 2 + 1(EOW)
addOneEvent(events.get(i++), dbusBuf, EventType.START);
addOneEvent(events.get(i++), dbusBuf, EventType.END);
checkEventsInBuffer(bufferReflector, 6); // 4 + 2(EOW)
// add two more events but don't do endEvents
addOneEvent(events.get(i++), dbusBuf, EventType.START);
addOneEvent(events.get(i++), dbusBuf, EventType.REG); // no endEvents()
// now close the buffer
dbusBuf.closeBuffer(true);
dbusBuf.closeBuffer(true); // should be ok (WARN in the logs)
checkEventsInBuffer(bufferReflector, 6); // 4 + 2(EOW)
// call endEvents(on a closed buffer);
try {
dbusBuf.endEvents(events.get(i-1).sequence());
} catch (Throwable ex) {
log.info("Got e2: ", ex);
}
checkEventsInBuffer(bufferReflector, 6); // 4 + 2(EOW)
// create new buffer
dbusBuf = new DbusEventBuffer(config); // should load from mmap
bufferReflector = new DbusEventBufferReflector(dbusBuf);
checkEventsInBuffer(bufferReflector, 6); // 4 + 2(EOW)
addOneEvent(events.get(i++), dbusBuf, EventType.START);
addOneEvent(events.get(i++), dbusBuf, EventType.END);
checkEventsInBuffer(bufferReflector, 9); // 6 + 3(EOW)
// add two more events but don't do endEvents
addOneEvent(events.get(i++), dbusBuf, EventType.START);
addOneEvent(events.get(i++), dbusBuf, EventType.REG); // no endEvents()
// now close the buffer
dbusBuf.closeBuffer(true);
checkEventsInBuffer(bufferReflector, 9); // 6 + 3(EOW)
// call endEvents(on a closed buffer);
try {
dbusBuf.clear(); //should fail
} catch (Throwable ex) {
log.info("Got e3: ", ex);
}
checkEventsInBuffer(bufferReflector, 9); // 6 + 3(EOW)
// make sure it is still valid
dbusBuf = new DbusEventBuffer(config); // should load from mmap
bufferReflector = new DbusEventBufferReflector(dbusBuf);
checkEventsInBuffer(bufferReflector, 9); // 6 + 3(EOW)
}