use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class MaxFlowControlStrategySystemTest method shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy.
@Test
@InterruptAfter(10)
void shouldTimeoutImageWhenBehindForTooLongWithMaxMulticastFlowControlStrategy() {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
driverAContext.multicastFlowControlSupplier(new MaxMulticastFlowControlSupplier());
launch();
subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
Tests.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
for (int i = 0; i < numMessagesToSend; i++) {
while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
Tests.yield();
}
fragmentsRead.set(0);
// A keeps up
Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
fragmentsRead.set(0);
// B receives slowly and eventually can't keep up
if (i % 10 == 0) {
Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
}
}
verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
verify(fragmentHandlerB, atMost(numMessagesToSend - 1)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class MemoryOrderingTest method shouldReceiveMessagesInOrderWithFirstLongWordIntact.
@Test
@InterruptAfter(10)
void shouldReceiveMessagesInOrderWithFirstLongWordIntact() throws Exception {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
srcBuffer.setMemory(0, MESSAGE_LENGTH, (byte) 7);
try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
final Thread subscriberThread = new Thread(new Subscriber(subscription));
subscriberThread.setDaemon(true);
subscriberThread.start();
for (int i = 0; i < NUM_MESSAGES; i++) {
if (null != failedMessage) {
fail(failedMessage);
}
srcBuffer.putLong(0, i);
while (publication.offer(srcBuffer) < 0L) {
if (null != failedMessage) {
fail(failedMessage);
}
idleStrategy.idle();
Tests.checkInterruptStatus();
}
if (i % BURST_LENGTH == 0) {
final long timeoutNs = System.nanoTime() + INTER_BURST_DURATION_NS;
long nowNs;
do {
nowNs = System.nanoTime();
} while ((timeoutNs - nowNs) > 0);
}
}
subscriberThread.join();
}
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class MemoryOrderingTest method shouldReceiveMessagesInOrderWithFirstLongWordIntactFromExclusivePublication.
@Test
@InterruptAfter(10)
void shouldReceiveMessagesInOrderWithFirstLongWordIntactFromExclusivePublication() throws InterruptedException {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
srcBuffer.setMemory(0, MESSAGE_LENGTH, (byte) 7);
try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
final Thread subscriberThread = new Thread(new Subscriber(subscription));
subscriberThread.setDaemon(true);
subscriberThread.start();
for (int i = 0; i < NUM_MESSAGES; i++) {
if (null != failedMessage) {
fail(failedMessage);
}
srcBuffer.putLong(0, i);
while (publication.offer(srcBuffer) < 0L) {
if (null != failedMessage) {
fail(failedMessage);
}
idleStrategy.idle();
Tests.checkInterruptStatus();
}
if (i % BURST_LENGTH == 0) {
final long timeoutNs = System.nanoTime() + INTER_BURST_DURATION_NS;
long nowNs;
do {
nowNs = System.nanoTime();
} while ((timeoutNs - nowNs) > 0);
}
}
subscriberThread.join();
}
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class LifecycleTest method shouldNotifyOfClientTimestampCounter.
@Test
@InterruptAfter(10)
void shouldNotifyOfClientTimestampCounter() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).errorHandler(Tests::onError);
try (TestMediaDriver mediaDriver = TestMediaDriver.launch(driverCtx, testWatcher)) {
final Aeron.Context clientCtxOne = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
final Aeron.Context clientCtxTwo = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
try (Aeron aeron = Aeron.connect(clientCtxOne)) {
final AvailableCounterHandler availableHandler = mock(AvailableCounterHandler.class);
aeron.addAvailableCounterHandler(availableHandler);
final UnavailableCounterHandler unavailableHandler = mock(UnavailableCounterHandler.class);
aeron.addUnavailableCounterHandler(unavailableHandler);
try (Aeron aeronTwo = Aeron.connect(clientCtxTwo)) {
aeronTwo.addSubscription("aeron:ipc", 1001);
verify(availableHandler, timeout(5000)).onAvailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
}
verify(unavailableHandler, timeout(5000)).onUnavailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
}
} finally {
driverCtx.deleteDirectory();
}
}
use of io.aeron.test.InterruptAfter 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);
}
Aggregations