Search in sources :

Example 46 with MutableInteger

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

the class CatalogWithJumboRecordingsAndGapsTest method listRecordingsForUri.

@ParameterizedTest
@InterruptAfter(10)
@MethodSource("listRecordingsForUriArguments")
void listRecordingsForUri(final long fromRecordingId, final int recordCount, final String channelFragment, final int streamId, final int expectedRecordCount) {
    final MutableInteger callCount = new MutableInteger();
    final int count = aeronArchive.listRecordingsForUri(fromRecordingId, recordCount, channelFragment, streamId, (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId1, strippedChannel, originalChannel, sourceIdentity) -> callCount.increment());
    assertEquals(expectedRecordCount, count);
    assertEquals(expectedRecordCount, callCount.get());
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 47 with MutableInteger

use of org.agrona.collections.MutableInteger 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 48 with MutableInteger

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

the class MinFlowControlSystemTest method shouldRemoveDeadReceiverWithMinMulticastFlowControlStrategy.

@Test
@InterruptAfter(10)
void shouldRemoveDeadReceiverWithMinMulticastFlowControlStrategy() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    final MutableInteger numMessagesLeftToSend = new MutableInteger(numMessagesToSend);
    final MutableInteger numFragmentsReadFromA = new MutableInteger(0);
    final MutableInteger numFragmentsReadFromB = new MutableInteger(0);
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    driverAContext.multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
    launch();
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    awaitConnected(subscriptionA);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
    awaitConnected(subscriptionB);
    awaitConnected(publication);
    boolean isBClosed = false;
    while (numFragmentsReadFromA.get() < numMessagesToSend) {
        int workDone = 0;
        if (numMessagesLeftToSend.get() > 0) {
            final long position = publication.offer(buffer, 0, buffer.capacity());
            if (position >= 0L) {
                numMessagesLeftToSend.decrement();
                workDone++;
            }
        }
        // A keeps up
        final int readA = subscriptionA.poll(fragmentHandlerA, 10);
        numFragmentsReadFromA.addAndGet(readA);
        workDone += readA;
        // B receives up to 1/8 of the messages, then stops
        if (numFragmentsReadFromB.get() < (numMessagesToSend / 8)) {
            final int readB = subscriptionB.poll(fragmentHandlerB, 10);
            numFragmentsReadFromB.addAndGet(readB);
            workDone += readB;
        } else if (!isBClosed) {
            subscriptionB.close();
            isBClosed = true;
        }
        if (0 == workDone) {
            Tests.yieldingIdle(() -> "numMessagesToSend=" + numMessagesToSend + " numMessagesLeftToSend=" + numMessagesLeftToSend + " numFragmentsReadFromA=" + numFragmentsReadFromA + " numFragmentsReadFromB=" + numFragmentsReadFromB);
        }
    }
    verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with MutableInteger

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

the class MultiDriverTest method shouldJoinExistingIdleStreamWithLockStepSendingReceiving.

@Test
@InterruptAfter(10)
void shouldJoinExistingIdleStreamWithLockStepSendingReceiving() throws InterruptedException {
    final int numMessagesToSendPreJoin = 0;
    final int numMessagesToSendPostJoin = NUM_MESSAGES_PER_TERM;
    launch();
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    while (!publication.isConnected() && !subscriptionA.isConnected()) {
        Tests.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) {
            Tests.yield();
        }
        final MutableInteger fragmentsRead = new MutableInteger();
        Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionA.poll(fragmentHandlerA, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
        fragmentsRead.set(0);
        Tests.executeUntil(() -> fragmentsRead.get() > 0, (j) -> {
            fragmentsRead.value += subscriptionB.poll(fragmentHandlerB, 10);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(500));
    }
    assertEquals(numMessagesToSendPreJoin + numMessagesToSendPostJoin, fragmentCountA.value);
    assertEquals(numMessagesToSendPostJoin, fragmentCountB.value);
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) Tests(io.aeron.test.Tests) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) IoUtil(org.agrona.IoUtil) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) SystemUtil(org.agrona.SystemUtil) AfterEach(org.junit.jupiter.api.AfterEach) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ThreadingMode(io.aeron.driver.ThreadingMode) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MutableInteger(org.agrona.collections.MutableInteger) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 50 with MutableInteger

use of org.agrona.collections.MutableInteger 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)

Aggregations

MutableInteger (org.agrona.collections.MutableInteger)151 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)76 DirectBuffer (org.agrona.DirectBuffer)64 Test (org.junit.jupiter.api.Test)61 InterruptAfter (io.aeron.test.InterruptAfter)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 MethodSource (org.junit.jupiter.params.provider.MethodSource)38 MediaDriver (io.aeron.driver.MediaDriver)34 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)34 Test (org.junit.Test)33 ByteBuffer (java.nio.ByteBuffer)32 CloseHelper (org.agrona.CloseHelper)32 Array32FW (io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW)28 HEADER (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADER)28 HEADERS (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADERS)28 KEY (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY)28 NOT (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.NOT)28 KafkaDeltaType (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaDeltaType)28 KafkaOffsetFW (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaOffsetFW)28 KafkaSkip (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaSkip)28