Search in sources :

Example 1 with ChronicleQueue

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

the class NotCompleteTest method testUsingANotCompleteArrayQueue.

@Test
public void testUsingANotCompleteArrayQueue() throws InterruptedException {
    BinaryLongArrayReference.startCollecting();
    File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteArrayQueue");
    try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
        ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
        try (DocumentContext dc = appender.writingDocument()) {
            dc.wire().write("some").text("data");
        }
        Thread.sleep(100);
        // System.out.println(queue.dump());
        // this is what will corrupt the queue
        BinaryLongArrayReference.forceAllToNotCompleteState();
    }
    try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().timeoutMS(500).build()) {
        // System.out.println(queue.dump());
        ExcerptTailer tailer = queue.createTailer();
        try (DocumentContext dc = tailer.readingDocument()) {
            assertEquals("data", dc.wire().read(() -> "some").text());
        }
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 2 with ChronicleQueue

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

the class NotCompleteTest method testSkipSafeLengthOverBlock.

@Ignore("store.writePosition() not set after we recover, but not trivial to fix. Problem only occurs rarely")
@Test
public void testSkipSafeLengthOverBlock() {
    File tmpDir = DirectoryUtils.tempDir("testSkipSafeLengthOverBlock");
    // 3rd time will do it
    for (int i = 0; i < 8; i++) {
        try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).timeoutMS(1).build()) {
            ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
            // start a message which won't be completed.
            DocumentContext dc = appender.writingDocument();
            // 2nd and subsequent times we call this will invoke recovery
            dc.wire().write("some").text("data");
        // don't call dc.close();
        }
    }
    try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().build()) {
        ExcerptTailer tailer = queue.createTailer();
        try (DocumentContext dc = tailer.readingDocument()) {
            assertFalse(dc.isPresent());
        }
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ChronicleQueue

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

the class NotCompleteTest method testUsingANotCompleteQueue.

/**
 * tests that when flags are set to not complete we are able to recover
 */
@Test
public void testUsingANotCompleteQueue() throws InterruptedException {
    BinaryLongReference.startCollecting();
    File tmpDir = DirectoryUtils.tempDir("testUsingANotCompleteQueue");
    try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
        ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
        try (DocumentContext dc = appender.writingDocument()) {
            dc.wire().write("some").text("data");
        }
        Thread.sleep(100);
        // System.out.println(queue.dump());
        // this is what will corrupt the queue
        BinaryLongReference.forceAllToNotCompleteState();
    }
    try (final ChronicleQueue queue = binary(tmpDir).testBlockSize().timeoutMS(500).build()) {
        // System.out.println(queue.dump());
        ExcerptTailer tailer = queue.createTailer();
        try (DocumentContext dc = tailer.readingDocument()) {
            assertEquals("data", dc.wire().read(() -> "some").text());
        }
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 4 with ChronicleQueue

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

the class RollCycleMultiThreadTest method testRead2.

@Test
public void testRead2() throws Exception {
    File path = DirectoryUtils.tempDir("testRead2");
    TestTimeProvider timeProvider = new TestTimeProvider();
    try (ChronicleQueue queue0 = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
        final ParallelQueueObserver observer = new ParallelQueueObserver(queue0);
        final ExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
            ExcerptAppender appender = queue.acquireAppender();
            try (final DocumentContext dc = appender.writingDocument()) {
                dc.wire().write().text("Day 1 data");
            }
            Assert.assertEquals(1, (int) scheduledExecutorService.submit(observer).get());
            // two days pass
            timeProvider.add(TimeUnit.DAYS.toMillis(2));
            try (final DocumentContext dc = appender.writingDocument()) {
                dc.wire().write().text("Day 3 data");
            }
            Assert.assertEquals(2, (int) scheduledExecutorService.submit(observer).get());
            System.out.println(queue.dump());
            assertEquals(2, observer.documentsRead);
        }
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) ExecutorService(java.util.concurrent.ExecutorService) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) Test(org.junit.Test)

Example 5 with ChronicleQueue

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

the class RollCycleMultiThreadTest method testRead1.

@Test
public void testRead1() throws Exception {
    File path = DirectoryUtils.tempDir(getClass().getSimpleName());
    TestTimeProvider timeProvider = new TestTimeProvider();
    try (ChronicleQueue queue0 = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
        ParallelQueueObserver observer = new ParallelQueueObserver(queue0);
        final ExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(DAILY).timeProvider(timeProvider).build()) {
            ExcerptAppender appender = queue.acquireAppender();
            Assert.assertEquals(0, (int) scheduledExecutorService.submit(observer::call).get());
            // two days pass
            timeProvider.add(TimeUnit.DAYS.toMillis(2));
            try (final DocumentContext dc = appender.writingDocument()) {
                dc.wire().write().text("Day 3 data");
            }
            Assert.assertEquals(1, (int) scheduledExecutorService.submit(observer::call).get());
            assertEquals(1, observer.documentsRead);
        }
    }
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) ExecutorService(java.util.concurrent.ExecutorService) DocumentContext(net.openhft.chronicle.wire.DocumentContext) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) Test(org.junit.Test)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)80 Test (org.junit.Test)59 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)37 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)37 File (java.io.File)36 DocumentContext (net.openhft.chronicle.wire.DocumentContext)21 ArrayList (java.util.ArrayList)16 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 MethodReader (net.openhft.chronicle.bytes.MethodReader)12 List (java.util.List)11 IOException (java.io.IOException)9 MappedFile (net.openhft.chronicle.bytes.MappedFile)8 Path (java.nio.file.Path)7 Bytes (net.openhft.chronicle.bytes.Bytes)7 Collections (java.util.Collections)6 RollCycles (net.openhft.chronicle.queue.RollCycles)6 NotNull (org.jetbrains.annotations.NotNull)6 ByteBuffer (java.nio.ByteBuffer)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)5 Histogram (net.openhft.chronicle.core.util.Histogram)5