Search in sources :

Example 16 with InterruptAfter

use of io.aeron.test.InterruptAfter in project Aeron by real-logic.

the class UntetheredSubscriptionTest method shouldBecomeUnavailableWhenNotKeepingUp.

@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
public void shouldBecomeUnavailableWhenNotKeepingUp(final String channel) {
    final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> {
    };
    final AtomicBoolean unavailableCalled = new AtomicBoolean();
    final UnavailableImageHandler handler = (image) -> unavailableCalled.set(true);
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
    final String untetheredChannel = channel + "|tether=false";
    final String publicationChannel = channel.startsWith("aeron-spy") ? channel.substring(10) : channel;
    boolean pollingUntethered = true;
    try (Subscription tetheredSub = aeron.addSubscription(channel, STREAM_ID);
        Subscription untetheredSub = aeron.addSubscription(untetheredChannel, STREAM_ID, null, handler);
        Publication publication = aeron.addPublication(publicationChannel, STREAM_ID)) {
        while (!tetheredSub.isConnected() || !untetheredSub.isConnected()) {
            Tests.yield();
            aeron.conductorAgentInvoker().invoke();
        }
        while (true) {
            if (publication.offer(srcBuffer) < 0) {
                Tests.yield();
                aeron.conductorAgentInvoker().invoke();
            }
            if (pollingUntethered && untetheredSub.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT) > 0) {
                pollingUntethered = false;
            }
            tetheredSub.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT);
            if (unavailableCalled.get()) {
                assertTrue(tetheredSub.isConnected());
                assertFalse(untetheredSub.isConnected());
                while (publication.offer(srcBuffer) < 0) {
                    Tests.yield();
                    aeron.conductorAgentInvoker().invoke();
                }
                return;
            }
        }
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteBuffer(java.nio.ByteBuffer) TimeUnit(java.util.concurrent.TimeUnit) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ThreadingMode(io.aeron.driver.ThreadingMode) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) CloseHelper(org.agrona.CloseHelper) MethodSource(org.junit.jupiter.params.provider.MethodSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FragmentHandler(io.aeron.logbuffer.FragmentHandler) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with InterruptAfter

use of io.aeron.test.InterruptAfter in project Aeron by real-logic.

the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.

@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
    final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
    buffer.setMemory(0, buffer.capacity(), (byte) 'z');
    AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
    final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
    final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    final long position1 = recordedPublication1.position();
    final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to record data");
    }
    recordedPublication1.close();
    aeronArchive.stopRecording(subscriptionId);
    while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to stop recording");
    }
    aeronArchive.close();
    archive.close();
    archive.context().deleteDirectory();
    archive = Archive.launch(archiveContext.clone());
    aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
    aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
Also used : RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) ExclusivePublication(io.aeron.ExclusivePublication) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AeronArchive(io.aeron.archive.client.AeronArchive) InterruptAfter(io.aeron.test.InterruptAfter) Test(org.junit.jupiter.api.Test)

Example 18 with InterruptAfter

use of io.aeron.test.InterruptAfter in project Aeron by real-logic.

the class ArchiveTest method recordAndReplayConcurrentPublication.

@ParameterizedTest
@MethodSource("threadingModes")
@InterruptAfter(10)
public void recordAndReplayConcurrentPublication(final ThreadingMode threadingMode, final ArchiveThreadingMode archiveThreadingMode) {
    before(threadingMode, archiveThreadingMode);
    final Publication controlPublication = client.addPublication(archive.context().localControlChannel(), archive.context().localControlStreamId());
    final ArchiveProxy archiveProxy = new ArchiveProxy(controlPublication);
    final Subscription recordingEvents = client.addSubscription(archive.context().recordingEventsChannel(), archive.context().recordingEventsStreamId());
    prePublicationActionsAndVerifications(archiveProxy, controlPublication, recordingEvents);
    final Publication recordedPublication = client.addExclusivePublication(publishUri, PUBLISH_STREAM_ID);
    final int termBufferLength = recordedPublication.termBufferLength();
    final long startPosition = recordedPublication.position();
    preSendChecks(archiveProxy, recordingEvents, recordedPublication.sessionId(), termBufferLength, startPosition);
    prepAndSendMessages(recordingEvents, recordedPublication);
    postPublicationValidations(archiveProxy, recordingEvents, termBufferLength, recordedPublication.initialTermId(), recordedPublication.maxPayloadLength());
}
Also used : ArchiveProxy(io.aeron.archive.client.ArchiveProxy) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with InterruptAfter

use of io.aeron.test.InterruptAfter in project Aeron by real-logic.

the class ArchiveTest method recordAndReplayExclusivePublication.

@ParameterizedTest
@MethodSource("threadingModes")
@InterruptAfter(10)
public void recordAndReplayExclusivePublication(final ThreadingMode threadingMode, final ArchiveThreadingMode archiveThreadingMode) {
    before(threadingMode, archiveThreadingMode);
    final String controlChannel = archive.context().localControlChannel();
    final int controlStreamId = archive.context().localControlStreamId();
    final String recordingChannel = archive.context().recordingEventsChannel();
    final int recordingStreamId = archive.context().recordingEventsStreamId();
    final Publication controlPublication = client.addPublication(controlChannel, controlStreamId);
    final Subscription recordingEvents = client.addSubscription(recordingChannel, recordingStreamId);
    final ArchiveProxy archiveProxy = new ArchiveProxy(controlPublication);
    prePublicationActionsAndVerifications(archiveProxy, controlPublication, recordingEvents);
    final ExclusivePublication recordedPublication = client.addExclusivePublication(publishUri, PUBLISH_STREAM_ID);
    final int sessionId = recordedPublication.sessionId();
    final int termBufferLength = recordedPublication.termBufferLength();
    final int initialTermId = recordedPublication.initialTermId();
    final int maxPayloadLength = recordedPublication.maxPayloadLength();
    final long startPosition = recordedPublication.position();
    assertEquals(requestedStartPosition, startPosition);
    assertEquals(requestedInitialTermId, recordedPublication.initialTermId());
    preSendChecks(archiveProxy, recordingEvents, sessionId, termBufferLength, startPosition);
    prepAndSendMessages(recordingEvents, recordedPublication);
    postPublicationValidations(archiveProxy, recordingEvents, termBufferLength, initialTermId, maxPayloadLength);
}
Also used : ArchiveProxy(io.aeron.archive.client.ArchiveProxy) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 20 with InterruptAfter

use of io.aeron.test.InterruptAfter in project Aeron by real-logic.

the class SpecifiedPositionPublicationTest method shouldValidateSpecifiedPositionForConcurrentPublicationsInitiallyUnspecified.

@InterruptAfter(5)
@ParameterizedTest
@CsvSource({ CommonContext.IPC_CHANNEL, "aeron:udp?endpoint=localhost:24325" })
void shouldValidateSpecifiedPositionForConcurrentPublicationsInitiallyUnspecified(final String initialUri) {
    final MediaDriver.Context context = new MediaDriver.Context().dirDeleteOnStart(true).ipcPublicationTermWindowLength(LogBufferDescriptor.TERM_MIN_LENGTH).threadingMode(ThreadingMode.SHARED);
    final int streamId = 1001;
    try (TestMediaDriver mediaDriver = TestMediaDriver.launch(context, testWatcher);
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        Subscription subscription = aeron.addSubscription(initialUri, streamId);
        Publication publication = aeron.addPublication(initialUri, streamId)) {
        Tests.awaitConnected(subscription);
        Tests.awaitConnected(publication);
        final String channel = new ChannelUriStringBuilder(initialUri).initialPosition(publication.position(), publication.initialTermId(), publication.termBufferLength()).build();
        try (Publication publication2 = aeron.addPublication(channel, streamId)) {
            assertEquals(publication.position(), publication2.position());
            assertEquals(publication.initialTermId(), publication2.initialTermId());
        }
    } finally {
        context.deleteDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) InterruptAfter(io.aeron.test.InterruptAfter) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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