Search in sources :

Example 16 with TestMediaDriver

use of io.aeron.test.driver.TestMediaDriver in project aeron by real-logic.

the class TimestampingSystemTest method shouldSupportChannelSendTimestampsOnMdc.

@Test
@InterruptAfter(10)
void shouldSupportChannelSendTimestampsOnMdc() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Publication mdcPub = aeron.addPublication("aeron:udp?control-mode=manual|channel-snd-ts-offset=0", 1000);
        final Subscription sub1 = aeron.addSubscription("aeron:udp?endpoint=localhost:23424", 1000);
        final Subscription sub2 = aeron.addSubscription("aeron:udp?endpoint=localhost:23425", 1000);
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!sub1.isConnected() || !sub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > mdcPub.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
        while (1 > sub1.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        while (1 > sub2.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 17 with TestMediaDriver

use of io.aeron.test.driver.TestMediaDriver in project aeron by real-logic.

the class TimestampingSystemTest method shouldErrorIfSubscriptionConfigurationForTimestampsDoesNotMatch.

@Test
void shouldErrorIfSubscriptionConfigurationForTimestampsDoesNotMatch() {
    systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("option conflicts"));
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        aeron.addSubscription("aeron:udp?endpoint=localhost:23436|channel-rcv-ts-offset=reserved", 1000);
        assertThrows(RegistrationException.class, () -> aeron.addSubscription("aeron:udp?endpoint=localhost:23436", 1000));
        assertThrows(RegistrationException.class, () -> aeron.addSubscription("aeron:udp?endpoint=localhost:23436|channel-rcv-ts-offset=8", 1000));
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Test(org.junit.jupiter.api.Test)

Example 18 with TestMediaDriver

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();
    }
}
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)

Example 19 with TestMediaDriver

use of io.aeron.test.driver.TestMediaDriver in project aeron by real-logic.

the class MinFlowControlSystemTest method shouldPreventConnectionUntilGroupMinSizeIsMet.

@SlowTest
@Test
@InterruptAfter(20)
void shouldPreventConnectionUntilGroupMinSizeIsMet() {
    final Integer groupSize = 3;
    final ChannelUriStringBuilder builder = new ChannelUriStringBuilder().media("udp").endpoint("224.20.30.39:24326").networkInterface("localhost");
    final String uriPlain = builder.flowControl((String) null).build();
    final String uriWithMinFlowControl = builder.groupTag((Long) null).minFlowControl(groupSize, null).build();
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    launch();
    final CountersReader countersReader = clientA.countersReader();
    TestMediaDriver driverC = null;
    Aeron clientC = null;
    Publication publication = null;
    Subscription subscription0 = null;
    Subscription subscription1 = null;
    Subscription subscription2 = null;
    try {
        driverC = TestMediaDriver.launch(new MediaDriver.Context().publicationTermBufferLength(TERM_BUFFER_LENGTH).aeronDirectoryName(ROOT_DIR + "C").timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(100)).errorHandler(Tests::onError).threadingMode(ThreadingMode.SHARED), testWatcher);
        clientC = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverC.aeronDirectoryName()));
        subscription0 = clientA.addSubscription(uriPlain, STREAM_ID);
        subscription1 = clientB.addSubscription(uriPlain, STREAM_ID);
        publication = clientA.addPublication(uriWithMinFlowControl, STREAM_ID);
        awaitConnectionAndStatusMessages(countersReader, subscription0, subscription1);
        assertFalse(publication.isConnected());
        subscription2 = clientC.addSubscription(uriPlain, STREAM_ID);
        // Should now have 3 receivers and publication should eventually be connected.
        while (!publication.isConnected()) {
            Tests.sleep(1);
        }
        subscription2.close();
        subscription2 = null;
        // Lost a receiver and publication should eventually be disconnected.
        while (publication.isConnected()) {
            Tests.sleep(1);
        }
        subscription2 = clientC.addSubscription(uriPlain, STREAM_ID);
        while (!publication.isConnected()) {
            Tests.sleep(1);
        }
    } finally {
        CloseHelper.closeAll(publication, subscription0, subscription1, subscription2, clientC, driverC);
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with TestMediaDriver

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();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) ErrorHandler(org.agrona.ErrorHandler) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) Mockito(org.mockito.Mockito) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) FragmentHandler(io.aeron.logbuffer.FragmentHandler) Tests.awaitConnected(io.aeron.test.Tests.awaitConnected) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) ErrorHandler(org.agrona.ErrorHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) FragmentHandler(io.aeron.logbuffer.FragmentHandler) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

TestMediaDriver (io.aeron.test.driver.TestMediaDriver)42 MediaDriver (io.aeron.driver.MediaDriver)32 Test (org.junit.jupiter.api.Test)32 InterruptAfter (io.aeron.test.InterruptAfter)24 Tests (io.aeron.test.Tests)22 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)18 RegistrationException (io.aeron.exceptions.RegistrationException)16 FragmentHandler (io.aeron.logbuffer.FragmentHandler)16 SystemTestWatcher (io.aeron.test.SystemTestWatcher)16 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)16 DirectBuffer (org.agrona.DirectBuffer)14 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)14 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)12 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Objects.requireNonNull (java.util.Objects.requireNonNull)10 MutableDirectBuffer (org.agrona.MutableDirectBuffer)10 MutableLong (org.agrona.collections.MutableLong)10 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)10 Assumptions.assumeTrue (org.junit.jupiter.api.Assumptions.assumeTrue)10