use of net.openhft.chronicle.queue.RollCycle in project Chronicle-Queue by OpenHFT.
the class ExcerptsSkippedWhenTailerDirectionNoneTest method shouldNotSkipMessageAtStartOfQueue.
@Test
public void shouldNotSkipMessageAtStartOfQueue() throws Exception {
final File tmpDir = DirectoryUtils.tempDir(ExcerptsSkippedWhenTailerDirectionNoneTest.class.getSimpleName());
try (final ChronicleQueue writeQueue = SingleChronicleQueueBuilder.binary(tmpDir).testBlockSize().rollCycle(TEST_DAILY).build()) {
final ExcerptAppender excerptAppender = writeQueue.acquireAppender();
try (final DocumentContext ctx = excerptAppender.writingDocument()) {
ctx.wire().getValueOut().object("first");
}
try (final DocumentContext ctx = excerptAppender.writingDocument()) {
ctx.wire().getValueOut().object("second");
}
}
try (final SingleChronicleQueue readQueue = SingleChronicleQueueBuilder.binary(tmpDir).testBlockSize().rollCycle(TEST_DAILY).build()) {
final ExcerptTailer tailer = readQueue.createTailer();
final RollCycle rollCycle = readQueue.rollCycle();
assertThat(rollCycle.toSequenceNumber(tailer.index()), is(0L));
try (final DocumentContext ctx = tailer.direction(TailerDirection.NONE).readingDocument()) {
// access the first document without incrementing sequence number
}
assertThat(rollCycle.toSequenceNumber(tailer.index()), is(0L));
String value;
try (DocumentContext dc = tailer.direction(TailerDirection.FORWARD).readingDocument()) {
ValueIn valueIn = dc.wire().getValueIn();
value = (String) valueIn.object();
}
assertThat(rollCycle.toSequenceNumber(tailer.index()), is(1L));
assertThat(value, is("first"));
try (DocumentContext dc = tailer.direction(TailerDirection.NONE).readingDocument()) {
ValueIn valueIn = dc.wire().getValueIn();
value = (String) valueIn.object();
}
assertThat(rollCycle.toSequenceNumber(tailer.index()), is(1L));
assertThat(value, is("second"));
try (DocumentContext dc = tailer.direction(TailerDirection.NONE).readingDocument()) {
ValueIn valueIn = dc.wire().getValueIn();
value = (String) valueIn.object();
}
assertThat(rollCycle.toSequenceNumber(tailer.index()), is(1L));
assertThat(value, is("second"));
}
}
Aggregations