Search in sources :

Example 1 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class MultiDestinationCastTest method shouldManuallyRemovePortDuringActiveStream.

@Test(timeout = 10_000)
public void shouldManuallyRemovePortDuringActiveStream() throws Exception {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    final int numMessageForSub2 = 10;
    final CountDownLatch unavailableImage = new CountDownLatch(1);
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    launch();
    publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(SUB1_MDC_MANUAL_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(SUB2_MDC_MANUAL_URI, STREAM_ID, null, (image) -> unavailableImage.countDown());
    publication.addDestination(SUB1_MDC_MANUAL_URI);
    publication.addDestination(SUB2_MDC_MANUAL_URI);
    while (!subscriptionA.isConnected() || !subscriptionB.isConnected()) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        pollForFragment(subscriptionA, fragmentHandlerA, fragmentsRead);
        fragmentsRead.set(0);
        if (i < numMessageForSub2) {
            pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
        } else {
            fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
            Thread.yield();
        }
        if (i == numMessageForSub2 - 1) {
            publication.removeDestination(SUB2_MDC_MANUAL_URI);
        }
    }
    unavailableImage.await();
    verifyFragments(fragmentHandlerA, numMessagesToSend);
    verifyFragments(fragmentHandlerB, numMessageForSub2);
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test) UUID(java.util.UUID) IoUtil(org.agrona.IoUtil) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Header(io.aeron.logbuffer.Header) ThreadingMode(io.aeron.driver.ThreadingMode) After(org.junit.After) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class MultiDestinationCastTest method shouldSendToTwoPortsWithDynamic.

@Test(timeout = 10_000)
public void shouldSendToTwoPortsWithDynamic() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    launch();
    publication = clientA.addPublication(PUB_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(SUB1_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(SUB2_MDC_DYNAMIC_URI, STREAM_ID);
    subscriptionC = clientA.addSubscription(SUB3_MDC_DYNAMIC_URI, STREAM_ID);
    while (subscriptionA.hasNoImages() || subscriptionB.hasNoImages() || subscriptionC.hasNoImages()) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        pollForFragment(subscriptionA, fragmentHandlerA, fragmentsRead);
        fragmentsRead.set(0);
        pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
        fragmentsRead.set(0);
        pollForFragment(subscriptionC, fragmentHandlerC, fragmentsRead);
    }
    verifyFragments(fragmentHandlerA, numMessagesToSend);
    verifyFragments(fragmentHandlerB, numMessagesToSend);
    verifyFragments(fragmentHandlerC, numMessagesToSend);
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.Test)

Example 3 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class MultiDestinationCastTest method shouldSendToTwoPortsWithManualSingleDriver.

@Test(timeout = 10_000)
public void shouldSendToTwoPortsWithManualSingleDriver() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    launch();
    publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(SUB1_MDC_MANUAL_URI, STREAM_ID);
    subscriptionB = clientA.addSubscription(SUB2_MDC_MANUAL_URI, STREAM_ID);
    publication.addDestination(SUB1_MDC_MANUAL_URI);
    publication.addDestination(SUB2_MDC_MANUAL_URI);
    while (!subscriptionA.isConnected() || !subscriptionB.isConnected()) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    for (int i = 0; i < numMessagesToSend; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        pollForFragment(subscriptionA, fragmentHandlerA, fragmentsRead);
        fragmentsRead.set(0);
        pollForFragment(subscriptionB, fragmentHandlerB, fragmentsRead);
    }
    verifyFragments(fragmentHandlerA, numMessagesToSend);
    verifyFragments(fragmentHandlerB, numMessagesToSend);
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.Test)

Example 4 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class MultiDriverTest method shouldJoinExistingIdleStreamWithLockStepSendingReceiving.

@Test(timeout = 10_000)
public void shouldJoinExistingIdleStreamWithLockStepSendingReceiving() throws Exception {
    final int numMessagesToSendPreJoin = 0;
    final int numMessagesToSendPostJoin = NUM_MESSAGES_PER_TERM;
    launch();
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    while (!publication.isConnected() && !subscriptionA.isConnected()) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    final CountDownLatch newImageLatch = new CountDownLatch(1);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID, (image) -> newImageLatch.countDown(), null);
    newImageLatch.await();
    for (int i = 0; i < numMessagesToSendPostJoin; i++) {
        while (publication.offer(buffer, 0, buffer.capacity()) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        fragmentsRead.set(0);
        SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
    }
    assertThat(fragmentCountA.value, is(numMessagesToSendPreJoin + numMessagesToSendPostJoin));
    assertThat(fragmentCountB.value, is(numMessagesToSendPostJoin));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MediaDriver(io.aeron.driver.MediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test) UUID(java.util.UUID) IoUtil(org.agrona.IoUtil) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertThat(org.junit.Assert.assertThat) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadingMode(io.aeron.driver.ThreadingMode) After(org.junit.After) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) MutableInteger(org.agrona.collections.MutableInteger) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with MutableInteger

use of org.agrona.collections.MutableInteger in project aeron by real-logic.

the class PongTest method playPingPongWithRestart.

@Ignore
@Test
public void playPingPongWithRestart() throws Exception {
    buffer.putInt(0, 1);
    while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger fragmentsRead = new MutableInteger();
    SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 1);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    fragmentsRead.set(0);
    SystemTest.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()) {
        SystemTest.checkInterruptedStatus();
        Thread.sleep(100);
    }
    // restart Pong side
    pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
    pingSubscription = pingClient.addSubscription(PING_URI, PING_STREAM_ID);
    fragmentsRead.set(0);
    while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
        SystemTest.checkInterruptedStatus();
        Thread.yield();
    }
    SystemTest.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
        fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 10);
        Thread.yield();
    }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
    fragmentsRead.set(0);
    SystemTest.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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MutableInteger (org.agrona.collections.MutableInteger)77 Header (io.aeron.logbuffer.Header)29 DirectBuffer (org.agrona.DirectBuffer)29 Test (org.junit.Test)28 InterruptAfter (io.aeron.test.InterruptAfter)26 FragmentHandler (io.aeron.logbuffer.FragmentHandler)23 MediaDriver (io.aeron.driver.MediaDriver)22 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)22 Test (org.junit.jupiter.api.Test)21 ThreadingMode (io.aeron.driver.ThreadingMode)19 CloseHelper (org.agrona.CloseHelper)18 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)15 AfterEach (org.junit.jupiter.api.AfterEach)15 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)15 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)14 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)14 Tests (io.aeron.test.Tests)14 TimeUnit (java.util.concurrent.TimeUnit)14 DataPoint (org.junit.experimental.theories.DataPoint)14 Theory (org.junit.experimental.theories.Theory)14