Search in sources :

Example 76 with MediaDriver

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();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) CountersReader(org.agrona.concurrent.status.CountersReader) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 77 with MediaDriver

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();
    }
}
Also used : LossGenerator(io.aeron.driver.ext.LossGenerator) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 78 with MediaDriver

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();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Tests(io.aeron.test.Tests) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)78 Aeron (io.aeron.Aeron)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 Test (org.junit.jupiter.api.Test)20 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)17 InterruptAfter (io.aeron.test.InterruptAfter)16 Subscription (io.aeron.Subscription)14 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)14 IdleStrategy (org.agrona.concurrent.IdleStrategy)14 ContinueBarrier (org.agrona.console.ContinueBarrier)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Publication (io.aeron.Publication)10 Archive (io.aeron.archive.Archive)10 FragmentHandler (io.aeron.logbuffer.FragmentHandler)10 Tests (io.aeron.test.Tests)10 CommonContext (io.aeron.CommonContext)8 ExecutorService (java.util.concurrent.ExecutorService)8 DirectBuffer (org.agrona.DirectBuffer)7 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)7 AeronCluster (io.aeron.cluster.client.AeronCluster)6