use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class ClientErrorHandlerTest method shouldHaveCorrectTermBufferLength.
@Test
@InterruptAfter(10)
@SuppressWarnings("try")
void shouldHaveCorrectTermBufferLength() {
final MediaDriver.Context ctx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true);
final ErrorHandler mockErrorHandlerOne = mock(ErrorHandler.class);
final Aeron.Context clientCtxOne = new Aeron.Context().errorHandler(mockErrorHandlerOne);
final ErrorHandler mockErrorHandlerTwo = mock(ErrorHandler.class);
final Aeron.Context clientCtxTwo = new Aeron.Context().errorHandler(mockErrorHandlerTwo).subscriberErrorHandler(RethrowingErrorHandler.INSTANCE);
try (TestMediaDriver ignore = TestMediaDriver.launch(ctx, testWatcher);
Aeron aeronOne = Aeron.connect(clientCtxOne);
Aeron aeronTwo = Aeron.connect(clientCtxTwo);
Publication publication = aeronOne.addPublication(CHANNEL, STREAM_ID);
Subscription subscriptionOne = aeronOne.addSubscription(CHANNEL, STREAM_ID);
Subscription subscriptionTwo = aeronTwo.addSubscription(CHANNEL, STREAM_ID)) {
awaitConnected(subscriptionOne);
awaitConnected(subscriptionTwo);
assertEquals(clientCtxOne.errorHandler(), clientCtxOne.subscriberErrorHandler());
assertNotEquals(clientCtxTwo.errorHandler(), clientCtxTwo.subscriberErrorHandler());
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[100]);
while (publication.offer(buffer) < 0) {
Tests.yield();
}
final RuntimeException expectedException = new RuntimeException("Expected");
final FragmentHandler handler = (buffer1, offset, length, header) -> {
throw expectedException;
};
while (0 == subscriptionOne.poll(handler, 1)) {
Tests.yield();
}
verify(mockErrorHandlerOne).onError(expectedException);
try {
while (0 == subscriptionTwo.poll(handler, 1)) {
Tests.yield();
}
fail("Expected exception");
} catch (final Exception ex) {
assertEquals(expectedException, ex);
}
verify(mockErrorHandlerTwo, never()).onError(any());
} finally {
ctx.deleteDirectory();
}
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class CounterTest method shouldBeAbleToAddCounter.
@Test
@InterruptAfter(10)
void shouldBeAbleToAddCounter() {
final AvailableCounterHandler availableCounterHandlerClientA = mock(AvailableCounterHandler.class);
clientA.addAvailableCounterHandler(availableCounterHandlerClientA);
final AvailableCounterHandler availableCounterHandlerClientB = mock(AvailableCounterHandler.class);
clientB.addAvailableCounterHandler(availableCounterHandlerClientB);
final Counter counter = clientA.addCounter(COUNTER_TYPE_ID, keyBuffer, 0, keyBuffer.capacity(), labelBuffer, 0, COUNTER_LABEL.length());
assertFalse(counter.isClosed());
assertEquals(counter.registrationId(), clientA.countersReader().getCounterRegistrationId(counter.id()));
assertEquals(clientA.clientId(), clientA.countersReader().getCounterOwnerId(counter.id()));
verify(availableCounterHandlerClientA, timeout(5000L)).onAvailableCounter(any(CountersReader.class), eq(counter.registrationId()), eq(counter.id()));
verify(availableCounterHandlerClientB, timeout(5000L)).onAvailableCounter(any(CountersReader.class), eq(counter.registrationId()), eq(counter.id()));
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class BufferClaimMessageTest method shouldTransferReservedValue.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldTransferReservedValue(final String channel) {
final BufferClaim bufferClaim = new BufferClaim();
try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
Publication publication = aeron.addPublication(channel, STREAM_ID)) {
while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
Tests.yield();
}
final long reservedValue = System.currentTimeMillis();
bufferClaim.reservedValue(reservedValue);
bufferClaim.commit();
final MutableBoolean done = new MutableBoolean();
while (!done.get()) {
final int fragments = subscription.poll((buffer, offset, length, header) -> {
assertEquals(MESSAGE_LENGTH, length);
assertEquals(reservedValue, header.reservedValue());
done.value = true;
}, FRAGMENT_COUNT_LIMIT);
if (0 == fragments) {
Tests.yield();
}
}
}
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class ControlledMessageTest method shouldReceivePublishedMessage.
@Test
@InterruptAfter(10)
void shouldReceivePublishedMessage() {
try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[PAYLOAD_LENGTH * 4]);
for (int i = 0; i < 4; i++) {
srcBuffer.setMemory(i * PAYLOAD_LENGTH, PAYLOAD_LENGTH, (byte) (65 + i));
}
for (int i = 0; i < 4; i++) {
while (publication.offer(srcBuffer, i * PAYLOAD_LENGTH, PAYLOAD_LENGTH) < 0L) {
Tests.yield();
}
}
final FragmentCollector fragmentCollector = new FragmentCollector();
int numFragments = 0;
do {
final int fragments = subscription.controlledPoll(fragmentCollector, FRAGMENT_COUNT_LIMIT);
if (0 == fragments) {
Tests.yield();
}
numFragments += fragments;
} while (numFragments < 4);
final UnsafeBuffer collectedBuffer = fragmentCollector.collectedBuffer();
for (int i = 0; i < srcBuffer.capacity(); i++) {
assertEquals(srcBuffer.getByte(i), collectedBuffer.getByte(i), "same at i=" + i);
}
}
}
use of io.aeron.test.InterruptAfter in project aeron by real-logic.
the class MultiSubscriberTest method shouldReceiveMessageOnSeparateSubscriptions.
@Test
@InterruptAfter(10)
void shouldReceiveMessageOnSeparateSubscriptions() {
final FragmentHandler mockFragmentHandlerOne = mock(FragmentHandler.class);
final FragmentHandler mockFragmentHandlerTwo = mock(FragmentHandler.class);
final FragmentAssembler adapterOne = new FragmentAssembler(mockFragmentHandlerOne);
final FragmentAssembler adapterTwo = new FragmentAssembler(mockFragmentHandlerTwo);
try (Subscription subscriptionOne = aeron.addSubscription(CHANNEL_1, STREAM_ID);
Subscription subscriptionTwo = aeron.addSubscription(CHANNEL_2, STREAM_ID);
Publication publication = aeron.addPublication(CHANNEL_1, STREAM_ID)) {
final byte[] expectedBytes = "Hello, World! here is a small message".getBytes();
final UnsafeBuffer srcBuffer = new UnsafeBuffer(expectedBytes);
assertEquals(0, subscriptionOne.poll(adapterOne, FRAGMENT_COUNT_LIMIT));
assertEquals(0, subscriptionTwo.poll(adapterTwo, FRAGMENT_COUNT_LIMIT));
while (!subscriptionOne.isConnected() || !subscriptionTwo.isConnected()) {
Tests.yield();
}
while (publication.offer(srcBuffer) < 0L) {
Tests.yield();
}
while (subscriptionOne.poll(adapterOne, FRAGMENT_COUNT_LIMIT) == 0) {
Tests.yield();
}
while (subscriptionTwo.poll(adapterTwo, FRAGMENT_COUNT_LIMIT) == 0) {
Tests.yield();
}
verifyData(srcBuffer, mockFragmentHandlerOne);
verifyData(srcBuffer, mockFragmentHandlerTwo);
}
}
Aggregations