Search in sources :

Example 1 with TEST_DAILY

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) {
    }
}
Also used : DocumentContext(net.openhft.chronicle.wire.DocumentContext) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) IOTools(net.openhft.chronicle.core.io.IOTools) TEST_DAILY(net.openhft.chronicle.queue.RollCycles.TEST_DAILY) Test(org.junit.Test) OS(net.openhft.chronicle.core.OS) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) File(java.io.File) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 OS (net.openhft.chronicle.core.OS)1 IOTools (net.openhft.chronicle.core.io.IOTools)1 TEST_DAILY (net.openhft.chronicle.queue.RollCycles.TEST_DAILY)1 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)1 DocumentContext (net.openhft.chronicle.wire.DocumentContext)1 NotNull (org.jetbrains.annotations.NotNull)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1