use of org.agrona.collections.MutableInteger in project Aeron by real-logic.
the class ClusterNodeTest method shouldSendResponseAfterServiceMessage.
@Test
@InterruptAfter(10)
public void shouldSendResponseAfterServiceMessage() {
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
final MutableInteger messageCount = new MutableInteger();
final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchServiceMessageIngressService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
use of org.agrona.collections.MutableInteger in project Aeron by real-logic.
the class StatusUtil method receiveChannelStatus.
/**
* Return the read-only status indicator for the given receive channel URI.
*
* @param countersReader that holds the status indicator.
* @param channel for the receive channel.
* @return read-only status indicator that can be used to query the status of the receive channel or null.
* @see ChannelEndpointStatus for status values and indications.
*/
public static StatusIndicatorReader receiveChannelStatus(final CountersReader countersReader, final String channel) {
StatusIndicatorReader statusReader = null;
final MutableInteger id = new MutableInteger(-1);
countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
if (typeId == ReceiveChannelStatus.RECEIVE_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 CatalogWithJumboRecordingsAndGapsTest method listRecordingsForUri.
@ParameterizedTest
@InterruptAfter(10)
@MethodSource("listRecordingsForUriArguments")
void listRecordingsForUri(final long fromRecordingId, final int recordCount, final String channelFragment, final int streamId, final int expectedRecordCount) {
final MutableInteger callCount = new MutableInteger();
final int count = aeronArchive.listRecordingsForUri(fromRecordingId, recordCount, channelFragment, streamId, (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId1, strippedChannel, originalChannel, sourceIdentity) -> callCount.increment());
assertEquals(expectedRecordCount, count);
assertEquals(expectedRecordCount, callCount.get());
}
use of org.agrona.collections.MutableInteger in project Aeron by real-logic.
the class StopStartSecondSubscriberTest method shouldReceiveMessagesAfterStopStart.
private void shouldReceiveMessagesAfterStopStart(final String channelOne, final int streamOne, final String channelTwo, final int streamTwo) {
final int numMessages = 1;
final MutableInteger subscriber2AfterRestartCount = new MutableInteger();
final AtomicBoolean running = new AtomicBoolean(true);
final CountDownLatch latch = new CountDownLatch(2);
final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> subscriber2AfterRestartCount.value++;
launch(channelOne, streamOne, channelTwo, streamTwo);
buffer.putInt(0, 1);
final ExecutorService executor = Executors.newFixedThreadPool(2);
try {
executor.execute(() -> doPublisherWork(publicationOne, running, latch));
executor.execute(() -> doPublisherWork(publicationTwo, running, latch));
final MutableInteger fragmentsReadOne = new MutableInteger();
final MutableInteger fragmentsReadTwo = new MutableInteger();
final BooleanSupplier fragmentsReadCondition = () -> fragmentsReadOne.get() >= numMessages && fragmentsReadTwo.get() >= numMessages;
Tests.executeUntil(fragmentsReadCondition, (i) -> {
fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1);
fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandlerTwo, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900));
assertTrue(subOneCount.get() >= numMessages);
assertTrue(subTwoCount.get() >= numMessages);
subscriptionTwo.close();
fragmentsReadOne.set(0);
fragmentsReadTwo.set(0);
subscriptionTwo = subscriberTwo.addSubscription(channelTwo, streamTwo);
Tests.executeUntil(fragmentsReadCondition, (i) -> {
fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1);
fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900));
running.set(false);
latch.await();
assertTrue(subOneCount.get() >= numMessages * 2, "Expecting subscriberOne to receive messages the entire time");
assertTrue(subTwoCount.get() >= numMessages, "Expecting subscriberTwo to receive messages before being stopped and started");
assertTrue(subscriber2AfterRestartCount.get() >= numMessages, "Expecting subscriberTwo to receive messages after being stopped and started");
} catch (final InterruptedException ex) {
fail("Interrupted", ex);
} finally {
running.set(false);
executor.shutdownNow();
}
}
use of org.agrona.collections.MutableInteger in project Aeron by real-logic.
the class ExtendRecordingTest method consume.
private static void consume(final Subscription subscription, final int startIndex, final int count) {
final MutableInteger received = new MutableInteger(startIndex);
final FragmentHandler fragmentHandler = new FragmentAssembler((buffer, offset, length, header) -> {
final String expected = MESSAGE_PREFIX + received.value;
final String actual = buffer.getStringWithoutLengthAscii(offset, length);
assertEquals(expected, actual);
received.value++;
});
while (received.value < (startIndex + count)) {
if (0 == subscription.poll(fragmentHandler, ArchiveSystemTests.FRAGMENT_LIMIT)) {
Tests.yield();
}
}
assertEquals(startIndex + count, received.get());
}
Aggregations