Search in sources :

Example 31 with MutableInteger

use of org.agrona.collections.MutableInteger in project Aeron by real-logic.

the class MinFlowControlSystemTest method shouldRemoveDeadReceiverWithMinMulticastFlowControlStrategy.

@Test
@InterruptAfter(10)
void shouldRemoveDeadReceiverWithMinMulticastFlowControlStrategy() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    final MutableInteger numMessagesLeftToSend = new MutableInteger(numMessagesToSend);
    final MutableInteger numFragmentsReadFromA = new MutableInteger(0);
    final MutableInteger numFragmentsReadFromB = new MutableInteger(0);
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    driverAContext.multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
    launch();
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    awaitConnected(subscriptionA);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
    awaitConnected(subscriptionB);
    awaitConnected(publication);
    boolean isBClosed = false;
    while (numFragmentsReadFromA.get() < numMessagesToSend) {
        int workDone = 0;
        if (numMessagesLeftToSend.get() > 0) {
            final long position = publication.offer(buffer, 0, buffer.capacity());
            if (position >= 0L) {
                numMessagesLeftToSend.decrement();
                workDone++;
            }
        }
        // A keeps up
        final int readA = subscriptionA.poll(fragmentHandlerA, 10);
        numFragmentsReadFromA.addAndGet(readA);
        workDone += readA;
        // B receives up to 1/8 of the messages, then stops
        if (numFragmentsReadFromB.get() < (numMessagesToSend / 8)) {
            final int readB = subscriptionB.poll(fragmentHandlerB, 10);
            numFragmentsReadFromB.addAndGet(readB);
            workDone += readB;
        } else if (!isBClosed) {
            subscriptionB.close();
            isBClosed = true;
        }
        if (0 == workDone) {
            Tests.yieldingIdle(() -> "numMessagesToSend=" + numMessagesToSend + " numMessagesLeftToSend=" + numMessagesLeftToSend + " numFragmentsReadFromA=" + numFragmentsReadFromA + " numFragmentsReadFromB=" + numFragmentsReadFromB);
        }
    }
    verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with MutableInteger

use of org.agrona.collections.MutableInteger in project Aeron by real-logic.

the class SelectorAndTransportTest method shouldSendEmptyDataFrameUnicastFromSourceToReceiver.

@Test
@InterruptAfter(10)
public void shouldSendEmptyDataFrameUnicastFromSourceToReceiver() {
    final MutableInteger dataHeadersReceived = new MutableInteger(0);
    doAnswer((invocation) -> {
        dataHeadersReceived.value++;
        return null;
    }).when(mockDispatcher).onDataPacket(any(ReceiveChannelEndpoint.class), any(DataHeaderFlyweight.class), any(UnsafeBuffer.class), anyInt(), any(InetSocketAddress.class), anyInt());
    receiveChannelEndpoint = new ReceiveChannelEndpoint(RCV_DST, mockDispatcher, mockReceiveStatusIndicator, context);
    sendChannelEndpoint = new SendChannelEndpoint(SRC_DST, mockSendStatusIndicator, context);
    receiveChannelEndpoint.openDatagramChannel(mockReceiveStatusIndicator);
    receiveChannelEndpoint.registerForRead(dataTransportPoller);
    sendChannelEndpoint.openDatagramChannel(mockSendStatusIndicator);
    sendChannelEndpoint.registerForRead(controlTransportPoller);
    encodeDataHeader.wrap(buffer);
    encodeDataHeader.version(HeaderFlyweight.CURRENT_VERSION).flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS).headerType(HeaderFlyweight.HDR_TYPE_DATA).frameLength(FRAME_LENGTH);
    encodeDataHeader.sessionId(SESSION_ID).streamId(STREAM_ID).termId(TERM_ID);
    byteBuffer.position(0).limit(FRAME_LENGTH);
    processLoop(dataTransportPoller, 5);
    sendChannelEndpoint.send(byteBuffer);
    while (dataHeadersReceived.get() < 1) {
        processLoop(dataTransportPoller, 1);
    }
    assertEquals(1, dataHeadersReceived.get());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MutableInteger(org.agrona.collections.MutableInteger) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 33 with MutableInteger

use of org.agrona.collections.MutableInteger in project Aeron by real-logic.

the class StatusUtil method controllableIdleStrategy.

/**
 * Return the controllable idle strategy {@link StatusIndicator}.
 *
 * @param countersReader that holds the status indicator.
 * @return status indicator to use or null if not found.
 */
public static StatusIndicator controllableIdleStrategy(final CountersReader countersReader) {
    StatusIndicator statusIndicator = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, label) -> {
        if (counterId == SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.id() && label.equals(SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.label())) {
            id.value = counterId;
        }
    });
    if (Aeron.NULL_VALUE != id.value) {
        statusIndicator = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value);
    }
    return statusIndicator;
}
Also used : StatusIndicator(org.agrona.concurrent.status.StatusIndicator) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator)

Example 34 with MutableInteger

use of org.agrona.collections.MutableInteger in project Aeron by real-logic.

the class StatusUtil method sendChannelStatus.

/**
 * Return the read-only status indicator for the given send channel URI.
 *
 * @param countersReader that holds the status indicator.
 * @param channel        for the send channel.
 * @return read-only status indicator that can be used to query the status of the send channel or null.
 * @see ChannelEndpointStatus for status values and indications.
 */
public static StatusIndicatorReader sendChannelStatus(final CountersReader countersReader, final String channel) {
    StatusIndicatorReader statusReader = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
        if (typeId == SendChannelStatus.SEND_CHANNEL_STATUS_TYPE_ID) {
            if (channel.startsWith(keyBuffer.getStringAscii(ChannelEndpointStatus.CHANNEL_OFFSET))) {
                id.value = counterId;
            }
        }
    });
    if (Aeron.NULL_VALUE != id.value) {
        statusReader = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value);
    }
    return statusReader;
}
Also used : StatusIndicatorReader(org.agrona.concurrent.status.StatusIndicatorReader) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator)

Example 35 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class MultiDestinationCastTest method shouldSendToTwoPortsWithDynamic.

@Test(timeout = 10_000)
public void shouldSendToTwoPortsWithDynamic() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    launch();
    publication = clientA.addPublication(PUB_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(SUB1_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(SUB2_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionC = clientA.addSubscription(SUB3_MDC_DYNAMIC_URI, STREAM_ID);
    while (subscriptionA.hasNoImages() || subscriptionB.hasNoImages() || subscriptionC.hasNoImages()) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        pollForFragment(subscriptionA, fragmentHandlerA, fragmentsRead);
        fragmentsRead.set(0);
        pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
        fragmentsRead.set(0);
        pollForFragment(subscriptionC, fragmentHandlerC, fragmentsRead);
    }
    verifyFragments(fragmentHandlerA, numMessagesToSend);
    verifyFragments(fragmentHandlerB, numMessagesToSend);
    verifyFragments(fragmentHandlerC, numMessagesToSend);
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.Test)

Aggregations

MutableInteger (org.agrona.collections.MutableInteger)151 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)76 DirectBuffer (org.agrona.DirectBuffer)64 Test (org.junit.jupiter.api.Test)61 InterruptAfter (io.aeron.test.InterruptAfter)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 MethodSource (org.junit.jupiter.params.provider.MethodSource)38 MediaDriver (io.aeron.driver.MediaDriver)34 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)34 Test (org.junit.Test)33 ByteBuffer (java.nio.ByteBuffer)32 CloseHelper (org.agrona.CloseHelper)32 Array32FW (io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW)28 HEADER (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADER)28 HEADERS (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADERS)28 KEY (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY)28 NOT (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.NOT)28 KafkaDeltaType (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaDeltaType)28 KafkaOffsetFW (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaOffsetFW)28 KafkaSkip (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaSkip)28