Search in sources :

Example 11 with FragmentHandler

use of io.aeron.logbuffer.FragmentHandler in project Aeron by real-logic.

the class SubscriptionTest method shouldReadDataFromMultipleSources.

@Test
public void shouldReadDataFromMultipleSources() {
    subscription.addImage(imageOneMock);
    subscription.addImage(imageTwoMock);
    when(imageOneMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
        final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
        handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
        return 1;
    });
    when(imageTwoMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
        final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
        handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
        return 1;
    });
    assertThat(subscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT), is(2));
}
Also used : FragmentHandler(io.aeron.logbuffer.FragmentHandler) Test(org.junit.Test)

Aggregations

FragmentHandler (io.aeron.logbuffer.FragmentHandler)11 MediaDriver (io.aeron.driver.MediaDriver)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Test (org.junit.Test)5 Aeron (io.aeron.Aeron)4 Subscription (io.aeron.Subscription)4 ExecutorService (java.util.concurrent.ExecutorService)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)3 ContinueBarrier (org.agrona.console.ContinueBarrier)3 TimeUnit (java.util.concurrent.TimeUnit)2 FragmentAssembler (io.aeron.FragmentAssembler)1 Publication (io.aeron.Publication)1 BufferClaim (io.aeron.logbuffer.BufferClaim)1 Header (io.aeron.logbuffer.Header)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BitUtil (org.agrona.BitUtil)1 LangUtil (org.agrona.LangUtil)1 BackoffIdleStrategy (org.agrona.concurrent.BackoffIdleStrategy)1