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) {
}
}
}
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);
}
Aggregations