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));
}
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());
}
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;
}
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;
}
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);
}
Aggregations