Search in sources :

Example 6 with ChronicleReader

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

the class ChronicleReaderTest method findByBinarySearchBeforeStartReverse.

@Test
public void findByBinarySearchBeforeStartReverse() {
    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()).inReverseOrder().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)

Example 7 with ChronicleReader

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

the class ChronicleReaderTest method findByBinarySearchSparseRepeatedReverse.

@Test
public void findByBinarySearchSparseRepeatedReverse() {
    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(2));
            writeTimestamp(appender, getTimestampAtIndex(2));
            writeTimestamp(appender, getTimestampAtIndex(2));
            writeTimestamp(appender, getTimestampAtIndex(3));
        }
        capturedOutput.clear();
        long tsToLookFor = getTimestampAtIndex(2);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(7, 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 8 with ChronicleReader

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

the class ChronicleReaderTest method findByBinarySearchApprox.

@Test
public void findByBinarySearchApprox() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        final int reps = 5;
        final int max = 10;
        populateQueueWithTimestamps(queue, max, reps);
        for (int i = 0; i < max; i++) {
            capturedOutput.clear();
            long tsToLookFor = getTimestampAtIndex(i) - 1;
            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 9 with ChronicleReader

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

the class ChronicleReaderTest method findByBinarySearchSparseApproxReverse.

@Test
public void findByBinarySearchSparseApproxReverse() {
    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()).inReverseOrder().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 10 with ChronicleReader

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

the class ChronicleReaderTest method shouldNotFailOnEmptyQueue.

@Test
public void shouldNotFailOnEmptyQueue() {
    Path path = getTmpDir().toPath();
    path.toFile().mkdirs();
    if (!OS.isWindows())
        expectException("Failback to readonly tablestore");
    new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
    assertTrue(capturedOutput.isEmpty());
}
Also used : Path(java.nio.file.Path) 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