Search in sources :

Example 1 with HelloWorld

use of net.openhft.chronicle.queue.service.HelloWorld in project Chronicle-Queue by OpenHFT.

the class StoreTailerTest method shouldConsiderSourceIdWhenDeterminingLastWrittenIndex.

@Test
public void shouldConsiderSourceIdWhenDeterminingLastWrittenIndex() throws Exception {
    final SingleChronicleQueue firstInputQueue = createQueue(dataDirectory, RollCycles.TEST_DAILY, 1, "firstInputQueue");
    // different RollCycle means that indicies are not identical to firstInputQueue
    final SingleChronicleQueue secondInputQueue = createQueue(dataDirectory, RollCycles.TEST_SECONDLY, 2, "secondInputQueue");
    final SingleChronicleQueue outputQueue = createQueue(dataDirectory, RollCycles.TEST_DAILY, 0, "outputQueue");
    ;
    final StringEvents firstWriter = firstInputQueue.acquireAppender().methodWriterBuilder(StringEvents.class).get();
    final HelloWorld secondWriter = secondInputQueue.acquireAppender().methodWriterBuilder(HelloWorld.class).get();
    // generate some data in the input queues
    firstWriter.onEvent("one");
    firstWriter.onEvent("two");
    secondWriter.hello("thirteen");
    secondWriter.hello("thirtyOne");
    final StringEvents eventSink = outputQueue.acquireAppender().methodWriterBuilder(StringEvents.class).recordHistory(true).get();
    final CapturingStringEvents outputWriter = new CapturingStringEvents(eventSink);
    final MethodReader firstMethodReader = firstInputQueue.createTailer().methodReader(outputWriter);
    final MethodReader secondMethodReader = secondInputQueue.createTailer().methodReader(outputWriter);
    // replay events from the inputs into the output queue
    assertThat(firstMethodReader.readOne(), is(true));
    assertThat(firstMethodReader.readOne(), is(true));
    assertThat(secondMethodReader.readOne(), is(true));
    assertThat(secondMethodReader.readOne(), is(true));
    // ensures that tailer is not moved to index from the incorrect source
    secondInputQueue.createTailer().afterLastWritten(outputQueue);
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) HelloWorld(net.openhft.chronicle.queue.service.HelloWorld) Test(org.junit.Test)

Aggregations

MethodReader (net.openhft.chronicle.bytes.MethodReader)1 HelloWorld (net.openhft.chronicle.queue.service.HelloWorld)1 Test (org.junit.Test)1