Search in sources :

Example 76 with MutableInteger

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

the class ClusterNodeTest method shouldSendResponseAfterServiceMessage.

@Test
@InterruptAfter(10)
public void shouldSendResponseAfterServiceMessage() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchServiceMessageIngressService();
    aeronCluster = connectToCluster(listener);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 77 with MutableInteger

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

the class StatusUtil method receiveChannelStatus.

/**
 * Return the read-only status indicator for the given receive channel URI.
 *
 * @param countersReader that holds the status indicator.
 * @param channel        for the receive channel.
 * @return read-only status indicator that can be used to query the status of the receive channel or null.
 * @see ChannelEndpointStatus for status values and indications.
 */
public static StatusIndicatorReader receiveChannelStatus(final CountersReader countersReader, final String channel) {
    StatusIndicatorReader statusReader = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
        if (typeId == ReceiveChannelStatus.RECEIVE_CHANNEL_STATUS_TYPE_ID) {
            if (channel.startsWith(keyBuffer.getStringAscii(ChannelEndpointStatus.CHANNEL_OFFSET))) {
                id.value = counterId;
            }
        }
    });
    if (Aeron.NULL_VALUE != id.value) {
        statusReader = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value);
    }
    return statusReader;
}
Also used : StatusIndicatorReader(org.agrona.concurrent.status.StatusIndicatorReader) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBufferStatusIndicator(org.agrona.concurrent.status.UnsafeBufferStatusIndicator)

Example 78 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 79 with MutableInteger

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

the class StopStartSecondSubscriberTest method shouldReceiveMessagesAfterStopStart.

private void shouldReceiveMessagesAfterStopStart(final String channelOne, final int streamOne, final String channelTwo, final int streamTwo) {
    final int numMessages = 1;
    final MutableInteger subscriber2AfterRestartCount = new MutableInteger();
    final AtomicBoolean running = new AtomicBoolean(true);
    final CountDownLatch latch = new CountDownLatch(2);
    final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> subscriber2AfterRestartCount.value++;
    launch(channelOne, streamOne, channelTwo, streamTwo);
    buffer.putInt(0, 1);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try {
        executor.execute(() -> doPublisherWork(publicationOne, running, latch));
        executor.execute(() -> doPublisherWork(publicationTwo, running, latch));
        final MutableInteger fragmentsReadOne = new MutableInteger();
        final MutableInteger fragmentsReadTwo = new MutableInteger();
        final BooleanSupplier fragmentsReadCondition = () -> fragmentsReadOne.get() >= numMessages && fragmentsReadTwo.get() >= numMessages;
        Tests.executeUntil(fragmentsReadCondition, (i) -> {
            fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1);
            fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandlerTwo, 1);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900));
        assertTrue(subOneCount.get() >= numMessages);
        assertTrue(subTwoCount.get() >= numMessages);
        subscriptionTwo.close();
        fragmentsReadOne.set(0);
        fragmentsReadTwo.set(0);
        subscriptionTwo = subscriberTwo.addSubscription(channelTwo, streamTwo);
        Tests.executeUntil(fragmentsReadCondition, (i) -> {
            fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1);
            fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandler, 1);
            Thread.yield();
        }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900));
        running.set(false);
        latch.await();
        assertTrue(subOneCount.get() >= numMessages * 2, "Expecting subscriberOne to receive messages the entire time");
        assertTrue(subTwoCount.get() >= numMessages, "Expecting subscriberTwo to receive messages before being stopped and started");
        assertTrue(subscriber2AfterRestartCount.get() >= numMessages, "Expecting subscriberTwo to receive messages after being stopped and started");
    } catch (final InterruptedException ex) {
        fail("Interrupted", ex);
    } finally {
        running.set(false);
        executor.shutdownNow();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) Tests(io.aeron.test.Tests) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) BitUtil(org.agrona.BitUtil) Executors(java.util.concurrent.Executors) BooleanSupplier(java.util.function.BooleanSupplier) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions(org.junit.jupiter.api.Assertions) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) ExecutorService(java.util.concurrent.ExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) BooleanSupplier(java.util.function.BooleanSupplier)

Example 80 with MutableInteger

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

the class ExtendRecordingTest method consume.

private static void consume(final Subscription subscription, final int startIndex, final int count) {
    final MutableInteger received = new MutableInteger(startIndex);
    final FragmentHandler fragmentHandler = new FragmentAssembler((buffer, offset, length, header) -> {
        final String expected = MESSAGE_PREFIX + received.value;
        final String actual = buffer.getStringWithoutLengthAscii(offset, length);
        assertEquals(expected, actual);
        received.value++;
    });
    while (received.value < (startIndex + count)) {
        if (0 == subscription.poll(fragmentHandler, ArchiveSystemTests.FRAGMENT_LIMIT)) {
            Tests.yield();
        }
    }
    assertEquals(startIndex + count, received.get());
}
Also used : FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger)

Aggregations

MutableInteger (org.agrona.collections.MutableInteger)145 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)72 DirectBuffer (org.agrona.DirectBuffer)58 Test (org.junit.jupiter.api.Test)55 InterruptAfter (io.aeron.test.InterruptAfter)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)40 MethodSource (org.junit.jupiter.params.provider.MethodSource)38 Test (org.junit.Test)33 ByteBuffer (java.nio.ByteBuffer)32 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)29 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 KafkaValueMatchFW (io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaValueMatchFW)28 OctetsFW (io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW)28