Search in sources :

Example 1 with VanillaMessageHistory

use of net.openhft.chronicle.wire.VanillaMessageHistory in project Chronicle-Queue by OpenHFT.

the class ChronicleHistoryReaderTest method doTest.

private void doTest(boolean recordHistoryFirst) {
    VanillaMessageHistory veh = new VanillaMessageHistory();
    veh.addSourceDetails(true);
    MessageHistory.set(veh);
    int extraTiming = recordHistoryFirst ? 1 : 0;
    long nanoTime = System.nanoTime();
    File queuePath = new File(OS.TARGET, "testWithQueueHistory-" + nanoTime);
    File queuePath2 = new File(OS.TARGET, "testWithQueueHistory2-" + nanoTime);
    File queuePath3 = new File(OS.TARGET, "testWithQueueHistory3-" + nanoTime);
    try {
        try (SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().sourceId(1).build()) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(DummyListener.class).recordHistory(recordHistoryFirst).get();
            writer.say("hello");
        }
        try (SingleChronicleQueue in = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().sourceId(1).build();
            SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath2).testBlockSize().build()) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(DummyListener.class).recordHistory(true).get();
            DummyListener dummy = msg -> {
                MessageHistory history = MessageHistory.get();
                Assert.assertEquals(1, history.sources());
                // written 1st then received by me
                Assert.assertEquals(1 + extraTiming, history.timings());
                writer.say(msg);
            };
            MethodReader reader = in.createTailer().methodReader(dummy);
            assertTrue(reader.readOne());
            assertFalse(reader.readOne());
        }
        try (SingleChronicleQueue in = SingleChronicleQueueBuilder.binary(queuePath2).testBlockSize().sourceId(2).build();
            SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath3).testBlockSize().build()) {
            DummyListener writer = out.acquireAppender().methodWriterBuilder(DummyListener.class).recordHistory(true).get();
            DummyListener dummy = msg -> {
                MessageHistory history = MessageHistory.get();
                Assert.assertEquals(2, history.sources());
                Assert.assertEquals(3 + extraTiming, history.timings());
                writer.say(msg);
            };
            MethodReader reader = in.createTailer().methodReader(dummy);
            assertTrue(reader.readOne());
            assertFalse(reader.readOne());
        }
        ChronicleHistoryReader chronicleHistoryReader = new ChronicleHistoryReader().withBasePath(queuePath3.toPath()).withTimeUnit(TimeUnit.MICROSECONDS);
        Map<String, Histogram> histos = chronicleHistoryReader.readChronicle();
        chronicleHistoryReader.withMessageSink(System.out::println);
        chronicleHistoryReader.outputData();
        if (recordHistoryFirst) {
            Assert.assertEquals(5, histos.size());
            Assert.assertEquals("[1, startTo1, 2, 1to2, endToEnd]", histos.keySet().toString());
        } else {
            Assert.assertEquals(4, histos.size());
            Assert.assertEquals("[1, 2, 1to2, endToEnd]", histos.keySet().toString());
        }
    } finally {
        try {
            IOTools.shallowDeleteDirWithFiles(queuePath);
            IOTools.shallowDeleteDirWithFiles(queuePath2);
            IOTools.shallowDeleteDirWithFiles(queuePath3);
        } catch (Exception e) {
        }
    }
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) MessageHistory(net.openhft.chronicle.wire.MessageHistory) Histogram(net.openhft.chronicle.core.util.Histogram) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) VanillaMessageHistory(net.openhft.chronicle.wire.VanillaMessageHistory) IOTools(net.openhft.chronicle.core.io.IOTools) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Assume(org.junit.Assume) OS(net.openhft.chronicle.core.OS) Assert(org.junit.Assert) Histogram(net.openhft.chronicle.core.util.Histogram) MessageHistory(net.openhft.chronicle.wire.MessageHistory) VanillaMessageHistory(net.openhft.chronicle.wire.VanillaMessageHistory) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) VanillaMessageHistory(net.openhft.chronicle.wire.VanillaMessageHistory) File(java.io.File) MethodReader(net.openhft.chronicle.bytes.MethodReader)

Example 2 with VanillaMessageHistory

use of net.openhft.chronicle.wire.VanillaMessageHistory in project Chronicle-Queue by OpenHFT.

the class MessageHistoryTest method setUp.

@Before
public void setUp() {
    inputQueueDir = getTmpDir();
    middleQueueDir = getTmpDir();
    outputQueueDir = getTmpDir();
    final VanillaMessageHistory messageHistory = new VanillaMessageHistory();
    messageHistory.addSourceDetails(true);
    MessageHistory.set(messageHistory);
}
Also used : VanillaMessageHistory(net.openhft.chronicle.wire.VanillaMessageHistory) Before(org.junit.Before)

Aggregations

VanillaMessageHistory (net.openhft.chronicle.wire.VanillaMessageHistory)2 File (java.io.File)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)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 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)1 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)1 MessageHistory (net.openhft.chronicle.wire.MessageHistory)1 Assert (org.junit.Assert)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assume (org.junit.Assume)1 Before (org.junit.Before)1 Test (org.junit.Test)1