Search in sources :

Example 26 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 27 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)

Example 28 with MutableInteger

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

the class SelectorAndTransportTest method shouldHandleSmFrameFromReceiverToSender.

@Test
@InterruptAfter(10)
public void shouldHandleSmFrameFromReceiverToSender() {
    final MutableInteger controlMessagesReceived = new MutableInteger(0);
    doAnswer((invocation) -> {
        controlMessagesReceived.value++;
        return null;
    }).when(mockPublication).onStatusMessage(any(), any());
    receiveChannelEndpoint = new ReceiveChannelEndpoint(RCV_DST, mockDispatcher, mockReceiveStatusIndicator, context);
    sendChannelEndpoint = new SendChannelEndpoint(SRC_DST, mockSendStatusIndicator, context);
    sendChannelEndpoint.registerForSend(mockPublication);
    receiveChannelEndpoint.openDatagramChannel(mockReceiveStatusIndicator);
    receiveChannelEndpoint.registerForRead(dataTransportPoller);
    sendChannelEndpoint.openDatagramChannel(mockSendStatusIndicator);
    sendChannelEndpoint.registerForRead(controlTransportPoller);
    statusMessage.wrap(buffer);
    statusMessage.streamId(STREAM_ID).sessionId(SESSION_ID).consumptionTermId(TERM_ID).receiverWindowLength(1000).consumptionTermOffset(0).version(HeaderFlyweight.CURRENT_VERSION).flags((short) 0).headerType(HeaderFlyweight.HDR_TYPE_SM).frameLength(StatusMessageFlyweight.HEADER_LENGTH);
    byteBuffer.position(0).limit(statusMessage.frameLength());
    processLoop(dataTransportPoller, 5);
    receiveChannelEndpoint.sendTo(byteBuffer, rcvRemoteAddress);
    while (controlMessagesReceived.get() < 1) {
        processLoop(controlTransportPoller, 1);
    }
    verify(mockStatusMessagesReceivedCounter, times(1)).incrementOrdered();
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 29 with MutableInteger

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

the class SelectorAndTransportTest method shouldSendMultipleDataFramesPerDatagramUnicastFromSourceToReceiver.

@Test
@InterruptAfter(10)
public void shouldSendMultipleDataFramesPerDatagramUnicastFromSourceToReceiver() {
    final MutableInteger dataHeadersReceived = new MutableInteger(0);
    doAnswer((invocation) -> {
        dataHeadersReceived.value++;
        return null;
    }).when(mockDispatcher).onDataPacket(any(ReceiveChannelEndpoint.class), any(DataHeaderFlyweight.class), any(UnsafeBuffer.class), anyInt(), any(InetSocketAddress.class), anyInt());
    receiveChannelEndpoint = new ReceiveChannelEndpoint(RCV_DST, mockDispatcher, mockReceiveStatusIndicator, context);
    sendChannelEndpoint = new SendChannelEndpoint(SRC_DST, mockSendStatusIndicator, context);
    receiveChannelEndpoint.openDatagramChannel(mockReceiveStatusIndicator);
    receiveChannelEndpoint.registerForRead(dataTransportPoller);
    sendChannelEndpoint.openDatagramChannel(mockSendStatusIndicator);
    sendChannelEndpoint.registerForRead(controlTransportPoller);
    encodeDataHeader.wrap(buffer);
    encodeDataHeader.version(HeaderFlyweight.CURRENT_VERSION).flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS).headerType(HeaderFlyweight.HDR_TYPE_DATA).frameLength(FRAME_LENGTH);
    encodeDataHeader.sessionId(SESSION_ID).streamId(STREAM_ID).termId(TERM_ID);
    final int alignedFrameLength = BitUtil.align(FRAME_LENGTH, FrameDescriptor.FRAME_ALIGNMENT);
    encodeDataHeader.wrap(buffer, alignedFrameLength, buffer.capacity() - alignedFrameLength);
    encodeDataHeader.version(HeaderFlyweight.CURRENT_VERSION).flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS).headerType(HeaderFlyweight.HDR_TYPE_DATA).frameLength(24);
    encodeDataHeader.sessionId(SESSION_ID).streamId(STREAM_ID).termId(TERM_ID);
    byteBuffer.position(0).limit(2 * alignedFrameLength);
    processLoop(dataTransportPoller, 5);
    sendChannelEndpoint.send(byteBuffer);
    while (dataHeadersReceived.get() < 1) {
        processLoop(dataTransportPoller, 1);
    }
    assertEquals(1, dataHeadersReceived.get());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MutableInteger(org.agrona.collections.MutableInteger) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 30 with MutableInteger

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

the class ArchiveTool method verify.

static boolean verify(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Checksum checksum, final EpochClock epochClock, final ActionConfirmation<File> truncateOnPageStraddle) {
    try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
        final MutableInteger errorCount = new MutableInteger();
        catalog.forEach(createVerifyEntryProcessor(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle));
        return errorCount.get() == 0;
    }
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Catalog(io.aeron.archive.Catalog)

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