Search in sources :

Example 1 with DebugSendChannelEndpoint

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

the class GapFillLossTest method shouldGapFillWhenLossOccurs.

@Test(timeout = 10000)
public 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().threadingMode(ThreadingMode.SHARED).publicationTermBufferLength(TERM_BUFFER_LENGTH);
    final LossReport lossReport = mock(LossReport.class);
    ctx.lossReport(lossReport);
    final LossGenerator dataLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0.20, 0xcafebabeL);
    final LossGenerator noLossGenerator = DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);
    ctx.sendChannelEndpointSupplier((udpChannel, statusIndicator, context) -> new DebugSendChannelEndpoint(udpChannel, statusIndicator, context, noLossGenerator, noLossGenerator));
    ctx.receiveChannelEndpointSupplier((udpChannel, dispatcher, statusIndicator, context) -> new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, context, dataLossGenerator, noLossGenerator));
    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(CHANNEL, STREAM_ID);
        Subscription subscription = aeron.addSubscription(UNRELIABLE_CHANNEL, STREAM_ID)) {
        final IdleStrategy idleStrategy = new YieldingIdleStrategy();
        final Subscriber subscriber = new Subscriber(subscription);
        final Thread subscriberThread = new Thread(subscriber);
        subscriberThread.start();
        long position = 0;
        for (int i = 0; i < NUM_MESSAGES; i++) {
            srcBuffer.putLong(0, i);
            while ((position = publication.offer(srcBuffer)) < 0L) {
                idleStrategy.idle();
            }
        }
        FINAL_POSITION.set(position);
        subscriberThread.join();
        assertThat(subscriber.messageCount, lessThan(NUM_MESSAGES));
        verify(lossReport).createEntry(anyLong(), anyLong(), anyInt(), eq(STREAM_ID), anyString(), anyString());
    } finally {
        ctx.deleteAeronDirectory();
    }
}
Also used : YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) LossGenerator(io.aeron.driver.ext.LossGenerator) YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) LossReport(io.aeron.driver.reports.LossReport) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) DebugReceiveChannelEndpoint(io.aeron.driver.ext.DebugReceiveChannelEndpoint) MediaDriver(io.aeron.driver.MediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Example 2 with DebugSendChannelEndpoint

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

the class PubAndSubTest method shouldReceivePublishedMessageBatchedWithDataLoss.

@Theory
@Test(timeout = 10000)
public void shouldReceivePublishedMessageBatchedWithDataLoss(final String channel) throws Exception {
    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);
    Assume.assumeThat(channel, not(IPC_URI));
    for (int i = 0; i < numBatches; i++) {
        for (int j = 0; j < numMessagesPerBatch; j++) {
            while (publication.offer(buffer, 0, messageLength) < 0L) {
                Thread.yield();
            }
        }
        final AtomicInteger fragmentsRead = new AtomicInteger();
        SystemTestHelper.executeUntil(() -> fragmentsRead.get() >= numMessagesPerBatch, (j) -> {
            fragmentsRead.addAndGet(subscription.poll(fragmentHandler, 10));
            Thread.yield();
        }, 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 3 with DebugSendChannelEndpoint

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

the class PubAndSubTest method shouldReceivePublishedMessageOneForOneWithDataLoss.

@Theory
@Test(timeout = 10000)
public void shouldReceivePublishedMessageOneForOneWithDataLoss(final String channel) throws Exception {
    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);
    Assume.assumeThat(channel, not(IPC_URI));
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, messageLength) < 0L) {
            Thread.yield();
        }
        final int[] fragmentsRead = new int[1];
        SystemTestHelper.executeUntil(() -> fragmentsRead[0] > 0, (j) -> {
            fragmentsRead[0] += subscription.poll(fragmentHandler, 10);
            Thread.yield();
        }, 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) 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

DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)3 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)3 LossGenerator (io.aeron.driver.ext.LossGenerator)3 LossReport (io.aeron.driver.reports.LossReport)3 Test (org.junit.Test)3 Header (io.aeron.logbuffer.Header)2 DirectBuffer (org.agrona.DirectBuffer)2 DataPoint (org.junit.experimental.theories.DataPoint)2 Theory (org.junit.experimental.theories.Theory)2 MediaDriver (io.aeron.driver.MediaDriver)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IdleStrategy (org.agrona.concurrent.IdleStrategy)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 YieldingIdleStrategy (org.agrona.concurrent.YieldingIdleStrategy)1