use of io.aeron.logbuffer.FragmentHandler in project aeron by real-logic.
the class BasicArchiveTest method consume.
private static void consume(final Subscription subscription, final int count, final String prefix) {
final MutableInteger received = new MutableInteger(0);
final FragmentHandler fragmentHandler = new FragmentAssembler((buffer, offset, length, header) -> {
final String expected = prefix + received.value;
final String actual = buffer.getStringWithoutLengthAscii(offset, length);
assertEquals(expected, actual);
received.value++;
});
while (received.value < count) {
if (0 == subscription.poll(fragmentHandler, FRAGMENT_LIMIT)) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
}
assertThat(received.get(), is(count));
}
use of io.aeron.logbuffer.FragmentHandler in project aeron by real-logic.
the class ExtendRecordingTest method consume.
private static void consume(final Subscription subscription, final int startIndex, final int count, final String prefix) {
final MutableInteger received = new MutableInteger(startIndex);
final FragmentHandler fragmentHandler = new FragmentAssembler((buffer, offset, length, header) -> {
final String expected = prefix + received.value;
final String actual = buffer.getStringWithoutLengthAscii(offset, length);
assertEquals(expected, actual);
received.value++;
});
while (received.value < (startIndex + count)) {
if (0 == subscription.poll(fragmentHandler, FRAGMENT_LIMIT)) {
SystemTest.checkInterruptedStatus();
Thread.yield();
}
}
assertThat(received.get(), is(startIndex + count));
}
use of io.aeron.logbuffer.FragmentHandler in project Aeron by real-logic.
the class DriverLoggingAgentTest method testLogMediaDriverEvents.
private void testLogMediaDriverEvents(final String channel, final String enabledEvents, final EnumSet<DriverEventCode> expectedEvents) {
before(enabledEvents, expectedEvents);
final MediaDriver.Context driverCtx = new MediaDriver.Context().errorHandler(Tests::onError).publicationLingerTimeoutNs(0).timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(1));
try (MediaDriver mediaDriver = MediaDriver.launch(driverCtx)) {
try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
Publication publication = aeron.addPublication(channel, STREAM_ID)) {
final UnsafeBuffer offerBuffer = new UnsafeBuffer(new byte[32]);
while (publication.offer(offerBuffer) < 0) {
Tests.yield();
}
final MutableInteger counter = new MutableInteger();
final FragmentHandler handler = (buffer, offset, length, header) -> counter.value++;
while (0 == subscription.poll(handler, 1)) {
Tests.yield();
}
assertEquals(counter.get(), 1);
}
final Supplier<String> errorMessage = () -> "Pending events: " + WAIT_LIST;
while (!WAIT_LIST.isEmpty()) {
Tests.yieldingIdle(errorMessage);
}
}
}
use of io.aeron.logbuffer.FragmentHandler in project Aeron by real-logic.
the class SubscriptionTest method shouldReadData.
@Test
public void shouldReadData() {
subscription.addImage(imageOneMock);
when(imageOneMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
return 1;
});
assertEquals(1, subscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT));
verify(fragmentHandler).onFragment(eq(atomicReadBuffer), eq(HEADER_LENGTH), eq(READ_BUFFER_CAPACITY - HEADER_LENGTH), any(Header.class));
}
use of io.aeron.logbuffer.FragmentHandler in project Aeron by real-logic.
the class SubscriptionTest method shouldReadDataFromMultipleSources.
@Test
public void shouldReadDataFromMultipleSources() {
subscription.addImage(imageOneMock);
subscription.addImage(imageTwoMock);
when(imageOneMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
return 1;
});
when(imageTwoMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
return 1;
});
assertEquals(2, subscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT));
}
Aggregations