Search in sources :

Example 16 with ChronicleReader

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

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

use of net.openhft.chronicle.queue.reader.ChronicleReader 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 19 with ChronicleReader

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

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

the class ChronicleReaderTest method reverseOrderShouldIgnoreOptionsThatDontMakeSense.

@Test
public void reverseOrderShouldIgnoreOptionsThatDontMakeSense() {
    addCountToEndOfQueue();
    new ChronicleReader().withBasePath(dataDir).withMessageSink(capturedOutput::add).inReverseOrder().suppressDisplayIndex().tail().historyRecords(// Ignored
    10).execute();
    final List<String> firstFourElements = capturedOutput.stream().limit(4).collect(Collectors.toList());
    assertEquals(Arrays.asList("\"4\"\n", "\"3\"\n", "\"2\"\n", "\"1\"\n"), firstFourElements);
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) Test(org.junit.Test)

Aggregations

ChronicleReader (net.openhft.chronicle.queue.reader.ChronicleReader)24 Test (org.junit.Test)22 File (java.io.File)16 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)16 RandomAccessFile (java.io.RandomAccessFile)13 Path (java.nio.file.Path)5 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)4 Calendar (java.util.Calendar)3 LinkedList (java.util.LinkedList)3 Optional (java.util.Optional)2 NotNull (org.jetbrains.annotations.NotNull)2 NamedThreadFactory (net.openhft.chronicle.threads.NamedThreadFactory)1