Search in sources :

Example 1 with MaxMulticastFlowControlSupplier

use of io.aeron.driver.MaxMulticastFlowControlSupplier in project aeron by real-logic.

the class MaxFlowControlStrategySystemTest method shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy.

@Test
@InterruptAfter(10)
void shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    driverAContext.multicastFlowControlSupplier(new MaxMulticastFlowControlSupplier());
    launch();
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
        Tests.yield();
    }
    final MutableInteger fragmentsRead = new MutableInteger();
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            Tests.yield();
        }
        fragmentsRead.set(0);
        // A keeps up
        Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        fragmentsRead.set(0);
        // B receives slowly and eventually can't keep up
        if (i % 10 == 0) {
            Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
                fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 1);
                Thread.yield();
            }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        }
    }
    verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
    verify(fragmentHandlerB, atMost(numMessagesToSend - 1)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) MaxMulticastFlowControlSupplier(io.aeron.driver.MaxMulticastFlowControlSupplier) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 2 with MaxMulticastFlowControlSupplier

use of io.aeron.driver.MaxMulticastFlowControlSupplier in project Aeron by real-logic.

the class MaxFlowControlStrategySystemTest method shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy.

@Test
@InterruptAfter(10)
void shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    driverAContext.multicastFlowControlSupplier(new MaxMulticastFlowControlSupplier());
    launch();
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
        Tests.yield();
    }
    final MutableInteger fragmentsRead = new MutableInteger();
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            Tests.yield();
        }
        fragmentsRead.set(0);
        // A keeps up
        Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        fragmentsRead.set(0);
        // B receives slowly and eventually can't keep up
        if (i % 10 == 0) {
            Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
                fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 1);
                Thread.yield();
            }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        }
    }
    verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
    verify(fragmentHandlerB, atMost(numMessagesToSend - 1)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) MaxMulticastFlowControlSupplier(io.aeron.driver.MaxMulticastFlowControlSupplier) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

MaxMulticastFlowControlSupplier (io.aeron.driver.MaxMulticastFlowControlSupplier)2 Header (io.aeron.logbuffer.Header)2 InterruptAfter (io.aeron.test.InterruptAfter)2 DirectBuffer (org.agrona.DirectBuffer)2 MutableInteger (org.agrona.collections.MutableInteger)2 Test (org.junit.jupiter.api.Test)2