Search in sources :

Example 71 with InterruptAfter

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

the class StopStartSecondSubscriberTest method shouldReceivePublishedMessage.

@Test
@InterruptAfter(10)
void shouldReceivePublishedMessage() {
    launch(CHANNEL1, STREAM_ID1, CHANNEL2, STREAM_ID2);
    buffer.putInt(0, 1);
    final int messagesPerPublication = 1;
    while (publicationOne.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        Tests.yield();
    }
    while (publicationTwo.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        Tests.yield();
    }
    final MutableInteger fragmentsRead1 = new MutableInteger();
    final MutableInteger fragmentsRead2 = new MutableInteger();
    Tests.executeUntil(() -> fragmentsRead1.get() >= messagesPerPublication && fragmentsRead2.get() >= messagesPerPublication, (i) -> {
        fragmentsRead1.value += subscriptionOne.poll(fragmentHandlerOne, 10);
        fragmentsRead2.value += subscriptionTwo.poll(fragmentHandlerTwo, 10);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(9900));
    assertEquals(messagesPerPublication, subOneCount.get());
    assertEquals(messagesPerPublication, subTwoCount.get());
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 72 with InterruptAfter

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

the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMergedMds.

@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMergedMds() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription mdsSub = aeron.addSubscription("aeron:udp?control-mode=manual|channel-rcv-ts-offset=0", 1000);
        final Publication pub1 = aeron.addExclusivePublication("aeron:udp?endpoint=localhost:23424", 1000);
        final String pub2Uri = new ChannelUriStringBuilder("aeron:udp?endpoint=localhost:23425").initialPosition(0L, pub1.initialTermId(), pub1.termBufferLength()).sessionId(pub1.sessionId()).build();
        final Publication pub2 = aeron.addExclusivePublication(pub2Uri, 1000);
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!pub1.isConnected() || !pub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
        while (1 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        sendTimestamp.set(SENTINEL_VALUE);
        while (1 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 73 with InterruptAfter

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

the class TimestampingSystemTest method shouldSupportMediaReceiveTimestampsInCDriver.

@Test
@InterruptAfter(10)
@EnabledOnOs(OS.LINUX)
void shouldSupportMediaReceiveTimestampsInCDriver() {
    assumeTrue(TestMediaDriver.shouldRunCMediaDriver());
    final DirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription sub = aeron.addSubscription(CHANNEL_WITH_MEDIA_TIMESTAMP, 1000);
        while (null == sub.resolvedEndpoint()) {
            Tests.yieldingIdle("Failed to resolve endpoint");
        }
        final String uri = "aeron:udp?endpoint=" + sub.resolvedEndpoint();
        final Publication pub = aeron.addPublication(uri, 1000);
        Tests.awaitConnected(pub);
        while (0 > pub.offer(buffer, 0, buffer.capacity(), (termBuffer, termOffset, frameLength) -> SENTINEL_VALUE)) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> assertNotEquals(SENTINEL_VALUE, header.reservedValue());
        while (1 > sub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
    }
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 74 with InterruptAfter

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

the class TimestampingSystemTest method shouldSupportChannelSendTimestampsOnMdc.

@Test
@InterruptAfter(10)
void shouldSupportChannelSendTimestampsOnMdc() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Publication mdcPub = aeron.addPublication("aeron:udp?control-mode=manual|channel-snd-ts-offset=0", 1000);
        final Subscription sub1 = aeron.addSubscription("aeron:udp?endpoint=localhost:23424", 1000);
        final Subscription sub2 = aeron.addSubscription("aeron:udp?endpoint=localhost:23425", 1000);
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!sub1.isConnected() || !sub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > mdcPub.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
        while (1 > sub1.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        while (1 > sub2.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 75 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)

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