Search in sources :

Example 31 with InterruptAfter

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());
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with InterruptAfter

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));
    }
}
Also used : Publication(io.aeron.Publication) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 33 with InterruptAfter

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;
        });
    }
}
Also used : Publication(io.aeron.Publication) File(java.io.File) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 34 with InterruptAfter

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();
    }
}
Also used : YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 35 with InterruptAfter

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LossGenerator(io.aeron.driver.ext.LossGenerator) Header(io.aeron.logbuffer.Header) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) DebugSendChannelEndpoint(io.aeron.driver.ext.DebugSendChannelEndpoint) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

InterruptAfter (io.aeron.test.InterruptAfter)304 Test (org.junit.jupiter.api.Test)240 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)90 MediaDriver (io.aeron.driver.MediaDriver)74 TestNode (io.aeron.test.cluster.TestNode)72 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)68 Tests (io.aeron.test.Tests)66 CountersReader (org.agrona.concurrent.status.CountersReader)64 MethodSource (org.junit.jupiter.params.provider.MethodSource)62 SlowTest (io.aeron.test.SlowTest)60 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)58 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)58 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)54 TestCluster (io.aeron.test.cluster.TestCluster)52 ThreadingMode (io.aeron.driver.ThreadingMode)50 MutableInteger (org.agrona.collections.MutableInteger)50 DirectBuffer (org.agrona.DirectBuffer)48 SystemTestWatcher (io.aeron.test.SystemTestWatcher)46 MutableLong (org.agrona.collections.MutableLong)46 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)46