use of io.aeron.driver.ext.LossGenerator in project Aeron by real-logic.
the class PubAndSubTest method shouldReceivePublishedMessageOneForOneWithDataLoss.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(20)
void shouldReceivePublishedMessageOneForOneWithDataLoss(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 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 < numMessagesToSend; i++) {
while (publication.offer(buffer, 0, messageLength) < 0L) {
Tests.yield();
}
pollForFragment();
}
verify(fragmentHandler, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(messageLength), any(Header.class));
verifyLossOccurredForStream(context.aeronDirectoryName(), STREAM_ID);
}
use of io.aeron.driver.ext.LossGenerator in project aeron by real-logic.
the class PubAndSubTest method shouldReceivePublishedMessageOneForOneWithDataLoss.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(20)
void shouldReceivePublishedMessageOneForOneWithDataLoss(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 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 < numMessagesToSend; i++) {
while (publication.offer(buffer, 0, messageLength) < 0L) {
Tests.yield();
}
pollForFragment();
}
verify(fragmentHandler, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(messageLength), any(Header.class));
verifyLossOccurredForStream(context.aeronDirectoryName(), STREAM_ID);
}
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();
}
}
Aggregations