Search in sources :

Example 36 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 37 with MutableInteger

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

the class ClusterNodeTest method shouldEchoMessageViaService.

@Test(timeout = 10_000)
public void shouldEchoMessageViaService() {
    container = launchEchoService();
    aeronCluster = connectToCluster();
    final Aeron aeron = aeronCluster.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    final Publication publication = aeronCluster.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
        TestUtil.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger messageCount = new MutableInteger();
    final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {

        public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertThat(correlationId, is(msgCorrelationId));
            assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg));
            messageCount.value += 1;
        }
    }, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
    while (messageCount.get() == 0) {
        if (adapter.poll() <= 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Example 38 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 39 with MutableInteger

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

the class StatusUtil method sendChannelStatus.

/**
 * Return the read-only status indicator for the given send channel URI.
 *
 * @param countersReader that holds the status indicator.
 * @param channel        for the send channel.
 * @return read-only status indicator that can be used to query the status of the send channel or null.
 * @see ChannelEndpointStatus for status values and indications.
 */
public static StatusIndicatorReader sendChannelStatus(final CountersReader countersReader, final String channel) {
    StatusIndicatorReader statusReader = null;
    final MutableInteger id = new MutableInteger(-1);
    countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
        if (typeId == SendChannelStatus.SEND_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 40 with MutableInteger

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

the class ClusterNodeTest method shouldScheduleEventInService.

@Test
@InterruptAfter(10)
public void shouldScheduleEventInService() {
    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) -> {
        final String expected = msg + "-scheduled";
        assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchTimedService();
    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)

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