use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class MultiDestinationCastTest method shouldManuallyRemovePortDuringActiveStream.
@Test(timeout = 10_000)
public void shouldManuallyRemovePortDuringActiveStream() throws Exception {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
final int numMessageForSub2 = 10;
final CountDownLatch unavailableImage = new CountDownLatch(1);
driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
launch();
publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
subscriptionA = clientA.addSubscription(SUB1_MDC_MANUAL_URI, STREAM_ID);
subscriptionB = clientB.addSubscription(SUB2_MDC_MANUAL_URI, STREAM_ID, null, (image) -> unavailableImage.countDown());
publication.addDestination(SUB1_MDC_MANUAL_URI);
publication.addDestination(SUB2_MDC_MANUAL_URI);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected()) {
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);
if (i < numMessageForSub2) {
pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
} else {
fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
Thread.yield();
}
if (i == numMessageForSub2 - 1) {
publication.removeDestination(SUB2_MDC_MANUAL_URI);
}
}
unavailableImage.await();
verifyFragments(fragmentHandlerA, numMessagesToSend);
verifyFragments(fragmentHandlerB, numMessageForSub2);
}
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);
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class MultiDestinationCastTest method shouldSendToTwoPortsWithManualSingleDriver.
@Test(timeout = 10_000)
public void shouldSendToTwoPortsWithManualSingleDriver() {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
launch();
publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
subscriptionA = clientA.addSubscription(SUB1_MDC_MANUAL_URI, STREAM_ID);
subscriptionB = clientA.addSubscription(SUB2_MDC_MANUAL_URI, STREAM_ID);
publication.addDestination(SUB1_MDC_MANUAL_URI);
publication.addDestination(SUB2_MDC_MANUAL_URI);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected()) {
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);
}
verifyFragments(fragmentHandlerA, numMessagesToSend);
verifyFragments(fragmentHandlerB, numMessagesToSend);
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class MultiDriverTest method shouldJoinExistingIdleStreamWithLockStepSendingReceiving.
@Test(timeout = 10_000)
public void shouldJoinExistingIdleStreamWithLockStepSendingReceiving() throws Exception {
final int numMessagesToSendPreJoin = 0;
final int numMessagesToSendPostJoin = NUM_MESSAGES_PER_TERM;
launch();
publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
while (!publication.isConnected() && !subscriptionA.isConnected()) {
SystemTest.checkInterruptedStatus();
Thread.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) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
fragmentsRead.set(0);
SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
}
assertThat(fragmentCountA.value, is(numMessagesToSendPreJoin + numMessagesToSendPostJoin));
assertThat(fragmentCountB.value, is(numMessagesToSendPostJoin));
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class PongTest method playPingPongWithRestart.
@Ignore
@Test
public void playPingPongWithRestart() throws Exception {
buffer.putInt(0, 1);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
SystemTest.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()) {
SystemTest.checkInterruptedStatus();
Thread.sleep(100);
}
// restart Pong side
pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
pingSubscription = pingClient.addSubscription(PING_URI, PING_STREAM_ID);
fragmentsRead.set(0);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
SystemTest.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