see code in net.openhft.chronicle.queue.impl.single.SingleChronicleQueueTest#testReadingDocument
try (final DocumentContext dc = tailer.readingDocument()) {
assert dc.isPresent();
assert dc.isData();
dc.wire().read(() -> "key").text(sb);
Assert.assertEquals("value=0", sb.toString());
}
2 Rolling
see net.openhft.chronicle.queue.RollCycles
for example see net.openhft.chronicle.queue.impl.single.SingleChronicleQueueTest#testReadingDocumentWithFirstAMove
try (final RollingChronicleQueue queue = SingleChronicleQueueBuilder.binary(getTmpDir()) .wireType(this.wireType)
.rollCycle(RollCycles.HOURLY)
.build()) {
….
}
3. indexes
see net.openhft.chronicle.queue.LastIndexAppendedTest#testLastIndexAppendedAcrossRestarts
@Test
public void testLastIndexAppendedAcrossRestarts() throws Exception {
String path = OS.TARGET + "/deleteme.q-" + System.nanoTime();
long expectedIndex = 0;
for (int i = 0; i < 5; i++) {
try (SingleChronicleQueue queue = ChronicleQueueBuilder.single(path).build()) {
ExcerptAppender appender = queue.createAppender();
try (DocumentContext documentContext = appender.writingDocument()) {
long expectedIndex2 = documentContext.index();
assertTrue("expectedIndex: " + expectedIndex2, expectedIndex2 > 0);
if (expectedIndex == 0)
expectedIndex = expectedIndex2;
else
assertEquals(++expectedIndex, expectedIndex2);
documentContext.wire().write().text("hello world");
}
final long lastIndex = queue.nextIndexToWrite();
assertEquals(expectedIndex + 1, lastIndex);
assertEquals(expectedIndex, appender.lastIndexAppended());
}
}
try {
IOTools.deleteDirWithFiles(path, 2);
} catch (Exception index) {
}
}