use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class OrderManagerTest method testWithQueueHistory.
/*
When all the tests are run gets
[main] WARN net.openhft.chronicle.queue.micros.OrderManagerTest$$Lambda$478/807322507 - Failure to dispatch message: onOrder [!Order {
symbol: EURUSD,
side: Buy,
limitPrice: 1.1167,
quantity: 1E6
}
]
java.lang.AssertionError: expected:<4> but was:<7>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:631)
at net.openhft.chronicle.queue.micros.OrderManagerTest.lambda$testWithQueueHistory$0(OrderManagerTest.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.openhft.chronicle.wire.MethodReader.invoke(MethodReader.java:284)
at net.openhft.chronicle.wire.MethodReader.lambda$addParseletForMethod$3(MethodReader.java:164)
at net.openhft.chronicle.wire.WireParser.parseOne(WireParser.java:41)
at net.openhft.chronicle.wire.WireParser.accept(WireParser.java:49)
at net.openhft.chronicle.wire.MethodReader.readOne(MethodReader.java:311)
at net.openhft.chronicle.queue.micros.OrderManagerTest.testWithQueueHistory(OrderManagerTest.java:165)
*/
@Ignore("TODO FIX")
@Test
public void testWithQueueHistory() {
File queuePath = new File(OS.TARGET, "testWithQueueHistory-" + System.nanoTime());
File queuePath2 = new File(OS.TARGET, "testWithQueueHistory-down-" + System.nanoTime());
try {
try (SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().build()) {
OrderIdeaListener orderManager = out.acquireAppender().methodWriterBuilder(OrderIdeaListener.class).addInterface(MarketDataListener.class).recordHistory(true).get();
SidedMarketDataCombiner combiner = new SidedMarketDataCombiner((MarketDataListener) orderManager);
// events in
// not expected to trigger
orderManager.onOrderIdea(new OrderIdea("EURUSD", Side.Buy, 1.1180, 2e6));
combiner.onSidedPrice(new SidedPrice("EURUSD", 123456789000L, Side.Sell, 1.1172, 2e6));
combiner.onSidedPrice(new SidedPrice("EURUSD", 123456789100L, Side.Buy, 1.1160, 2e6));
combiner.onSidedPrice(new SidedPrice("EURUSD", 123456789100L, Side.Buy, 1.1167, 2e6));
// expected to trigger
orderManager.onOrderIdea(new OrderIdea("EURUSD", Side.Buy, 1.1165, 1e6));
}
try (SingleChronicleQueue in = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().sourceId(1).build();
SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath2).testBlockSize().build()) {
OrderListener listener = out.acquireAppender().methodWriterBuilder(OrderListener.class).recordHistory(true).get();
// build our scenario
OrderManager orderManager = new OrderManager(listener);
MethodReader reader = in.createTailer().methodReader(orderManager);
for (int i = 0; i < 5; i++) assertTrue(reader.readOne());
assertFalse(reader.readOne());
// System.out.println(out.dump());
}
try (SingleChronicleQueue in = SingleChronicleQueueBuilder.binary(queuePath2).testBlockSize().sourceId(2).build()) {
MethodReader reader = in.createTailer().methodReader((OrderListener) order -> {
MessageHistory x = MessageHistory.get();
System.out.println(x);
assertEquals(1, x.sourceId(0));
assertEquals(2, x.sourceId(1));
assertEquals(4, x.timings());
});
assertTrue(reader.readOne());
assertFalse(reader.readOne());
}
} finally {
try {
IOTools.shallowDeleteDirWithFiles(queuePath);
IOTools.shallowDeleteDirWithFiles(queuePath2);
} catch (Exception e) {
}
}
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class OrderManagerTest method testRestartingAService.
/*
Fails when all the tests are run, but not this test alone.
*/
@Ignore("TODO FIX")
@Test
public void testRestartingAService() {
File queuePath = new File(OS.TARGET, "testRestartingAService-" + System.nanoTime());
File queuePath2 = new File(OS.TARGET, "testRestartingAService-down-" + System.nanoTime());
try {
try (SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
SidedMarketDataListener combiner = out.acquireAppender().methodWriterBuilder(SidedMarketDataListener.class).recordHistory(true).get();
combiner.onSidedPrice(new SidedPrice("EURUSD1", 123456789000L, Side.Sell, 1.1172, 2e6));
combiner.onSidedPrice(new SidedPrice("EURUSD2", 123456789100L, Side.Buy, 1.1160, 2e6));
for (int i = 2; i < 10; i += 2) {
combiner.onSidedPrice(new SidedPrice("EURUSD3", 123456789100L, Side.Sell, 1.1173, 2.5e6));
combiner.onSidedPrice(new SidedPrice("EURUSD4", 123456789100L, Side.Buy, 1.1167, 1.5e6));
}
}
// TODO FIx for more.
for (int i = 0; i < 10; i++) {
// read one message at a time
try (SingleChronicleQueue in = SingleChronicleQueueBuilder.binary(queuePath).testBlockSize().sourceId(1).build();
SingleChronicleQueue out = SingleChronicleQueueBuilder.binary(queuePath2).testBlockSize().rollCycle(RollCycles.TEST_DAILY).build()) {
ExcerptAppender excerptAppender = out.acquireAppender();
MarketDataListener mdListener = excerptAppender.methodWriterBuilder(MarketDataListener.class).recordHistory(true).get();
SidedMarketDataCombiner combiner = new SidedMarketDataCombiner(mdListener);
ExcerptTailer tailer = in.createTailer().afterLastWritten(out);
assertEquals(i, in.rollCycle().toSequenceNumber(tailer.index()));
MethodReader reader = tailer.methodReader(combiner);
// System.out.println("#### IN\n" + in.dump());
// System.out.println("#### OUT:\n" + out.dump());
assertTrue("i: " + i, reader.readOne());
}
}
} finally {
try {
IOTools.shallowDeleteDirWithFiles(queuePath);
IOTools.shallowDeleteDirWithFiles(queuePath2);
} catch (Exception e) {
}
}
}
use of net.openhft.chronicle.bytes.MethodReader 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.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class EventLoopServiceWrapper method action.
@Override
public boolean action() throws InvalidEventHandlerException, InterruptedException {
if (isClosed()) {
Closeable.closeQuietly(serviceImpl);
Closeable.closeQuietly(serviceIn);
Closeable.closeQuietly(outputQueue);
Closeable.closeQuietly(inputQueues);
throw new InvalidEventHandlerException();
}
boolean busy = false;
for (MethodReader reader : serviceIn) {
busy |= reader.readOne();
}
return busy;
}
use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.
the class ServiceWrapperBuilder method outputReader.
@NotNull
public MethodReader outputReader(Object... impls) {
SingleChronicleQueue queue = outputQueue();
MethodReader reader = queue.createTailer().methodReader(impls);
reader.closeIn(true);
return reader;
}
Aggregations