Search in sources :

Example 16 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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 17 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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 18 with ExcerptAppender

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

the class NotCompleteTest method doWrite.

private void doWrite(ChronicleQueue queue, BiConsumer<PersonListener, ChronicleQueue> action) {
    ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
    PersonListener proxy = appender.methodWriterBuilder(PersonListener.class).get();
    action.accept(proxy, queue);
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender)

Example 19 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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 20 with ExcerptAppender

use of net.openhft.chronicle.queue.ExcerptAppender 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)

Aggregations

ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)63 Test (org.junit.Test)55 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)34 File (java.io.File)33 DocumentContext (net.openhft.chronicle.wire.DocumentContext)28 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)21 MappedFile (net.openhft.chronicle.bytes.MappedFile)15 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)6 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)5 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)5 Ignore (org.junit.Ignore)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ValueOut (net.openhft.chronicle.wire.ValueOut)4 Wire (net.openhft.chronicle.wire.Wire)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 ExecutorService (java.util.concurrent.ExecutorService)3 Bytes (net.openhft.chronicle.bytes.Bytes)3 ChronicleQueueTestBase (net.openhft.chronicle.queue.ChronicleQueueTestBase)3