use of net.openhft.chronicle.queue.RollCycles.TEST_DAILY in project Chronicle-Queue by OpenHFT.
the class LastIndexAppendedTest method testTwoAppenders.
@Test
public void testTwoAppenders() throws Exception {
File path = DirectoryUtils.tempDir("testTwoAppenders");
long a_index;
try (SingleChronicleQueue appender_queue = ChronicleQueueBuilder.single(path).testBlockSize().rollCycle(TEST_DAILY).build()) {
ExcerptAppender appender = appender_queue.acquireAppender();
for (int i = 0; i < 5; i++) {
appender.writeDocument(wireOut -> wireOut.write("log").marshallable(m -> m.write("msg").text("hello world ")));
}
a_index = appender.lastIndexAppended();
}
SingleChronicleQueue tailer_queue = ChronicleQueueBuilder.single(path).testBlockSize().rollCycle(TEST_DAILY).build();
ExcerptTailer tailer = tailer_queue.createTailer();
tailer = tailer.toStart();
long t_index;
t_index = doRead(tailer, 5);
assertEquals(a_index, t_index);
System.out.println("Continue appending");
try (SingleChronicleQueue appender_queue = ChronicleQueueBuilder.single(path).testBlockSize().rollCycle(TEST_DAILY).build()) {
ExcerptAppender appender = appender_queue.acquireAppender();
for (int i = 0; i < 5; i++) {
appender.writeDocument(wireOut -> wireOut.write("log").marshallable(m -> m.write("msg").text("hello world2 ")));
}
a_index = appender.lastIndexAppended();
assertTrue(a_index > t_index);
}
// if the tailer continues as well it should see the 5 new messages
System.out.println("Reading messages added");
t_index = doRead(tailer, 5);
assertEquals(a_index, t_index);
// if the tailer is expecting to read all the message again
System.out.println("Reading all the messages again");
tailer.toStart();
t_index = doRead(tailer, 10);
assertEquals(a_index, t_index);
try {
IOTools.deleteDirWithFiles(path, 2);
} catch (Exception index) {
}
}
Aggregations