use of io.aeron.test.driver.TestMediaDriver 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.driver.TestMediaDriver in project Aeron by real-logic.
the class LifecycleTest method shouldStartAndStopInstantly.
@Test
@InterruptAfter(10)
void shouldStartAndStopInstantly() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).errorHandler(Tests::onError);
try (TestMediaDriver mediaDriver = TestMediaDriver.launch(driverCtx, testWatcher)) {
final Aeron.Context clientCtx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
final Aeron aeron = Aeron.connect(clientCtx);
aeron.close();
} finally {
driverCtx.deleteDirectory();
}
}
use of io.aeron.test.driver.TestMediaDriver 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.driver.TestMediaDriver in project Aeron by real-logic.
the class AsyncResourceTest method shouldDetectUnknownHost.
@Test
@SlowTest
@Timeout(60)
void shouldDetectUnknownHost() {
final ErrorHandler mockClientErrorHandler = mock(ErrorHandler.class);
final Aeron.Context clientCtx = new Aeron.Context().errorHandler(mockClientErrorHandler);
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
try (TestMediaDriver ignore = TestMediaDriver.launch(driverCtx, testWatcher);
Aeron aeron = Aeron.connect(clientCtx)) {
final long registrationId = aeron.asyncAddPublication("aeron:udp?endpoint=wibble:1234", STREAM_ID);
verify(mockClientErrorHandler, timeout(55_000)).onError(any(RegistrationException.class));
assertFalse(aeron.isCommandActive(registrationId));
assertFalse(aeron.hasActiveCommands());
} finally {
driverCtx.deleteDirectory();
}
}
use of io.aeron.test.driver.TestMediaDriver in project Aeron by real-logic.
the class AsyncResourceTest method shouldDetectInvalidUri.
@Test
@Timeout(10)
void shouldDetectInvalidUri() {
final ErrorHandler mockClientErrorHandler = mock(ErrorHandler.class);
final Aeron.Context clientCtx = new Aeron.Context().errorHandler(mockClientErrorHandler);
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
try (TestMediaDriver ignore = TestMediaDriver.launch(driverCtx, testWatcher);
Aeron aeron = Aeron.connect(clientCtx)) {
final long registrationId = aeron.asyncAddPublication("invalid" + AERON_IPC, STREAM_ID);
verify(mockClientErrorHandler, timeout(5000)).onError(any(RegistrationException.class));
assertFalse(aeron.isCommandActive(registrationId));
assertFalse(aeron.hasActiveCommands());
} finally {
driverCtx.deleteDirectory();
}
}
Aggregations