use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class Queue28Test method test.
/*
* Tailer doesn't work if created before the appender
*
* See https://higherfrequencytrading.atlassian.net/browse/QUEUE-28
*/
@Test
public void test() throws IOException, InterruptedException {
File dir = getTmpDir();
try (final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(dir, wireType).testBlockSize().build()) {
final ExcerptTailer tailer = queue.createTailer();
assertFalse(tailer.readDocument(r -> r.read(TestKey.test).int32()));
final ExcerptAppender appender = queue.acquireAppender();
appender.writeDocument(w -> w.write(TestKey.test).int32(1));
Jvm.pause(100);
assertTrue(tailer.readDocument(r -> r.read(TestKey.test).int32()));
}
}
use of net.openhft.chronicle.queue.ExcerptAppender 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.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method before.
@Before
public void before() throws Exception {
dataDir = DirectoryUtils.tempDir(ChronicleReaderTest.class.getSimpleName()).toPath();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(dataDir).testBlockSize().build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final MethodWriterBuilder<StringEvents> methodWriterBuilder = excerptAppender.methodWriterBuilder(StringEvents.class);
methodWriterBuilder.recordHistory(true);
final StringEvents events = methodWriterBuilder.build();
for (int i = 0; i < 24; i++) {
events.say(i % 2 == 0 ? "hello" : "goodbye");
}
}
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class ChronicleReaderTest method shouldReadQueueWithNonDefaultRollCycle.
@Test
public void shouldReadQueueWithNonDefaultRollCycle() {
Path path = DirectoryUtils.tempDir("shouldReadQueueWithNonDefaultRollCycle").toPath();
path.toFile().mkdirs();
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).rollCycle(RollCycles.MINUTELY).testBlockSize().build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final MethodWriterBuilder<StringEvents> methodWriterBuilder = excerptAppender.methodWriterBuilder(StringEvents.class);
methodWriterBuilder.recordHistory(true);
final StringEvents events = methodWriterBuilder.build();
for (int i = 0; i < 24; i++) {
events.say(i % 2 == 0 ? "hello" : "goodbye");
}
}
new ChronicleReader().withBasePath(path).withMessageSink(capturedOutput::add).execute();
assertFalse(capturedOutput.isEmpty());
}
use of net.openhft.chronicle.queue.ExcerptAppender in project Chronicle-Queue by OpenHFT.
the class DocumentOrderingTest method codeWithinPriorDocumentMustExecuteBeforeSubsequentDocumentWhenQueueIsEmpty.
@Test
public void codeWithinPriorDocumentMustExecuteBeforeSubsequentDocumentWhenQueueIsEmpty() throws Exception {
try (final SingleChronicleQueue queue = builder(DirectoryUtils.tempDir("document-ordering"), 3_000L).build()) {
final ExcerptAppender excerptAppender = queue.acquireAppender();
final Future<RecordInfo> otherDocumentWriter;
try (final DocumentContext documentContext = excerptAppender.writingDocument()) {
// move time to beyond the next cycle
clock.addAndGet(TimeUnit.SECONDS.toMillis(2L));
otherDocumentWriter = attemptToWriteDocument(queue);
// stall this thread, other thread should not be able to advance,
// since this DocumentContext is still open
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(2L));
documentContext.wire().getValueOut().int32(counter.getAndIncrement());
}
assertEquals(1, otherDocumentWriter.get(5L, TimeUnit.SECONDS).counterValue);
final ExcerptTailer tailer = queue.createTailer();
expectValue(0, tailer);
expectValue(1, tailer);
}
}
Aggregations