Search in sources :

Example 1 with ChronicleHistoryReader

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

the class ChronicleHistoryReaderMain method run.

protected void run(String[] args) {
    final Options options = options();
    final CommandLine commandLine = parseCommandLine(args, options);
    final ChronicleHistoryReader chronicleHistoryReader = chronicleHistoryReader();
    setup(commandLine, chronicleHistoryReader);
    chronicleHistoryReader.execute();
}
Also used : ChronicleHistoryReader(net.openhft.chronicle.queue.reader.ChronicleHistoryReader)

Example 2 with ChronicleHistoryReader

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

the class ChronicleHistoryReaderTest method checkWithQueueHistoryRecordHistoryInitial.

private void checkWithQueueHistoryRecordHistoryInitial(Class<? extends DummyListener> dummyClass) {
    expectException("Overriding sourceId from existing metadata, was 0, overriding to");
    MessageHistory.set(null);
    int extraTiming = 1;
    File queuePath1 = IOTools.createTempFile("testWithQueueHistory1-");
    File queuePath2 = IOTools.createTempFile("testWithQueueHistory2-");
    File queuePath3 = IOTools.createTempFile("testWithQueueHistory3-");
    try {
        try (ChronicleQueue out = queue(queuePath1, 1)) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(dummyClass).useMethodIds(true).get();
            // this will write the 1st timestamps
            writer.say("hello");
        }
        try (ChronicleQueue in = queue(queuePath1, 1);
            ChronicleQueue out = queue(queuePath2, 2)) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(dummyClass).get();
            final AtomicInteger numberRead = new AtomicInteger();
            // if this listener is a DummyListener then messages with methodId won't be routed to it
            DummyListenerId dummy = msg -> {
                numberRead.incrementAndGet();
                MessageHistory history = MessageHistory.get();
                Assert.assertEquals(1, history.sources());
                // written 1st then received by me
                Assert.assertEquals(1 + extraTiming, history.timings());
                // this writes 2 more timestamps
                writer.say(msg);
            };
            MethodReader reader = in.createTailer().methodReader(dummy);
            assertTrue(reader.readOne());
            assertEquals("check routed to correct dest", 1, numberRead.get());
            assertFalse(reader.readOne());
        }
        try (ChronicleQueue in = queue(queuePath2, 2);
            ChronicleQueue out = queue(queuePath3, 3)) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(dummyClass).get();
            final AtomicInteger numberRead = new AtomicInteger();
            DummyListenerId dummy = msg -> {
                numberRead.incrementAndGet();
                MessageHistory history = MessageHistory.get();
                Assert.assertEquals(2, history.sources());
                Assert.assertEquals(3 + extraTiming, history.timings());
                // this writes 2 more timestamps
                writer.say(msg);
            };
            MethodReader reader = in.createTailer().methodReader(dummy);
            assertTrue(reader.readOne());
            assertEquals("check routed to correct dest", 1, numberRead.get());
            assertFalse(reader.readOne());
        }
        ChronicleHistoryReader chronicleHistoryReader = new ChronicleHistoryReader().withBasePath(queuePath3.toPath()).withTimeUnit(TimeUnit.MICROSECONDS).withMessageSink(System.out::println);
        Map<String, Histogram> histos = chronicleHistoryReader.readChronicle();
        chronicleHistoryReader.outputData();
        Assert.assertEquals(5, histos.size());
        Assert.assertEquals("[1, startTo1, 2, 1to2, endToEnd]", histos.keySet().toString());
    } finally {
        IOTools.deleteDirWithFiles(queuePath1.toString(), queuePath2.toString(), queuePath3.toString());
    }
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) MessageHistory(net.openhft.chronicle.wire.MessageHistory) Histogram(net.openhft.chronicle.core.util.Histogram) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Test(org.junit.Test) ChronicleHistoryReader(net.openhft.chronicle.queue.reader.ChronicleHistoryReader) File(java.io.File) MethodId(net.openhft.chronicle.bytes.MethodId) TimeUnit(java.util.concurrent.TimeUnit) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOTools(net.openhft.chronicle.core.io.IOTools) Map(java.util.Map) QueueTestCommon(net.openhft.chronicle.queue.QueueTestCommon) OS(net.openhft.chronicle.core.OS) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Histogram(net.openhft.chronicle.core.util.Histogram) ChronicleHistoryReader(net.openhft.chronicle.queue.reader.ChronicleHistoryReader) MessageHistory(net.openhft.chronicle.wire.MessageHistory) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) MethodReader(net.openhft.chronicle.bytes.MethodReader)

Aggregations

ChronicleHistoryReader (net.openhft.chronicle.queue.reader.ChronicleHistoryReader)2 File (java.io.File)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MethodId (net.openhft.chronicle.bytes.MethodId)1 MethodReader (net.openhft.chronicle.bytes.MethodReader)1 OS (net.openhft.chronicle.core.OS)1 IOTools (net.openhft.chronicle.core.io.IOTools)1 Histogram (net.openhft.chronicle.core.util.Histogram)1 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)1 QueueTestCommon (net.openhft.chronicle.queue.QueueTestCommon)1 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)1 MessageHistory (net.openhft.chronicle.wire.MessageHistory)1 NotNull (org.jetbrains.annotations.NotNull)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1