Search in sources :

Example 41 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchWithDeletedRollCyles.

@Test
public void findByBinarySearchWithDeletedRollCyles() {
    final File queueDir = getTmpDir();
    final SetTimeProvider timeProvider = new SetTimeProvider();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).timeProvider(timeProvider).rollCycle(RollCycles.TEST_SECONDLY).build()) {
        for (int i = 0; i < 5; i++) {
            int entries = 10, reps = 5;
            populateQueueWithTimestamps(queue, entries, reps, i);
            timeProvider.advanceMillis(3_000);
        }
    }
    // Just make sure Windows has closed all the files before we try to delete
    BackgroundResourceReleaser.releasePendingResources();
    // delete the 4th roll cycle
    assertTrue("Couldn't delete cycle, test is broken", queueDir.toPath().resolve("19700101-000009T.cq4").toFile().delete());
    // this should be before the start
    // third index in 3rd roll cycle, should be ({reps=5} * 8) + ({remaining_cycles=1} * ({reps=5} * {entries=10})) = 90 in output
    long tsToLookFor = getTimestampAtIndex(22);
    System.out.println(tsToLookFor);
    ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
    reader.execute();
    assertEquals(90 * 2, capturedOutput.size());
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Example 42 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchSparseApprox.

@Test
public void findByBinarySearchSparseApprox() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        try (ExcerptAppender appender = queue.acquireAppender()) {
            writeTimestamp(appender, getTimestampAtIndex(1));
            writeTimestamp(appender, getTimestampAtIndex(2));
            writeTimestamp(appender, getTimestampAtIndex(2));
            appender.writeText("aaaa");
            writeTimestamp(appender, getTimestampAtIndex(4));
            writeTimestamp(appender, getTimestampAtIndex(4));
            writeTimestamp(appender, getTimestampAtIndex(4));
        }
        capturedOutput.clear();
        long tsToLookFor = getTimestampAtIndex(3);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(3, capturedOutput.size() / 2);
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 43 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearch.

@Test
public void findByBinarySearch() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        int max = 10, reps = 5;
        populateQueueWithTimestamps(queue, max, reps);
        for (int i = 0; i < max; i++) {
            capturedOutput.clear();
            long tsToLookFor = getTimestampAtIndex(i);
            System.out.println("Looking for " + tsToLookFor);
            ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
            reader.execute();
            assertEquals(reps * (max - i), capturedOutput.size() / 2);
        }
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 44 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchBeforeStart.

@Test
public void findByBinarySearchBeforeStart() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        int max = 10, reps = 5;
        populateQueueWithTimestamps(queue, max, reps);
        // this should be before the start
        long tsToLookFor = getTimestampAtIndex(-1);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(max * reps, capturedOutput.size() / 2);
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 45 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchAfterEnd.

@Test
public void findByBinarySearchAfterEnd() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        int max = 10, reps = 5;
        populateQueueWithTimestamps(queue, max, reps);
        // this should be after the end
        long tsToLookFor = getTimestampAtIndex(11);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(0, capturedOutput.size());
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Aggregations

SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)70 Test (org.junit.Test)54 File (java.io.File)31 DocumentContext (net.openhft.chronicle.wire.DocumentContext)15 RandomAccessFile (java.io.RandomAccessFile)14 ChronicleReader (net.openhft.chronicle.queue.reader.ChronicleReader)13 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)12 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)10 Ignore (org.junit.Ignore)10 NotNull (org.jetbrains.annotations.NotNull)9 MethodReader (net.openhft.chronicle.bytes.MethodReader)8 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)8 InternalAppender (net.openhft.chronicle.queue.impl.single.InternalAppender)7 Bytes (net.openhft.chronicle.bytes.Bytes)5 Path (java.nio.file.Path)4 OS (net.openhft.chronicle.core.OS)4 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)4 Assert (org.junit.Assert)4 IOException (java.io.IOException)3 TimeUnit (java.util.concurrent.TimeUnit)3