use of net.openhft.chronicle.bytes.MethodId 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());
}
}
Aggregations