Search in sources :

Example 36 with InterruptAfter

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

Example 37 with InterruptAfter

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

Example 38 with InterruptAfter

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();
    }
}
Also used : Random(java.util.Random) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 39 with InterruptAfter

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);
}
Also used : MutableLong(org.agrona.collections.MutableLong) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 40 with InterruptAfter

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);
}
Also used : MutableLong(org.agrona.collections.MutableLong) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

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