Search in sources :

Example 46 with SingleChronicleQueue

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

the class TestDeleteQueueFile method tailerToEndFromEndWorksInFaceOfDeletedStoreFile.

@Test
public void tailerToEndFromEndWorksInFaceOfDeletedStoreFile() throws IOException {
    assumeFalse(OS.isWindows());
    try (QueueWithCycleDetails queueWithCycleDetails = createQueueWithNRollCycles(3, null)) {
        final SingleChronicleQueue queue = queueWithCycleDetails.queue;
        RollCycleDetails firstCycle = queueWithCycleDetails.rollCycles.get(0);
        RollCycleDetails secondCycle = queueWithCycleDetails.rollCycles.get(1);
        RollCycleDetails thirdCycle = queueWithCycleDetails.rollCycles.get(2);
        ExcerptTailer tailer = queue.createTailer();
        // while the queue is intact
        assertEquals(Long.toHexString(firstCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
        assertEquals(Long.toHexString(thirdCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
        // delete the last store
        Files.delete(Paths.get(thirdCycle.filename));
        // should be at correct index
        assertEquals(Long.toHexString(secondCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
    }
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) Test(org.junit.Test)

Example 47 with SingleChronicleQueue

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

the class TestDeleteQueueFile method tailerToStartFromStartWorksInFaceOfDeletedStoreFile.

@Ignore("still doesn't work")
@Test
public void tailerToStartFromStartWorksInFaceOfDeletedStoreFile() throws IOException {
    assumeFalse(OS.isWindows());
    try (QueueWithCycleDetails queueWithCycleDetails = createQueueWithNRollCycles(3, null)) {
        final SingleChronicleQueue queue = queueWithCycleDetails.queue;
        RollCycleDetails firstCycle = queueWithCycleDetails.rollCycles.get(0);
        RollCycleDetails secondCycle = queueWithCycleDetails.rollCycles.get(1);
        RollCycleDetails thirdCycle = queueWithCycleDetails.rollCycles.get(2);
        ExcerptTailer tailer = queue.createTailer();
        // while the queue is intact
        assertEquals(Long.toHexString(thirdCycle.lastIndex + 1), Long.toHexString(tailer.toEnd().index()));
        assertEquals(Long.toHexString(firstCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
        // delete the first store
        Files.delete(Paths.get(firstCycle.filename));
        // should be at correct index
        assertEquals(Long.toHexString(secondCycle.firstIndex), Long.toHexString(tailer.toStart().index()));
    }
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 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 49 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 50 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)

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