use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class PubAndSubTest method shouldContinueAfterBufferRolloverWithPadding.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldContinueAfterBufferRolloverWithPadding(final String channel) {
/*
* 65536 bytes in the buffer
* 63 * 1032 = 65016
* 65536 - 65016 = 520 bytes padding at the end
* so, sending 64 messages causes last to overflow
*/
final int termBufferLength = 64 * 1024;
final int messageLength = 1032 - HEADER_LENGTH;
final int numMessagesToSend = 64;
context.publicationTermBufferLength(termBufferLength);
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));
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class PubAndSubTest method shouldContinueAfterBufferRolloverWithPaddingBatched.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldContinueAfterBufferRolloverWithPaddingBatched(final String channel) {
/*
* 65536 bytes in the buffer
* 63 * 1032 = 65016
* 65536 - 65016 = 520 bytes padding at the end
* so, sending 64 messages causes last to overflow
*/
final int termBufferLength = 64 * 1024;
final int messageLength = 1032 - HEADER_LENGTH;
final int numMessagesToSend = 64;
final int numBatchesPerTerm = 4;
final int numMessagesPerBatch = numMessagesToSend / numBatchesPerTerm;
context.publicationTermBufferLength(termBufferLength);
launch(channel);
for (int i = 0; i < numBatchesPerTerm; 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));
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class PublishFromArbitraryPositionTest method shouldPublishFromArbitraryJoinPosition.
@Test
@InterruptAfter(10)
void shouldPublishFromArbitraryJoinPosition() throws InterruptedException {
final Random rnd = new Random();
rnd.setSeed(seed);
// 64k to 64M
final int termLength = 1 << (16 + rnd.nextInt(10));
// 1024 to 8096
final int mtu = 1 << (10 + rnd.nextInt(3));
final int initialTermId = rnd.nextInt(1234);
final int termOffset = BitUtil.align(rnd.nextInt(termLength), FrameDescriptor.FRAME_ALIGNMENT);
final int termId = initialTermId + rnd.nextInt(1000);
final String channelUri = new ChannelUriStringBuilder().endpoint("localhost:24325").termLength(termLength).initialTermId(initialTermId).termId(termId).termOffset(termOffset).mtu(mtu).media("udp").build();
final int expectedNumberOfFragments = 10 + rnd.nextInt(10000);
try (Subscription subscription = aeron.addSubscription(channelUri, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(channelUri, STREAM_ID)) {
Tests.awaitConnected(publication);
final Thread t = new Thread(() -> {
int totalFragmentsRead = 0;
do {
int fragmentsRead = subscription.poll(mockFragmentHandler, FRAGMENT_COUNT_LIMIT);
while (0 == fragmentsRead) {
Thread.yield();
fragmentsRead = subscription.poll(mockFragmentHandler, FRAGMENT_COUNT_LIMIT);
}
totalFragmentsRead += fragmentsRead;
} while (totalFragmentsRead < expectedNumberOfFragments);
assertEquals(expectedNumberOfFragments, totalFragmentsRead);
});
t.setDaemon(true);
t.setName("image-consumer");
t.start();
for (int i = 0; i < expectedNumberOfFragments; i++) {
publishMessage(srcBuffer, publication, rnd);
}
t.join();
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateMoreThanOnce.
@Test
@InterruptAfter(10)
public void shouldReplicateMoreThanOnce() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader srcCounters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(srcCounters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(srcCounters, counterId);
offer(publication, messageCount, messagePrefix);
awaitPosition(srcCounters, counterId, publication.position());
final MutableLong recordingIdRef = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, recordingIdRef);
long replicationId = dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
final CountersReader dstCounters = dstAeron.countersReader();
final long dstRecordingId = recordingIdRef.get();
int dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId);
awaitPosition(dstCounters, dstCounterId, publication.position());
dstAeronArchive.stopReplication(replicationId);
assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
replicationId = dstAeronArchive.replicate(srcRecordingId, dstRecordingId, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId);
offer(publication, messageCount, messagePrefix);
awaitPosition(dstCounters, dstCounterId, publication.position());
dstAeronArchive.stopReplication(replicationId);
}
srcAeronArchive.stopRecording(subscriptionId);
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateLiveRecordingAndStopAtSpecifiedPosition.
@Test
@InterruptAfter(10)
public void shouldReplicateLiveRecordingAndStopAtSpecifiedPosition() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader srcCounters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(srcCounters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(srcCounters, counterId);
offer(publication, messageCount, messagePrefix);
final long firstPosition = publication.position();
awaitPosition(srcCounters, counterId, firstPosition);
offer(publication, messageCount, messagePrefix);
awaitPosition(srcCounters, counterId, publication.position());
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, firstPosition, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
offer(publication, messageCount, messagePrefix);
final int srcCounterId = RecordingPos.findCounterIdByRecording(srcCounters, srcRecordingId);
awaitPosition(srcCounters, srcCounterId, publication.position());
assertTrue(firstPosition < publication.position());
long dstStopPosition;
while (NULL_POSITION == (dstStopPosition = dstAeronArchive.getStopPosition(dstRecordingId.get()))) {
Tests.yield();
}
assertEquals(firstPosition, dstStopPosition);
}
srcAeronArchive.stopRecording(subscriptionId);
}
Aggregations