Search in sources :

Example 41 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 42 with TestMediaDriver

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

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