use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class RegistrationAndOwnerTest method shouldHaveCorrectOwnershipOnEntities.
@ParameterizedTest
@ValueSource(strings = { "aeron:udp?endpoint=localhost:24325", "aeron:ipc" })
void shouldHaveCorrectOwnershipOnEntities(final String channel) {
final MediaDriver.Context ctx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true);
try (TestMediaDriver mediaDriver = TestMediaDriver.launch(ctx, testWatcher);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
Publication publication = aeron.addPublication(channel, STREAM_ID);
Counter userCounter = aeron.addCounter(1002, "Test Counter")) {
awaitConnected(subscription);
awaitConnected(publication);
final CountersReader countersReader = aeron.countersReader();
final int subscriberPositionId = subscription.imageAtIndex(0).subscriberPositionId();
assertEquals(aeron.clientId(), countersReader.getCounterOwnerId(subscriberPositionId));
assertEquals(aeron.clientId(), countersReader.getCounterOwnerId(publication.positionLimitId()));
assertEquals(aeron.clientId(), countersReader.getCounterOwnerId(userCounter.id()));
assertEquals(subscription.registrationId(), countersReader.getCounterRegistrationId(subscriberPositionId));
assertEquals(publication.registrationId(), countersReader.getCounterRegistrationId(publication.positionLimitId()));
assertEquals(userCounter.registrationId(), countersReader.getCounterRegistrationId(userCounter.id()));
} finally {
ctx.deleteDirectory();
}
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class GapFillLossTest method shouldGapFillWhenLossOccurs.
@Test
@InterruptAfter(10)
void shouldGapFillWhenLossOccurs() throws Exception {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(MSG_LENGTH));
srcBuffer.setMemory(0, MSG_LENGTH, (byte) 7);
final MediaDriver.Context ctx = new MediaDriver.Context().errorHandler(Tests::onError).threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH);
final LossGenerator noLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
ctx.sendChannelEndpointSupplier((udpChannel, statusIndicator, context) -> new DebugSendChannelEndpoint(udpChannel, statusIndicator, context, noLossGenerator, noLossGenerator));
TestMediaDriver.enableLossGenerationOnReceive(ctx, 0.20, 0xcafebabeL, true, false);
try (TestMediaDriver mediaDriver = TestMediaDriver.launch(ctx, watcher);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(UNRELIABLE_CHANNEL, STREAM_ID);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
final Subscriber subscriber = new Subscriber(subscription);
final Thread subscriberThread = new Thread(subscriber);
subscriberThread.setDaemon(true);
subscriberThread.start();
long position = 0;
for (int i = 0; i < NUM_MESSAGES; i++) {
srcBuffer.putLong(0, i);
while ((position = publication.offer(srcBuffer)) < 0L) {
Tests.yield();
}
}
FINAL_POSITION.set(position);
subscriberThread.join();
verifyLossOccurredForStream(ctx.aeronDirectoryName(), STREAM_ID);
assertThat(subscriber.messageCount, lessThan(NUM_MESSAGES));
} finally {
ctx.deleteDirectory();
}
}
use of io.aeron.driver.MediaDriver 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();
}
}
Aggregations