use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class CatalogWithJumboRecordingsAndGapsTest method listRecordings.
@ParameterizedTest
@InterruptAfter(10)
@MethodSource("listRecordingsArguments")
void listRecordings(final long fromRecordingId, final int recordCount, final int expectedRecordCount) {
final MutableInteger callCount = new MutableInteger();
final int count = aeronArchive.listRecordings(fromRecordingId, recordCount, (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> callCount.increment());
assertEquals(expectedRecordCount, count);
assertEquals(expectedRecordCount, callCount.get());
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ManageRecordingHistoryTest method shouldDetachThenAttachFullSegments.
@Test
@InterruptAfter(10)
void shouldDetachThenAttachFullSegments() {
final String messagePrefix = "Message-Prefix-";
final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
offerToPosition(publication, messagePrefix, targetPosition);
awaitPosition(counters, counterId, publication.position());
aeronArchive.stopRecording(publication);
final long startPosition = 0L;
final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(startPosition, SEGMENT_LENGTH * 2L, TERM_LENGTH, SEGMENT_LENGTH);
aeronArchive.detachSegments(recordingId, segmentFileBasePosition);
assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));
final long attachSegments = aeronArchive.attachSegments(recordingId);
assertEquals(2L, attachSegments);
assertEquals(startPosition, aeronArchive.getStartPosition(recordingId));
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class ManageRecordingHistoryTest method shouldDeleteDetachedFullSegments.
@Test
@InterruptAfter(10)
void shouldDeleteDetachedFullSegments() {
final String messagePrefix = "Message-Prefix-";
final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID)) {
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
offerToPosition(publication, messagePrefix, targetPosition);
awaitPosition(counters, counterId, publication.position());
aeronArchive.stopRecording(publication);
final String prefix = recordingId + "-";
final File archiveDir = archive.context().archiveDir();
final String[] files = archiveDir.list((dir, name) -> name.startsWith(prefix));
assertThat(files, arrayWithSize(4));
final long startPosition = 0L;
final long segmentFileBasePosition = AeronArchive.segmentFileBasePosition(startPosition, SEGMENT_LENGTH * 2L, TERM_LENGTH, SEGMENT_LENGTH);
aeronArchive.detachSegments(recordingId, segmentFileBasePosition);
assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));
final long deletedSegments = aeronArchive.deleteDetachedSegments(recordingId);
assertEquals(2L, deletedSegments);
assertEquals(segmentFileBasePosition, aeronArchive.getStartPosition(recordingId));
Tests.await(() -> {
final String[] updatedFiles = archiveDir.list((dir, name) -> name.startsWith(prefix));
if (null != updatedFiles && 2 == updatedFiles.length) {
assertThat(updatedFiles, arrayContainingInAnyOrder(Archive.segmentFileName(recordingId, segmentFileBasePosition), Archive.segmentFileName(recordingId, segmentFileBasePosition + SEGMENT_LENGTH)));
return true;
}
return false;
});
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class MemoryOrderingTest method shouldReceiveMessagesInOrderWithFirstLongWordIntactFromExclusivePublication.
@Test
@InterruptAfter(10)
void shouldReceiveMessagesInOrderWithFirstLongWordIntactFromExclusivePublication() throws InterruptedException {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
srcBuffer.setMemory(0, MESSAGE_LENGTH, (byte) 7);
try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
final Thread subscriberThread = new Thread(new Subscriber(subscription));
subscriberThread.setDaemon(true);
subscriberThread.start();
for (int i = 0; i < NUM_MESSAGES; i++) {
if (null != failedMessage) {
fail(failedMessage);
}
srcBuffer.putLong(0, i);
while (publication.offer(srcBuffer) < 0L) {
if (null != failedMessage) {
fail(failedMessage);
}
idleStrategy.idle();
Tests.checkInterruptStatus();
}
if (i % BURST_LENGTH == 0) {
final long timeoutNs = System.nanoTime() + INTER_BURST_DURATION_NS;
long nowNs;
do {
nowNs = System.nanoTime();
} while ((timeoutNs - nowNs) > 0);
}
}
subscriberThread.join();
}
}
use of io.aeron.test.InterruptAfter in project Aeron by real-logic.
the class PubAndSubTest method shouldReceivePublishedMessageBatchedWithDataLoss.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldReceivePublishedMessageBatchedWithDataLoss(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 int numBatches = 4;
final int numMessagesPerBatch = numMessagesToSend / numBatches;
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 < numBatches; 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));
verifyLossOccurredForStream(context.aeronDirectoryName(), STREAM_ID);
}
Aggregations