Search in sources :

Example 11 with TestMediaDriver

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

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

the class TimestampingSystemTest method shouldErrorIfPublicationConfigurationForTimestampsDoesNotMatch.

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

Example 13 with TestMediaDriver

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

the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMergedMds.

@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMergedMds() {
    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.addExclusivePublication("aeron:udp?endpoint=localhost:23424", 1000);
        final String pub2Uri = new ChannelUriStringBuilder("aeron:udp?endpoint=localhost:23425").initialPosition(0L, pub1.initialTermId(), pub1.termBufferLength()).sessionId(pub1.sessionId()).build();
        final Publication pub2 = aeron.addExclusivePublication(pub2Uri, 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");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        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());
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        sendTimestamp.set(SENTINEL_VALUE);
        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 14 with TestMediaDriver

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

the class TimestampingSystemTest method shouldErrorOnMediaReceiveTimestampsInJavaDriver.

@Test
void shouldErrorOnMediaReceiveTimestampsInJavaDriver() {
    assumeTrue(TestMediaDriver.shouldRunJavaMediaDriver());
    systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("ERROR - Media timestamps"));
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        assertThrows(RegistrationException.class, () -> aeron.addSubscription(CHANNEL_WITH_MEDIA_TIMESTAMP, 1000));
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Test(org.junit.jupiter.api.Test)

Example 15 with TestMediaDriver

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

the class TimestampingSystemTest method shouldSupportMediaReceiveTimestampsInCDriver.

@Test
@InterruptAfter(10)
@EnabledOnOs(OS.LINUX)
void shouldSupportMediaReceiveTimestampsInCDriver() {
    assumeTrue(TestMediaDriver.shouldRunCMediaDriver());
    final DirectBuffer 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_MEDIA_TIMESTAMP, 1000);
        while (null == sub.resolvedEndpoint()) {
            Tests.yieldingIdle("Failed to resolve endpoint");
        }
        final String uri = "aeron:udp?endpoint=" + sub.resolvedEndpoint();
        final Publication pub = aeron.addPublication(uri, 1000);
        Tests.awaitConnected(pub);
        while (0 > pub.offer(buffer, 0, buffer.capacity(), (termBuffer, termOffset, frameLength) -> SENTINEL_VALUE)) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> assertNotEquals(SENTINEL_VALUE, header.reservedValue());
        while (1 > sub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) 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) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) 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