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 shouldReceivePublishedMessage.
@Test
@InterruptAfter(10)
void shouldReceivePublishedMessage() {
launch(CHANNEL1, STREAM_ID1, CHANNEL2, STREAM_ID2);
buffer.putInt(0, 1);
final int messagesPerPublication = 1;
while (publicationOne.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
while (publicationTwo.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
final MutableInteger fragmentsRead1 = new MutableInteger();
final MutableInteger fragmentsRead2 = new MutableInteger();
Tests.executeUntil(() -> fragmentsRead1.get() >= messagesPerPublication && fragmentsRead2.get() >= messagesPerPublication, (i) -> {
fragmentsRead1.value += subscriptionOne.poll(fragmentHandlerOne, 10);
fragmentsRead2.value += subscriptionTwo.poll(fragmentHandlerTwo, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(9900));
assertEquals(messagesPerPublication, subOneCount.get());
assertEquals(messagesPerPublication, subTwoCount.get());
}
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 MultiDriverTest method shouldJoinExistingIdleStreamWithLockStepSendingReceiving.
@Test
@InterruptAfter(10)
void shouldJoinExistingIdleStreamWithLockStepSendingReceiving() throws InterruptedException {
final int numMessagesToSendPreJoin = 0;
final int numMessagesToSendPostJoin = NUM_MESSAGES_PER_TERM;
launch();
subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
while (!publication.isConnected() && !subscriptionA.isConnected()) {
Tests.yield();
}
final CountDownLatch newImageLatch = new CountDownLatch(1);
subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID, (image) -> newImageLatch.countDown(), null);
newImageLatch.await();
for (int i = 0; i < numMessagesToSendPostJoin; i++) {
while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
Tests.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
fragmentsRead.set(0);
Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
}
assertEquals(numMessagesToSendPreJoin + numMessagesToSendPostJoin, fragmentCountA.value);
assertEquals(numMessagesToSendPostJoin, fragmentCountB.value);
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class PongTest method playPingPongWithRestart.
@SlowTest
@Test
void playPingPongWithRestart() {
buffer.putInt(0, 1);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pongSubscription.poll(pongHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
// close Pong side
pongPublication.close();
pingSubscription.close();
// wait for disconnect to ensure we stay in lock step
while (pingPublication.isConnected()) {
Tests.sleep(10);
}
// restart Pong side
pingSubscription = pingClient.addSubscription(PING_URI, PING_STREAM_ID);
pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
fragmentsRead.set(0);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pongSubscription.poll(pongHandler, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
verify(pongHandler, times(2)).onFragment(any(DirectBuffer.class), eq(DataHeaderFlyweight.HEADER_LENGTH), eq(BitUtil.SIZE_OF_INT), any(Header.class));
}
Aggregations