Search in sources :

Example 36 with TestMediaDriver

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

the class DriverNameResolverTest method after.

@AfterEach
public void after() {
    CloseHelper.closeAll(clients.values());
    CloseHelper.closeAll(drivers.values());
    for (final TestMediaDriver driver : drivers.values()) {
        driver.context().deleteDirectory();
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) AfterEach(org.junit.jupiter.api.AfterEach)

Example 37 with TestMediaDriver

use of io.aeron.test.driver.TestMediaDriver 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 38 with TestMediaDriver

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

the class TaggedFlowControlSystemTest method shouldPreventConnectionUntilRequiredGroupSizeMatchTagIsMet.

@SuppressWarnings("methodlength")
@SlowTest
@Test
@InterruptAfter(20)
void shouldPreventConnectionUntilRequiredGroupSizeMatchTagIsMet() {
    final Long groupTag = 2701L;
    final Integer groupSize = 3;
    final ChannelUriStringBuilder builder = new ChannelUriStringBuilder().media("udp").endpoint("224.20.30.39:24326").networkInterface("localhost");
    final String uriWithGroupTag = builder.groupTag(groupTag).flowControl((String) null).build();
    final String uriPlain = builder.groupTag((Long) null).flowControl((String) null).build();
    final String uriWithTaggedFlowControl = builder.groupTag((Long) null).taggedFlowControl(groupTag, groupSize, null).build();
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    launch();
    TestMediaDriver driverC = null;
    Aeron clientC = null;
    TestMediaDriver driverD = null;
    Aeron clientD = null;
    Publication publication = null;
    Subscription subscription0 = null;
    Subscription subscription1 = null;
    Subscription subscription2 = null;
    Subscription subscription3 = null;
    Subscription subscription4 = null;
    Subscription subscription5 = 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()));
        driverD = TestMediaDriver.launch(new MediaDriver.Context().publicationTermBufferLength(TERM_BUFFER_LENGTH).aeronDirectoryName(ROOT_DIR + "D").timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(100)).errorHandler(Tests::onError).threadingMode(ThreadingMode.SHARED), testWatcher);
        clientD = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverD.aeronDirectoryName()));
        publication = clientA.addPublication(uriWithTaggedFlowControl, STREAM_ID);
        subscription0 = clientA.addSubscription(uriPlain, STREAM_ID);
        subscription1 = clientA.addSubscription(uriPlain, STREAM_ID);
        subscription2 = clientA.addSubscription(uriPlain, STREAM_ID);
        subscription3 = clientB.addSubscription(uriWithGroupTag, STREAM_ID);
        subscription4 = clientC.addSubscription(uriWithGroupTag, STREAM_ID);
        awaitConnectionAndStatusMessages(clientA.countersReader(), subscription0, subscription1, subscription2, subscription3, subscription4);
        assertFalse(publication.isConnected());
        subscription5 = clientD.addSubscription(uriWithGroupTag, STREAM_ID);
        // Should now have 3 receivers and publication should eventually be connected.
        while (!publication.isConnected()) {
            Tests.sleep(1);
        }
        subscription5.close();
        subscription5 = null;
        // Lost a receiver and publication should eventually be disconnected.
        while (publication.isConnected()) {
            Tests.sleep(1);
        }
        subscription5 = clientD.addSubscription(uriWithGroupTag, STREAM_ID);
        // Aaaaaand reconnect.
        while (!publication.isConnected()) {
            Tests.sleep(1);
        }
    } finally {
        CloseHelper.closeAll(publication, subscription0, subscription1, subscription2, subscription3, subscription4, subscription5, clientC, clientD, driverC, driverD);
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with TestMediaDriver

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

the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMds.

@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMds() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription mdsSub = aeron.addSubscription("aeron:udp?control-mode=manual|channel-rcv-ts-offset=0", 1000);
        final Publication pub1 = aeron.addPublication("aeron:udp?endpoint=localhost:23424", 1000);
        final Publication pub2 = aeron.addPublication("aeron:udp?endpoint=localhost:23425", 1000);
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!pub1.isConnected() || !pub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        while (0 > pub2.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 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        while (1 > mdsSub.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 40 with TestMediaDriver

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

the class TimestampingSystemTest method shouldSupportSendReceiveTimestamps.

@Test
@InterruptAfter(10)
void shouldSupportSendReceiveTimestamps() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription sub = aeron.addSubscription(CHANNEL_WITH_CHANNEL_TIMESTAMPS, 1000);
        while (null == sub.resolvedEndpoint()) {
            Tests.yieldingIdle("Failed to resolve endpoint");
        }
        final String uri = new ChannelUriStringBuilder(CHANNEL_WITH_CHANNEL_TIMESTAMPS).endpoint(requireNonNull(sub.resolvedEndpoint())).build();
        final Publication pub = aeron.addPublication(uri, 1000);
        Tests.awaitConnected(pub);
        buffer.putLong(0, SENTINEL_VALUE);
        buffer.putLong(8, SENTINEL_VALUE);
        while (0 > pub.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final MutableLong receiveTimestamp = new MutableLong(SENTINEL_VALUE);
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> {
            receiveTimestamp.set(buffer1.getLong(offset));
            sendTimestamp.set(buffer1.getLong(offset + 8));
        };
        while (1 > sub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, receiveTimestamp.longValue());
        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)

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