Search in sources :

Example 1 with LossGenerator

use of io.aeron.driver.ext.LossGenerator in project aeron by real-logic.

the class PubAndSubTest method shouldReceivePublishedMessageBatchedWithDataLoss.

@Theory
@Test(timeout = 10_000)
public void shouldReceivePublishedMessageBatchedWithDataLoss(final String channel) {
    if (IPC_URI.equals(channel)) {
        return;
    }
    final int termBufferLength = 64 * 1024;
    final int numMessagesInTermBuffer = 64;
    final int messageLength = (termBufferLength / numMessagesInTermBuffer) - HEADER_LENGTH;
    final int numMessagesToSend = 2 * numMessagesInTermBuffer;
    final int numBatches = 4;
    final int numMessagesPerBatch = numMessagesToSend / numBatches;
    final LossReport lossReport = mock(LossReport.class);
    context.lossReport(lossReport);
    final LossGenerator dataLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0.10, 0xcafebabeL);
    final LossGenerator noLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    context.publicationTermBufferLength(termBufferLength);
    context.sendChannelEndpointSupplier((udpChannel, statusIndicator, context) -> new DebugSendChannelEndpoint(udpChannel, statusIndicator, context, noLossGenerator, noLossGenerator));
    context.receiveChannelEndpointSupplier((udpChannel, dispatcher, statusIndicator, context) -> new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, context, dataLossGenerator, noLossGenerator));
    launch(channel);
    for (int i = 0; i < numBatches; i++) {
        for (int j = 0; j < numMessagesPerBatch; j++) {
            while (publication.offer(buffer, 0, messageLength) < 0L) {
                SystemTest.checkInterruptedStatus();
                Thread.yield();
            }
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        SystemTest.executeUntil(() -> fragmentsRead.value >= numMessagesPerBatch, (j) -> {
            final int fragments = subscription.poll(fragmentHandler, 10);
            if (0 == fragments) {
                Thread.yield();
            }
            fragmentsRead.value += fragments;
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(900));
    }
    verify(fragmentHandler, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(messageLength), any(Header.class));
    verify(lossReport).createEntry(anyLong(), anyLong(), anyInt(), eq(STREAM_ID), anyString(), anyString());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) LossGenerator(io.aeron.driver.ext.LossGenerator) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) LossReport(io.aeron.driver.reports.LossReport) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DataPoint(org.junit.experimental.theories.DataPoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 2 with LossGenerator

use of io.aeron.driver.ext.LossGenerator 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 3 with LossGenerator

use of io.aeron.driver.ext.LossGenerator in project Aeron by real-logic.

the class PubAndSubTest method shouldReceivePublishedMessageBatchedWithDataLoss.

@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldReceivePublishedMessageBatchedWithDataLoss(final String channel) throws IOException {
    assumeFalse(IPC_URI.equals(channel));
    final int termBufferLength = 64 * 1024;
    final int numMessagesInTermBuffer = 64;
    final int messageLength = (termBufferLength / numMessagesInTermBuffer) - HEADER_LENGTH;
    final int numMessagesToSend = 2 * numMessagesInTermBuffer;
    final int numBatches = 4;
    final int numMessagesPerBatch = numMessagesToSend / numBatches;
    final LossGenerator noLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    context.publicationTermBufferLength(termBufferLength);
    context.sendChannelEndpointSupplier((udpChannel, statusIndicator, context) -> new DebugSendChannelEndpoint(udpChannel, statusIndicator, context, noLossGenerator, noLossGenerator));
    TestMediaDriver.enableLossGenerationOnReceive(context, 0.1, 0xcafebabeL, true, false);
    launch(channel);
    for (int i = 0; i < numBatches; i++) {
        for (int j = 0; j < numMessagesPerBatch; j++) {
            while (publication.offer(buffer, 0, messageLength) < 0L) {
                Tests.yield();
            }
        }
        pollForBatch(numMessagesPerBatch);
    }
    verify(fragmentHandler, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(messageLength), any(Header.class));
    verifyLossOccurredForStream(context.aeronDirectoryName(), STREAM_ID);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LossGenerator(io.aeron.driver.ext.LossGenerator) Header(io.aeron.logbuffer.Header) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with LossGenerator

use of io.aeron.driver.ext.LossGenerator in project Aeron by real-logic.

the class JavaTestMediaDriver method enableLossGenerationOnReceive.

public static void enableLossGenerationOnReceive(final MediaDriver.Context context, final double rate, final long seed, final boolean loseDataMessages, final boolean loseControlMessages) {
    final LossGenerator dataLossGenerator = loseDataMessages ? DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) : DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    final LossGenerator controlLossGenerator = loseControlMessages ? DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) : DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    final ReceiveChannelEndpointSupplier endpointSupplier = (udpChannel, dispatcher, statusIndicator, ctx) -> {
        return new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, ctx, dataLossGenerator, controlLossGenerator);
    };
    context.receiveChannelEndpointSupplier(endpointSupplier);
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) ReceiveChannelEndpointSupplier(io.aeron.driver.ReceiveChannelEndpointSupplier) LossGenerator(io.aeron.driver.ext.LossGenerator) DebugChannelEndpointConfiguration(io.aeron.driver.ext.DebugChannelEndpointConfiguration) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) CountersManager(org.agrona.concurrent.status.CountersManager) AgentInvoker(org.agrona.concurrent.AgentInvoker) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) LossGenerator(io.aeron.driver.ext.LossGenerator) ReceiveChannelEndpointSupplier(io.aeron.driver.ReceiveChannelEndpointSupplier)

Example 5 with LossGenerator

use of io.aeron.driver.ext.LossGenerator in project aeron by real-logic.

the class PubAndSubTest method shouldReceivePublishedMessageOneForOneWithDataLoss.

@Theory
@Test(timeout = 10_000)
public void shouldReceivePublishedMessageOneForOneWithDataLoss(final String channel) {
    if (IPC_URI.equals(channel)) {
        return;
    }
    final int termBufferLength = 64 * 1024;
    final int numMessagesInTermBuffer = 64;
    final int messageLength = (termBufferLength / numMessagesInTermBuffer) - HEADER_LENGTH;
    final int numMessagesToSend = 2 * numMessagesInTermBuffer;
    final LossReport lossReport = mock(LossReport.class);
    context.lossReport(lossReport);
    final LossGenerator dataLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0.10, 0xcafebabeL);
    final LossGenerator noLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    context.publicationTermBufferLength(termBufferLength);
    context.sendChannelEndpointSupplier((udpChannel, statusIndicator, context) -> new DebugSendChannelEndpoint(udpChannel, statusIndicator, context, noLossGenerator, noLossGenerator));
    context.receiveChannelEndpointSupplier((udpChannel, dispatcher, statusIndicator, context) -> new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, context, dataLossGenerator, noLossGenerator));
    launch(channel);
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, messageLength) < 0L) {
            Thread.yield();
        }
        final MutableInteger mutableInteger = new MutableInteger();
        SystemTest.executeUntil(() -> mutableInteger.value > 0, (j) -> {
            final int fragments = subscription.poll(fragmentHandler, 10);
            if (0 == fragments) {
                Thread.yield();
            }
            mutableInteger.value += fragments;
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(900));
    }
    verify(fragmentHandler, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(messageLength), any(Header.class));
    verify(lossReport).createEntry(anyLong(), anyLong(), anyInt(), eq(STREAM_ID), anyString(), anyString());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) LossGenerator(io.aeron.driver.ext.LossGenerator) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) LossReport(io.aeron.driver.reports.LossReport) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DataPoint(org.junit.experimental.theories.DataPoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Aggregations

LossGenerator (io.aeron.driver.ext.LossGenerator)6 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)5 Header (io.aeron.logbuffer.Header)4 DirectBuffer (org.agrona.DirectBuffer)4 DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)3 InterruptAfter (io.aeron.test.InterruptAfter)3 MediaDriver (io.aeron.driver.MediaDriver)2 LossReport (io.aeron.driver.reports.LossReport)2 MutableInteger (org.agrona.collections.MutableInteger)2 Test (org.junit.Test)2 DataPoint (org.junit.experimental.theories.DataPoint)2 Theory (org.junit.experimental.theories.Theory)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ReceiveChannelEndpointSupplier (io.aeron.driver.ReceiveChannelEndpointSupplier)1 DebugChannelEndpointConfiguration (io.aeron.driver.ext.DebugChannelEndpointConfiguration)1 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)1 AgentInvoker (org.agrona.concurrent.AgentInvoker)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 CountersManager (org.agrona.concurrent.status.CountersManager)1