Search in sources :

Example 21 with ExcerptAppender

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

Example 22 with ExcerptAppender

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

the class RollCycleTest method newRollCycleIgnored.

@Test
public void newRollCycleIgnored() throws Exception {
    File path = DirectoryUtils.tempDir("newRollCycleIgnored");
    SetTimeProvider timeProvider = new SetTimeProvider();
    ParallelQueueObserver observer = new ParallelQueueObserver(timeProvider, path.toPath());
    try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(RollCycles.DAILY).timeProvider(timeProvider).build()) {
        ExcerptAppender appender = queue.acquireAppender();
        Thread thread = new Thread(observer);
        thread.start();
        observer.await();
        // two days pass
        timeProvider.advanceMillis(TimeUnit.DAYS.toMillis(2));
        appender.writeText("0");
        // allow parallel tailer to finish iteration
        for (int i = 0; i < 5_000 && observer.documentsRead != 1; i++) {
            Thread.sleep(1);
        }
        thread.interrupt();
    }
    assertEquals(1, observer.documentsRead);
    observer.queue.close();
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Example 23 with ExcerptAppender

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

the class RollCycleTest method newRollCycleIgnored2.

@Test
public void newRollCycleIgnored2() throws Exception {
    File path = DirectoryUtils.tempDir("newRollCycleIgnored2");
    SetTimeProvider timeProvider = new SetTimeProvider();
    ParallelQueueObserver observer = new ParallelQueueObserver(timeProvider, path.toPath());
    int cyclesToWrite = 100;
    try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.fieldlessBinary(path).testBlockSize().rollCycle(RollCycles.DAILY).timeProvider(timeProvider).build()) {
        ExcerptAppender appender = queue.acquireAppender();
        appender.writeText("0");
        Thread thread = new Thread(observer);
        thread.start();
        observer.await();
        for (int i = 1; i <= cyclesToWrite; i++) {
            // two days pass
            timeProvider.advanceMillis(TimeUnit.DAYS.toMillis(2));
            appender.writeText(Integer.toString(i));
        }
        // allow parallel tailer to finish iteration
        for (int i = 0; i < 5_000 && observer.documentsRead != 1 + cyclesToWrite; i++) {
            Thread.sleep(1);
        }
        thread.interrupt();
    }
    assertEquals(1 + cyclesToWrite, observer.documentsRead);
    observer.queue.close();
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Example 24 with ExcerptAppender

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

the class SingleChronicleQueueStoreTest method shouldPerformIndexingOnAppend.

@Test
public void shouldPerformIndexingOnAppend() throws Exception {
    runTest(queue -> {
        final ExcerptAppender appender = queue.acquireAppender();
        appender.lazyIndexing(false);
        final long[] indices = writeMessagesStoreIndices(appender, queue.createTailer());
        assertExcerptsAreIndexed(queue, indices, i -> i % INDEX_SPACING == 0, ScanResult.FOUND);
    });
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) Test(org.junit.Test)

Example 25 with ExcerptAppender

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

the class SingleChronicleQueueStoreTest method shouldPerformIndexingOnRead.

@Test
public void shouldPerformIndexingOnRead() throws Exception {
    runTest(queue -> {
        final ExcerptAppender appender = queue.acquireAppender();
        appender.lazyIndexing(true);
        final long[] indices = writeMessagesStoreIndices(appender, queue.createTailer().indexing(true));
        assertExcerptsAreIndexed(queue, indices, i -> i % INDEX_SPACING == 0, ScanResult.FOUND);
    });
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) 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