Search in sources :

Example 1 with RollCycles

use of net.openhft.chronicle.queue.RollCycles in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testReadingWritingWhenNextCycleIsInSequence.

@Test
public void testReadingWritingWhenNextCycleIsInSequence() {
    SetTimeProvider timeProvider = new SetTimeProvider();
    final File dir = DirectoryUtils.tempDir(testName.getMethodName());
    final RollCycles rollCycle = RollCycles.TEST_SECONDLY;
    // write first message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        queue.acquireAppender().writeText("first message");
    }
    timeProvider.advanceMillis(1100);
    // write second message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        queue.acquireAppender().writeText("second message");
    }
    // read both messages
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        ExcerptTailer tailer = queue.createTailer();
        Assert.assertEquals("first message", tailer.readText());
        Assert.assertEquals("second message", tailer.readText());
    }
}
Also used : RollCycles(net.openhft.chronicle.queue.RollCycles) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider)

Example 2 with RollCycles

use of net.openhft.chronicle.queue.RollCycles in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testReadingWritingWhenCycleIsSkippedBackwards.

@Test
public void testReadingWritingWhenCycleIsSkippedBackwards() throws Exception {
    final File dir = DirectoryUtils.tempDir(testName.getMethodName());
    final RollCycles rollCycle = RollCycles.TEST_SECONDLY;
    // write first message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).build()) {
        queue.acquireAppender().writeText("first message");
    }
    // TODO: this test fails when converted to use a TimeProvider. Need to work out why
    Thread.sleep(2100);
    // write second message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).build()) {
        queue.acquireAppender().writeText("second message");
    }
    // read both messages
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).build()) {
        ExcerptTailer tailer = queue.createTailer();
        ExcerptTailer excerptTailer = tailer.direction(TailerDirection.BACKWARD).toEnd();
        Assert.assertEquals("second message", excerptTailer.readText());
        Assert.assertEquals("first message", excerptTailer.readText());
    }
}
Also used : RollCycles(net.openhft.chronicle.queue.RollCycles) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue)

Example 3 with RollCycles

use of net.openhft.chronicle.queue.RollCycles in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testLongLivingTailerAppenderReAcquiredEachSecond.

@Test
public void testLongLivingTailerAppenderReAcquiredEachSecond() {
    SetTimeProvider timeProvider = new SetTimeProvider();
    final File dir = DirectoryUtils.tempDir(testName.getMethodName());
    final RollCycles rollCycle = RollCycles.TEST_SECONDLY;
    try (ChronicleQueue queuet = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        final ExcerptTailer tailer = queuet.createTailer();
        // write first message
        try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
            for (int i = 0; i < 5; i++) {
                final ExcerptAppender appender = queue.acquireAppender();
                timeProvider.advanceMillis(1100);
                try (final DocumentContext dc = appender.writingDocument()) {
                    dc.wire().write("some").int32(i);
                }
                try (final DocumentContext dc = tailer.readingDocument()) {
                    Assert.assertEquals(i, dc.wire().read("some").int32());
                }
            }
        }
    }
}
Also used : RollCycles(net.openhft.chronicle.queue.RollCycles) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider)

Example 4 with RollCycles

use of net.openhft.chronicle.queue.RollCycles in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testTailerSnappingRollWithNewAppender.

@Test
public void testTailerSnappingRollWithNewAppender() throws Exception {
    SetTimeProvider timeProvider = new SetTimeProvider();
    final File dir = DirectoryUtils.tempDir(testName.getMethodName());
    final RollCycles rollCycle = RollCycles.TEST_SECONDLY;
    // write first message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        ExcerptAppender excerptAppender = queue.acquireAppender();
        excerptAppender.writeText("someText");
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Future f1 = executorService.submit(() -> {
            try (ChronicleQueue queue2 = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
                queue2.acquireAppender().writeText("someText more");
            }
            timeProvider.advanceMillis(1100);
            try (ChronicleQueue queue2 = binary(dir).rollCycle(rollCycle).build()) {
                queue2.acquireAppender().writeText("someText more");
            }
        });
        Future f2 = executorService.submit(() -> {
            // write second message
            try (ChronicleQueue queue2 = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
                for (int i = 0; i < 5; i++) {
                    queue2.acquireAppender().writeText("someText more");
                    timeProvider.advanceMillis(400);
                }
            }
        });
        f1.get();
        f2.get();
        executorService.shutdownNow();
    }
}
Also used : RollCycles(net.openhft.chronicle.queue.RollCycles) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider)

Example 5 with RollCycles

use of net.openhft.chronicle.queue.RollCycles in project Chronicle-Queue by OpenHFT.

the class SingleChronicleQueueTest method testReadingWritingWhenCycleIsSkipped.

@Test
public void testReadingWritingWhenCycleIsSkipped() {
    SetTimeProvider timeProvider = new SetTimeProvider();
    final File dir = DirectoryUtils.tempDir(testName.getMethodName());
    final RollCycles rollCycle = RollCycles.TEST_SECONDLY;
    // write first message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        queue.acquireAppender().writeText("first message");
    }
    timeProvider.advanceMillis(2100);
    // write second message
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        queue.acquireAppender().writeText("second message");
    }
    // read both messages
    try (ChronicleQueue queue = binary(dir).rollCycle(rollCycle).timeProvider(timeProvider).build()) {
        ExcerptTailer tailer = queue.createTailer();
        Assert.assertEquals("first message", tailer.readText());
        Assert.assertEquals("second message", tailer.readText());
    }
}
Also used : RollCycles(net.openhft.chronicle.queue.RollCycles) RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider)

Aggregations

RollCycles (net.openhft.chronicle.queue.RollCycles)5 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)5 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)4