Search in sources :

Example 11 with ChronicleReader

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

the class ChronicleReaderTest method findByBinarySearchApproxReverse.

@Test
public void findByBinarySearchApproxReverse() {
    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()).inReverseOrder().withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
            reader.execute();
            assertEquals(reps * (i + 1), 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 12 with ChronicleReader

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

the class RollEOFTest method testRollWithoutEOFDoesntBlowup.

@Test(timeout = 5000L)
public void testRollWithoutEOFDoesntBlowup() throws IOException {
    assumeFalse("Read-only mode is not supported on Windows", OS.isWindows());
    // expectException("Overriding roll length from existing metadata");
    // expectException("Overriding roll cycle from");
    final File path = getTmpDir();
    try {
        path.mkdirs();
        final SetTimeProvider timeProvider = new SetTimeProvider();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, -1);
        timeProvider.currentTimeMillis(cal.getTimeInMillis());
        createQueueAndWriteData(timeProvider, path);
        assertEquals(1, getNumberOfQueueFiles(path));
        // adjust time
        timeProvider.currentTimeMillis(System.currentTimeMillis());
        createQueueAndWriteData(timeProvider, path);
        assertEquals(2, getNumberOfQueueFiles(path));
        Optional<Path> firstQueueFile = Files.list(path.toPath()).filter(p -> p.toString().endsWith(SUFFIX)).sorted().findFirst();
        assertTrue(firstQueueFile.isPresent());
        // remove EOF from first file
        removeEOF(firstQueueFile.get());
        List<String> l = new LinkedList<>();
        new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute();
        // 2 entries per message
        assertEquals(4, l.size());
    } finally {
        IOTools.deleteDirWithFiles(path, 20);
    }
}
Also used : Path(java.nio.file.Path) ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) Calendar(java.util.Calendar) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with ChronicleReader

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

the class RollEOFTest method testRollWritesEOF.

@Test(timeout = 5000L)
public void testRollWritesEOF() throws IOException {
    assumeFalse("Read-only mode is not supported on Windows", OS.isWindows());
    // expectException("Overriding roll length from existing metadata");
    // expectException("Overriding roll cycle from");
    final File path = getTmpDir();
    try {
        path.mkdirs();
        final SetTimeProvider timeProvider = new SetTimeProvider();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, -1);
        timeProvider.currentTimeMillis(cal.getTimeInMillis());
        createQueueAndWriteData(timeProvider, path);
        assertEquals(1, getNumberOfQueueFiles(path));
        // adjust time
        timeProvider.currentTimeMillis(System.currentTimeMillis());
        createQueueAndWriteData(timeProvider, path);
        assertEquals(2, getNumberOfQueueFiles(path));
        List<String> l = new LinkedList<>();
        new ChronicleReader().withMessageSink(l::add).withBasePath(path.toPath()).execute();
        // 2 entries per message
        assertEquals(4, l.size());
    } finally {
        IOTools.deleteDirWithFiles(path, 20);
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) Calendar(java.util.Calendar) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 14 with ChronicleReader

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

the class ChronicleReaderMain method run.

protected void run(@NotNull String[] args) {
    final Options options = options();
    final CommandLine commandLine = parseCommandLine(args, options);
    final ChronicleReader chronicleReader = chronicleReader();
    configureReader(chronicleReader, commandLine);
    chronicleReader.execute();
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader)

Example 15 with ChronicleReader

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

the class ChronicleReaderTest method shouldReadQueueWithNonDefaultRollCycle.

@Test(timeout = 10_000L)
public void shouldReadQueueWithNonDefaultRollCycle() {
    expectException("Overriding roll length from existing metadata");
    // expectException("Overriding roll cycle from");
    Path path = getTmpDir().toPath();
    path.toFile().mkdirs();
    try (final ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).testBlockSize().sourceId(1).build()) {
        final ExcerptAppender excerptAppender = queue.acquireAppender();
        final VanillaMethodWriterBuilder<Say> methodWriterBuilder = excerptAppender.methodWriterBuilder(Say.class);
        final Say events = methodWriterBuilder.build();
        for (int i = 0; i < TOTAL_EXCERPTS_IN_QUEUE; i++) {
            events.say(i % 2 == 0 ? "hello" : "goodbye");
        }
    }
    new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
    assertFalse(capturedOutput.isEmpty());
}
Also used : Path(java.nio.file.Path) ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) 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