Search in sources :

Example 16 with MutableInteger

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

the class ExclusivePublicationTest method shouldOfferTwoBuffersFromIndependentExclusivePublications.

@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldOfferTwoBuffersFromIndependentExclusivePublications(final String channel) {
    try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
        ExclusivePublication publicationOne = aeron.addExclusivePublication(channel, STREAM_ID);
        ExclusivePublication publicationTwo = aeron.addExclusivePublication(channel, STREAM_ID)) {
        final int expectedNumberOfFragments = 778;
        int totalFragmentsRead = 0;
        final MutableInteger messageCount = new MutableInteger();
        final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> {
            assertEquals(MESSAGE_LENGTH + SIZE_OF_INT, length);
            final int publisherId = buffer.getInt(offset);
            if (1 == publisherId) {
                assertEquals(Byte.MIN_VALUE, buffer.getByte(offset + SIZE_OF_INT));
            } else if (2 == publisherId) {
                assertEquals(Byte.MAX_VALUE, buffer.getByte(offset + SIZE_OF_INT));
            } else {
                fail("unknown publisherId=" + publisherId);
            }
            messageCount.value++;
        };
        Tests.awaitConnections(subscription, 2);
        final UnsafeBuffer pubOneHeader = new UnsafeBuffer(new byte[SIZE_OF_INT]);
        pubOneHeader.putInt(0, 1);
        final UnsafeBuffer pubOnePayload = new UnsafeBuffer(new byte[MESSAGE_LENGTH]);
        pubOnePayload.setMemory(0, MESSAGE_LENGTH, Byte.MIN_VALUE);
        final UnsafeBuffer pubTwoHeader = new UnsafeBuffer(new byte[SIZE_OF_INT]);
        pubTwoHeader.putInt(0, 2);
        final UnsafeBuffer pubTwoPayload = new UnsafeBuffer(new byte[MESSAGE_LENGTH]);
        pubTwoPayload.setMemory(0, MESSAGE_LENGTH, Byte.MAX_VALUE);
        for (int i = 0; i < expectedNumberOfFragments; i += 2) {
            while (publicationOne.offer(pubOneHeader, 0, SIZE_OF_INT, pubOnePayload, 0, MESSAGE_LENGTH) < 0L) {
                Tests.yield();
                totalFragmentsRead += pollFragments(subscription, fragmentHandler);
            }
            while (publicationTwo.offer(pubTwoHeader, 0, SIZE_OF_INT, pubTwoPayload, 0, MESSAGE_LENGTH) < 0L) {
                Tests.yield();
                totalFragmentsRead += pollFragments(subscription, fragmentHandler);
            }
            totalFragmentsRead += pollFragments(subscription, fragmentHandler);
        }
        do {
            totalFragmentsRead += pollFragments(subscription, fragmentHandler);
        } while (totalFragmentsRead < expectedNumberOfFragments);
        assertEquals(expectedNumberOfFragments, messageCount.value);
    }
}
Also used : SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) RawBlockHandler(io.aeron.logbuffer.RawBlockHandler) SIZE_OF_INT(org.agrona.BitUtil.SIZE_OF_INT) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) CLOSED(io.aeron.Publication.CLOSED) Arrays.asList(java.util.Arrays.asList) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) ExecutorService(java.util.concurrent.ExecutorService) MethodSource(org.junit.jupiter.params.provider.MethodSource) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) BACK_PRESSURED(io.aeron.Publication.BACK_PRESSURED) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) FragmentHandler(io.aeron.logbuffer.FragmentHandler) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with MutableInteger

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

the class CatalogWithJumboRecordingsAndGapsTest method listRecordings.

@ParameterizedTest
@InterruptAfter(10)
@MethodSource("listRecordingsArguments")
void listRecordings(final long fromRecordingId, final int recordCount, final int expectedRecordCount) {
    final MutableInteger callCount = new MutableInteger();
    final int count = aeronArchive.listRecordings(fromRecordingId, recordCount, (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, 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 18 with MutableInteger

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

the class ArchiveSystemTests method consume.

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

Example 19 with MutableInteger

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

the class ArchiveMigration_2_3Test method migrateRemovesGapsBetweenRecordings.

@Test
@SuppressWarnings("methodLength")
void migrateRemovesGapsBetweenRecordings() throws IOException {
    final Path catalogFile = archiveDir.toPath().resolve(Archive.Configuration.CATALOG_FILE_NAME);
    final List<RecordingDescriptorV2> recordings = asList(new RecordingDescriptorV2(VALID, 42, 21, 0, 123, 456, 0, 1024, 3, 500, 1024, 1408, 8, 55, "strCh", "aeron:udp?endpoint=localhost:9090", "sourceA"), new RecordingDescriptorV2(VALID, 41, 14, 4, 400, 4000, 44, 444, 4, 44, 44444, 4000, 44, 4040, "ch1024", "aeron:udp?endpoint=localhost:44444", generateStringWithSuffix("source", "B", 854)), new RecordingDescriptorV2(INVALID, 333, 333, 56, 100, 200, 999, 100999, 8, 2048, 4096, 9000, -10, 1, "ch", "channel", "sourceC"));
    try (ArchiveMarkFile markFile = createArchiveMarkFileInVersion2(archiveDir, clock);
        Catalog catalog = createCatalogInVersion2(archiveDir, clock, recordings)) {
        assertEquals(RECORDING_FRAME_LENGTH_V2 * 4, size(catalogFile));
        migration.migrate(System.out, markFile, catalog, archiveDir);
        assertEquals(migration.minimumVersion(), markFile.decoder().version());
        assertEquals(1440, size(catalogFile));
        assertTrue(catalog.isClosed());
        verifyCatalogHeader(catalogFile, 57);
    }
    final String migrationTimestampFileName = migrationTimestampFileName(VERSION_2_1_0, migration.minimumVersion());
    assertTrue(exists(archiveDir.toPath().resolve(migrationTimestampFileName)));
    try (Catalog catalog = new Catalog(archiveDir, null, 0, 1024, clock, null, null)) {
        final MutableInteger index = new MutableInteger();
        catalog.forEach((recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
            final RecordingDescriptorV2 recording = recordings.get(index.getAndIncrement());
            assertNotEquals(RECORDING_FRAME_LENGTH_V2, headerDecoder.length());
            assertEquals(recording.valid, headerDecoder.state().value());
            assertEquals(recording.controlSessionId, descriptorDecoder.controlSessionId());
            assertEquals(recording.correlationId, descriptorDecoder.correlationId());
            assertEquals(recording.recordingId, descriptorDecoder.recordingId());
            assertEquals(recording.startTimestamp, descriptorDecoder.startTimestamp());
            assertEquals(recording.stopTimestamp, descriptorDecoder.stopTimestamp());
            assertEquals(recording.startPosition, descriptorDecoder.startPosition());
            assertEquals(recording.stopPosition, descriptorDecoder.stopPosition());
            assertEquals(recording.initialTermId, descriptorDecoder.initialTermId());
            assertEquals(recording.segmentFileLength, descriptorDecoder.segmentFileLength());
            assertEquals(recording.termBufferLength, descriptorDecoder.termBufferLength());
            assertEquals(recording.mtuLength, descriptorDecoder.mtuLength());
            assertEquals(recording.sessionId, descriptorDecoder.sessionId());
            assertEquals(recording.streamId, descriptorDecoder.streamId());
            assertEquals(recording.strippedChannel, descriptorDecoder.strippedChannel());
            assertEquals(recording.originalChannel, descriptorDecoder.originalChannel());
            assertEquals(recording.sourceIdentity, descriptorDecoder.sourceIdentity());
        });
        assertEquals(recordings.size(), index.get());
    }
}
Also used : Path(java.nio.file.Path) MutableInteger(org.agrona.collections.MutableInteger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 20 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)

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