Search in sources :

Example 21 with ChronicleReader

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

the class ChronicleReaderTest method assertTimesAreInZone.

private void assertTimesAreInZone(File queueDir, ZoneId zoneId, List<Long> timestamps) {
    ChronicleReader reader = new ChronicleReader().asMethodReader(SayWhen.class.getName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
    reader.execute();
    MicroTimestampLongConverter mtlc = new MicroTimestampLongConverter(zoneId.toString());
    int i = 0;
    while (!capturedOutput.isEmpty()) {
        final String actualValue = capturedOutput.poll();
        if (actualValue.contains("sayWhen")) {
            final String expectedTimestamp = mtlc.asString(timestamps.get(i++));
            assertTrue(String.format("%s contains %s", actualValue, expectedTimestamp), actualValue.contains(expectedTimestamp));
        }
    }
    assertEquals("Didn't check all the timestamps", timestamps.size(), i);
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader)

Example 22 with ChronicleReader

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

Example 23 with ChronicleReader

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

the class ChronicleReaderTest method shouldReadQueueInReverse.

@Test(timeout = 10_000L)
public void shouldReadQueueInReverse() {
    addCountToEndOfQueue();
    new ChronicleReader().withBasePath(dataDir).withMessageSink(capturedOutput::add).inReverseOrder().suppressDisplayIndex().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)

Example 24 with ChronicleReader

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

the class RollEOFTest method testRollWithoutEOF.

@Test(timeout = 5000L)
public void testRollWithoutEOF() throws IOException {
    // 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, -3);
        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()).withReadOnly(false).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) File(java.io.File) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) LinkedList(java.util.LinkedList) 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