Search in sources :

Example 1 with SlowTest

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

the class PongTest method playPingPongWithRestart.

@SlowTest
@Test
void playPingPongWithRestart() {
    buffer.putInt(0, 1);
    while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        Tests.yield();
    }
    final MutableInteger fragmentsRead = new MutableInteger();
    Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 1);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    fragmentsRead.set(0);
    Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pongSubscription.poll(pongHandler, 1);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    // close Pong side
    pongPublication.close();
    pingSubscription.close();
    // wait for disconnect to ensure we stay in lock step
    while (pingPublication.isConnected()) {
        Tests.sleep(10);
    }
    // restart Pong side
    pingSubscription = pingClient.addSubscription(PING_URI, PING_STREAM_ID);
    pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
    fragmentsRead.set(0);
    while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        Tests.yield();
    }
    Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 10);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    fragmentsRead.set(0);
    Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pongSubscription.poll(pongHandler, 10);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    verify(pongHandler, times(2)).onFragment(any(DirectBuffer.class), eq(DataHeaderFlyweight.HEADER_LENGTH), eq(BitUtil.SIZE_OF_INT), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) SlowTest(io.aeron.test.SlowTest) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test)

Example 2 with SlowTest

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

the class AsyncResourceTest method shouldDetectUnknownHost.

@Test
@SlowTest
@Timeout(60)
void shouldDetectUnknownHost() {
    final ErrorHandler mockClientErrorHandler = mock(ErrorHandler.class);
    final Aeron.Context clientCtx = new Aeron.Context().errorHandler(mockClientErrorHandler);
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    try (TestMediaDriver ignore = TestMediaDriver.launch(driverCtx, testWatcher);
        Aeron aeron = Aeron.connect(clientCtx)) {
        final long registrationId = aeron.asyncAddPublication("aeron:udp?endpoint=wibble:1234", STREAM_ID);
        verify(mockClientErrorHandler, timeout(55_000)).onError(any(RegistrationException.class));
        assertFalse(aeron.isCommandActive(registrationId));
        assertFalse(aeron.hasActiveCommands());
    } finally {
        driverCtx.deleteDirectory();
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) RegistrationException(io.aeron.exceptions.RegistrationException) MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) SlowTest(io.aeron.test.SlowTest) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

SlowTest (io.aeron.test.SlowTest)2 Test (org.junit.jupiter.api.Test)2 MediaDriver (io.aeron.driver.MediaDriver)1 RegistrationException (io.aeron.exceptions.RegistrationException)1 Header (io.aeron.logbuffer.Header)1 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)1 DirectBuffer (org.agrona.DirectBuffer)1 ErrorHandler (org.agrona.ErrorHandler)1 MutableInteger (org.agrona.collections.MutableInteger)1 Timeout (org.junit.jupiter.api.Timeout)1