use of io.aeron.driver.ext.DebugReceiveChannelEndpoint 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());
}
use of io.aeron.driver.ext.DebugReceiveChannelEndpoint 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);
}
use of io.aeron.driver.ext.DebugReceiveChannelEndpoint 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());
}
Aggregations