Search in sources :

Example 11 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class TailerDirectionTest method testTailerBackwardsReadBeyondCycle.

@Test
public void testTailerBackwardsReadBeyondCycle() throws Exception {
    File basePath = DirectoryUtils.tempDir("tailerForwardBackwardBeyondCycle");
    SetTimeProvider timeProvider = new SetTimeProvider();
    ChronicleQueue queue = SingleChronicleQueueBuilder.binary(basePath).testBlockSize().timeProvider(timeProvider).build();
    ExcerptAppender appender = queue.acquireAppender();
    // 
    // Prepare test messages in queue
    // 
    // List of test messages with their queue index position
    List<Long> indexes = new ArrayList<>();
    List<String> messages = new ArrayList<>();
    for (int d = -7; d <= 0; d++) {
        if (d == -5 || d == -4)
            // nothing on those days.
            continue;
        timeProvider.currentTimeMillis(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(d));
        for (int i = 0; i < 3; i++) {
            String msg = testMessage(indexes.size());
            long idx = appendEntry(appender, msg);
            messages.add(msg);
            indexes.add(idx);
        }
    }
    ExcerptTailer tailer = queue.createTailer().direction(TailerDirection.BACKWARD).toEnd();
    for (int i = indexes.size() - 1; i >= 0; i--) {
        long index = indexes.get(i);
        String msg = messages.get(i);
        assertEquals("[Backward] Wrong index " + i, index, tailer.index());
        assertEquals("[Backward] Wrong message " + i, msg, readNextEntry(tailer));
    }
    queue.close();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) File(java.io.File) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Example 12 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class RollingChronicleQueueTest method testTailing.

private void testTailing(Function<Pretoucher, Integer> createGap) {
    final SetTimeProvider tp = new SetTimeProvider(0);
    final File tmpDir = getTmpDir();
    try (SingleChronicleQueue queue = builder(tmpDir, WireType.BINARY).rollCycle(RollCycles.TEST_SECONDLY).timeProvider(tp).build()) {
        int cyclesAdded = 0;
        final Pretoucher pretoucher = new Pretoucher(queue);
        ExcerptAppender appender = queue.acquireAppender();
        // to file ...000000
        appender.writeText("0");
        assertEquals(1, tmpDir.listFiles(file -> file.getName().endsWith("cq4")).length);
        tp.advanceMillis(1000);
        // to file ...000001
        appender.writeText("1");
        assertEquals(2, tmpDir.listFiles(file -> file.getName().endsWith("cq4")).length);
        tp.advanceMillis(2000);
        cyclesAdded += createGap.apply(pretoucher);
        assertEquals(2 + cyclesAdded, tmpDir.listFiles(file -> file.getName().endsWith("cq4")).length);
        tp.advanceMillis(1000);
        // to file ...000004
        appender.writeText("2");
        assertEquals(3 + cyclesAdded, tmpDir.listFiles(file -> file.getName().endsWith("cq4")).length);
        tp.advanceMillis(2000);
        cyclesAdded += createGap.apply(pretoucher);
        assertEquals(3 + cyclesAdded, tmpDir.listFiles(file -> file.getName().endsWith("cq4")).length);
        // now tail them all back
        int count = 0;
        ExcerptTailer tailer = queue.createTailer();
        long[] indexes = new long[3];
        while (true) {
            String text = tailer.readText();
            if (text == null)
                break;
            indexes[count] = tailer.index() - 1;
            assertEquals(count++, Integer.parseInt(text));
        }
        assertEquals(indexes.length, count);
        // now make sure we can go direct to each index (like afterLastWritten)
        tailer.toStart();
        for (int i = 0; i < indexes.length; i++) {
            assertTrue(tailer.moveToIndex(indexes[i]));
            String text = tailer.readText();
            assertEquals(i, Integer.parseInt(text));
        }
    }
}
Also used : Pretoucher(net.openhft.chronicle.queue.impl.single.Pretoucher) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) File(java.io.File)

Example 13 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class MultiThreadedRollTest method test.

@Test(timeout = 10000)
public void test() throws ExecutionException, InterruptedException {
    final SetTimeProvider timeProvider = new SetTimeProvider();
    timeProvider.currentTimeMillis(1000);
    final File path = DirectoryUtils.tempDir("MultiThreadedRollTest");
    try (final RollingChronicleQueue wqueue = binary(path).testBlockSize().timeProvider(timeProvider).rollCycle(TEST_SECONDLY).build()) {
        wqueue.acquireAppender().writeText("hello world");
        try (final RollingChronicleQueue rqueue = binary(path).testBlockSize().timeProvider(timeProvider).rollCycle(TEST_SECONDLY).build()) {
            ExcerptTailer tailer = rqueue.createTailer();
            Future f = reader.submit(() -> {
                long index;
                do {
                    try (DocumentContext documentContext = tailer.readingDocument()) {
                        System.out.println("tailer.state: " + tailer.state());
                        // index is only meaningful if present.
                        index = documentContext.index();
                        // if (documentContext.isPresent())
                        final boolean present = documentContext.isPresent();
                        System.out.println("documentContext.isPresent=" + present + (present ? ",index=" + Long.toHexString(index) : ", no index"));
                        Jvm.pause(50);
                    }
                } while (index != 0x200000000L && !reader.isShutdown());
            });
            timeProvider.currentTimeMillis(2000);
            ((SingleChronicleQueueExcerpts.StoreAppender) wqueue.acquireAppender()).writeEndOfCycleIfRequired();
            Jvm.pause(200);
            wqueue.acquireAppender().writeText("hello world");
            f.get();
        }
    }
}
Also used : RollingChronicleQueue(net.openhft.chronicle.queue.impl.RollingChronicleQueue) Future(java.util.concurrent.Future) DocumentContext(net.openhft.chronicle.wire.DocumentContext) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) File(java.io.File) MappedFile(net.openhft.chronicle.bytes.MappedFile) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Test(org.junit.Test)

Example 14 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class LastAppendedTest method testLastWritten.

@Test
public void testLastWritten() {
    SetTimeProvider timeProvider = new SetTimeProvider();
    try (SingleChronicleQueue outQueue = single(getTmpDir()).rollCycle(RollCycles.TEST_SECONDLY).sourceId(1).timeProvider(timeProvider).build()) {
        try (SingleChronicleQueue inQueue = single(getTmpDir()).rollCycle(RollCycles.TEST_SECONDLY).sourceId(2).timeProvider(timeProvider).build()) {
            // write some initial data to the inqueue
            final Msg msg = inQueue.acquireAppender().methodWriterBuilder(Msg.class).recordHistory(true).build();
            msg.msg("somedata-0");
            timeProvider.advanceMillis(1000);
            // write data into the inQueue
            msg.msg("somedata-1");
            // read a message on the in queue and write it to the out queue
            {
                Msg out = outQueue.acquireAppender().methodWriterBuilder(Msg.class).recordHistory(true).build();
                MethodReader methodReader = inQueue.createTailer().methodReader((Msg) out::msg);
                // reads the somedata-0
                methodReader.readOne();
                // reads the somedata-1
                methodReader.readOne();
            }
            // write data into the inQueue
            msg.msg("somedata-2");
            timeProvider.advanceMillis(2000);
            msg.msg("somedata-3");
            msg.msg("somedata-4");
            System.out.println(inQueue.dump());
            AtomicReference<String> actualValue = new AtomicReference<>();
            // check that we are able to pick up from where we left off, in other words the next read should be somedata-2
            {
                ExcerptTailer excerptTailer = inQueue.createTailer().afterLastWritten(outQueue);
                MethodReader methodReader = excerptTailer.methodReader((Msg) actualValue::set);
                methodReader.readOne();
                Assert.assertEquals("somedata-2", actualValue.get());
                methodReader.readOne();
                Assert.assertEquals("somedata-3", actualValue.get());
                methodReader.readOne();
                Assert.assertEquals("somedata-4", actualValue.get());
            }
        }
    }
}
Also used : SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) MethodReader(net.openhft.chronicle.bytes.MethodReader) Test(org.junit.Test)

Example 15 with SetTimeProvider

use of net.openhft.chronicle.core.time.SetTimeProvider in project Chronicle-Queue by OpenHFT.

the class RollingCycleTest method testRollCycle.

@Test
public void testRollCycle() throws InterruptedException {
    SetTimeProvider stp = new SetTimeProvider();
    long start = System.currentTimeMillis() - 3 * 86_400_000;
    stp.currentTimeMillis(start);
    String basePath = OS.TARGET + "/testRollCycle" + System.nanoTime();
    try (final ChronicleQueue queue = ChronicleQueueBuilder.single(basePath).testBlockSize().timeoutMS(5).rollCycle(RollCycles.TEST_DAILY).timeProvider(stp).build()) {
        final ExcerptAppender appender = queue.acquireAppender().lazyIndexing(lazyIndexing);
        int numWritten = 0;
        for (int h = 0; h < 3; h++) {
            stp.currentTimeMillis(start + TimeUnit.DAYS.toMillis(h));
            for (int i = 0; i < 3; i++) {
                appender.writeBytes(new TestBytesMarshallable(i));
                numWritten++;
            }
        }
        String expectedEager = "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    730,\n" + "    3135326126082\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 442,\n" + "    lastIndex: 3\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: -1\n" + "--- !!meta-data #binary\n" + "index2index: [\n" + "  # length: 8, used: 1\n" + "  544,\n" + "  0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 544, header: -1\n" + "--- !!meta-data #binary\n" + "index: [\n" + "  # length: 8, used: 3\n" + "  640,\n" + "  685,\n" + "  730,\n" + "  0, 0, 0, 0, 0\n" + "]\n" + "# position: 640, header: 0\n" + "--- !!data #binary\n" + "00000280             10 6e 61 6d  65 5f 2d 31 31 35 35 34     ·nam e_-11554\n" + "00000290 38 34 35 37 36 7a cb 93  3d 38 51 d9 d4 f6 c9 2d 84576z·· =8Q····-\n" + "000002a0 a3 bd 70 39 9b b7 70 e9  8c 39 f0 1d 4f          ··p9··p· ·9··O   \n" + "# position: 685, header: 1\n" + "--- !!data #binary\n" + "000002b0    10 6e 61 6d 65 5f 2d  31 31 35 35 38 36 39 33  ·name_- 11558693\n" + "000002c0 32 35 6f 0e fb 68 d8 9c  b8 19 fc cc 2c 35 92 f9 25o··h·· ····,5··\n" + "000002d0 4d 68 e5 f1 2c 55 f0 b8  46 09                   Mh··,U·· F·      \n" + "# position: 730, header: 2\n" + "--- !!data #binary\n" + "000002d0                                            10 6e                ·n\n" + "000002e0 61 6d 65 5f 2d 31 31 35  34 37 31 35 30 37 39 90 ame_-115 4715079·\n" + "000002f0 45 c5 e6 f7 b9 1a 4b ea  c3 2f 7f 17 5f 10 01 5c E·····K· ·/··_··\\\n" + "00000300 6e 62 fc cc 5e cc da                             nb··^··          \n" + "# position: 775, header: 2 EOF\n" + "--- !!not-ready-meta-data! #binary\n" + "...\n" + "# 130293 bytes remaining\n" + "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    730,\n" + "    3135326126082\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 442,\n" + "    lastIndex: 3\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: -1\n" + "--- !!meta-data #binary\n" + "index2index: [\n" + "  # length: 8, used: 1\n" + "  544,\n" + "  0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 544, header: -1\n" + "--- !!meta-data #binary\n" + "index: [\n" + "  # length: 8, used: 3\n" + "  640,\n" + "  685,\n" + "  730,\n" + "  0, 0, 0, 0, 0\n" + "]\n" + "# position: 640, header: 0\n" + "--- !!data #binary\n" + "00000280             10 6e 61 6d  65 5f 2d 31 31 35 35 34     ·nam e_-11554\n" + "00000290 38 34 35 37 36 7a cb 93  3d 38 51 d9 d4 f6 c9 2d 84576z·· =8Q····-\n" + "000002a0 a3 bd 70 39 9b b7 70 e9  8c 39 f0 1d 4f          ··p9··p· ·9··O   \n" + "# position: 685, header: 1\n" + "--- !!data #binary\n" + "000002b0    10 6e 61 6d 65 5f 2d  31 31 35 35 38 36 39 33  ·name_- 11558693\n" + "000002c0 32 35 6f 0e fb 68 d8 9c  b8 19 fc cc 2c 35 92 f9 25o··h·· ····,5··\n" + "000002d0 4d 68 e5 f1 2c 55 f0 b8  46 09                   Mh··,U·· F·      \n" + "# position: 730, header: 2\n" + "--- !!data #binary\n" + "000002d0                                            10 6e                ·n\n" + "000002e0 61 6d 65 5f 2d 31 31 35  34 37 31 35 30 37 39 90 ame_-115 4715079·\n" + "000002f0 45 c5 e6 f7 b9 1a 4b ea  c3 2f 7f 17 5f 10 01 5c E·····K· ·/··_··\\\n" + "00000300 6e 62 fc cc 5e cc da                             nb··^··          \n" + "# position: 775, header: 2 EOF\n" + "--- !!not-ready-meta-data! #binary\n" + "...\n" + "# 130293 bytes remaining\n" + "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    730,\n" + "    3135326126082\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 442,\n" + "    lastIndex: 3\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: -1\n" + "--- !!meta-data #binary\n" + "index2index: [\n" + "  # length: 8, used: 1\n" + "  544,\n" + "  0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 544, header: -1\n" + "--- !!meta-data #binary\n" + "index: [\n" + "  # length: 8, used: 3\n" + "  640,\n" + "  685,\n" + "  730,\n" + "  0, 0, 0, 0, 0\n" + "]\n" + "# position: 640, header: 0\n" + "--- !!data #binary\n" + "00000280             10 6e 61 6d  65 5f 2d 31 31 35 35 34     ·nam e_-11554\n" + "00000290 38 34 35 37 36 7a cb 93  3d 38 51 d9 d4 f6 c9 2d 84576z·· =8Q····-\n" + "000002a0 a3 bd 70 39 9b b7 70 e9  8c 39 f0 1d 4f          ··p9··p· ·9··O   \n" + "# position: 685, header: 1\n" + "--- !!data #binary\n" + "000002b0    10 6e 61 6d 65 5f 2d  31 31 35 35 38 36 39 33  ·name_- 11558693\n" + "000002c0 32 35 6f 0e fb 68 d8 9c  b8 19 fc cc 2c 35 92 f9 25o··h·· ····,5··\n" + "000002d0 4d 68 e5 f1 2c 55 f0 b8  46 09                   Mh··,U·· F·      \n" + "# position: 730, header: 2\n" + "--- !!data #binary\n" + "000002d0                                            10 6e                ·n\n" + "000002e0 61 6d 65 5f 2d 31 31 35  34 37 31 35 30 37 39 90 ame_-115 4715079·\n" + "000002f0 45 c5 e6 f7 b9 1a 4b ea  c3 2f 7f 17 5f 10 01 5c E·····K· ·/··_··\\\n" + "00000300 6e 62 fc cc 5e cc da                             nb··^··          \n" + "...\n" + "# 130293 bytes remaining\n";
        String expectedLazy = "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    532,\n" + "    0\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 0,\n" + "    lastIndex: 0\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: 0\n" + "--- !!data #binary\n" + "000001b0                                            10 6e                ·n\n" + "000001c0 61 6d 65 5f 2d 31 31 35  35 34 38 34 35 37 36 7a ame_-115 5484576z\n" + "000001d0 cb 93 3d 38 51 d9 d4 f6  c9 2d a3 bd 70 39 9b b7 ··=8Q··· ·-··p9··\n" + "000001e0 70 e9 8c 39 f0 1d 4f                             p··9··O          \n" + "# position: 487, header: 1\n" + "--- !!data #binary\n" + "000001e0                                   10 6e 61 6d 65             ·name\n" + "000001f0 5f 2d 31 31 35 35 38 36  39 33 32 35 6f 0e fb 68 _-115586 9325o··h\n" + "00000200 d8 9c b8 19 fc cc 2c 35  92 f9 4d 68 e5 f1 2c 55 ······,5 ··Mh··,U\n" + "00000210 f0 b8 46 09                                      ··F·             \n" + "# position: 532, header: 2\n" + "--- !!data #binary\n" + "00000210                          10 6e 61 6d 65 5f 2d 31          ·name_-1\n" + "00000220 31 35 34 37 31 35 30 37  39 90 45 c5 e6 f7 b9 1a 15471507 9·E·····\n" + "00000230 4b ea c3 2f 7f 17 5f 10  01 5c 6e 62 fc cc 5e cc K··/··_· ·\\nb··^·\n" + "00000240 da                                               ·                \n" + "# position: 577, header: 2 EOF\n" + "--- !!not-ready-meta-data! #binary\n" + "...\n" + "# 130491 bytes remaining\n" + "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    532,\n" + "    0\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 0,\n" + "    lastIndex: 0\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: 0\n" + "--- !!data #binary\n" + "000001b0                                            10 6e                ·n\n" + "000001c0 61 6d 65 5f 2d 31 31 35  35 34 38 34 35 37 36 7a ame_-115 5484576z\n" + "000001d0 cb 93 3d 38 51 d9 d4 f6  c9 2d a3 bd 70 39 9b b7 ··=8Q··· ·-··p9··\n" + "000001e0 70 e9 8c 39 f0 1d 4f                             p··9··O          \n" + "# position: 487, header: 1\n" + "--- !!data #binary\n" + "000001e0                                   10 6e 61 6d 65             ·name\n" + "000001f0 5f 2d 31 31 35 35 38 36  39 33 32 35 6f 0e fb 68 _-115586 9325o··h\n" + "00000200 d8 9c b8 19 fc cc 2c 35  92 f9 4d 68 e5 f1 2c 55 ······,5 ··Mh··,U\n" + "00000210 f0 b8 46 09                                      ··F·             \n" + "# position: 532, header: 2\n" + "--- !!data #binary\n" + "00000210                          10 6e 61 6d 65 5f 2d 31          ·name_-1\n" + "00000220 31 35 34 37 31 35 30 37  39 90 45 c5 e6 f7 b9 1a 15471507 9·E·····\n" + "00000230 4b ea c3 2f 7f 17 5f 10  01 5c 6e 62 fc cc 5e cc K··/··_· ·\\nb··^·\n" + "00000240 da                                               ·                \n" + "# position: 577, header: 2 EOF\n" + "--- !!not-ready-meta-data! #binary\n" + "...\n" + "# 130491 bytes remaining\n" + "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + "  wireType: !WireType BINARY_LIGHT,\n" + "  writePosition: [\n" + "    532,\n" + "    0\n" + "  ],\n" + "  roll: !SCQSRoll {\n" + "    length: !int 86400000,\n" + "    format: yyyyMMdd,\n" + "    epoch: 0\n" + "  },\n" + "  indexing: !SCQSIndexing {\n" + "    indexCount: 8,\n" + "    indexSpacing: 1,\n" + "    index2Index: 0,\n" + "    lastIndex: 0\n" + "  },\n" + "  lastAcknowledgedIndexReplicated: -1,\n" + "  recovery: !TimedStoreRecovery {\n" + "    timeStamp: 0\n" + "  },\n" + "  deltaCheckpointInterval: 0,\n" + "  lastIndexReplicated: -1,\n" + "  sourceId: 0\n" + "}\n" + "# position: 442, header: 0\n" + "--- !!data #binary\n" + "000001b0                                            10 6e                ·n\n" + "000001c0 61 6d 65 5f 2d 31 31 35  35 34 38 34 35 37 36 7a ame_-115 5484576z\n" + "000001d0 cb 93 3d 38 51 d9 d4 f6  c9 2d a3 bd 70 39 9b b7 ··=8Q··· ·-··p9··\n" + "000001e0 70 e9 8c 39 f0 1d 4f                             p··9··O          \n" + "# position: 487, header: 1\n" + "--- !!data #binary\n" + "000001e0                                   10 6e 61 6d 65             ·name\n" + "000001f0 5f 2d 31 31 35 35 38 36  39 33 32 35 6f 0e fb 68 _-115586 9325o··h\n" + "00000200 d8 9c b8 19 fc cc 2c 35  92 f9 4d 68 e5 f1 2c 55 ······,5 ··Mh··,U\n" + "00000210 f0 b8 46 09                                      ··F·             \n" + "# position: 532, header: 2\n" + "--- !!data #binary\n" + "00000210                          10 6e 61 6d 65 5f 2d 31          ·name_-1\n" + "00000220 31 35 34 37 31 35 30 37  39 90 45 c5 e6 f7 b9 1a 15471507 9·E·····\n" + "00000230 4b ea c3 2f 7f 17 5f 10  01 5c 6e 62 fc cc 5e cc K··/··_· ·\\nb··^·\n" + "00000240 da                                               ·                \n" + "...\n" + "# 130491 bytes remaining\n";
        assertEquals(lazyIndexing ? expectedLazy : expectedEager, queue.dump());
        System.out.println("Wrote: " + numWritten + " messages");
        long numRead = 0;
        final TestBytesMarshallable reusableData = new TestBytesMarshallable(0);
        final ExcerptTailer currentPosTailer = queue.createTailer().toStart();
        final ExcerptTailer endPosTailer = queue.createTailer().toEnd();
        while (currentPosTailer.index() < endPosTailer.index()) {
            try {
                assertTrue(currentPosTailer.readBytes(reusableData));
            } catch (AssertionError e) {
                System.err.println("Could not read data at index: " + numRead + " " + Long.toHexString(currentPosTailer.cycle()) + " " + Long.toHexString(currentPosTailer.index()) + " " + e.getMessage() + " " + e);
                throw e;
            }
            numRead++;
        }
        assertFalse(currentPosTailer.readBytes(reusableData));
        System.out.println("Wrote " + numWritten + " Read " + numRead);
        try {
            IOTools.deleteDirWithFiles(basePath, 2);
        } catch (IORuntimeException e) {
            e.printStackTrace();
        }
    }
}
Also used : IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) SetTimeProvider(net.openhft.chronicle.core.time.SetTimeProvider) Test(org.junit.Test)

Aggregations

SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)21 RollingChronicleQueue (net.openhft.chronicle.queue.impl.RollingChronicleQueue)13 Test (org.junit.Test)10 File (java.io.File)7 MappedFile (net.openhft.chronicle.bytes.MappedFile)5 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)5 RollCycles (net.openhft.chronicle.queue.RollCycles)5 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)4 DocumentContext (net.openhft.chronicle.wire.DocumentContext)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)2 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Future (java.util.concurrent.Future)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Bytes (net.openhft.chronicle.bytes.Bytes)1 MethodReader (net.openhft.chronicle.bytes.MethodReader)1 IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)1