Search in sources :

Example 41 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 42 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 43 with MutableInteger

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

the class SystemTestWatcher method countErrors.

private int countErrors(final List<Path> paths, final Predicate<String> filter, final Function<MappedByteBuffer, AtomicBuffer> toErrorBuffer) {
    final MutableInteger errorCount = new MutableInteger();
    for (final Path path : paths) {
        final File file = path.toFile();
        final MappedByteBuffer mmap = SamplesUtil.mapExistingFileReadOnly(file);
        try {
            final AtomicBuffer buffer = toErrorBuffer.apply(mmap);
            ErrorLogReader.read(buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> {
                if (filter.test(encodedException)) {
                    errorCount.set(errorCount.get() + observationCount);
                }
            });
        } finally {
            IoUtil.unmap(mmap);
        }
    }
    return errorCount.get();
}
Also used : Path(java.nio.file.Path) MappedByteBuffer(java.nio.MappedByteBuffer) MutableInteger(org.agrona.collections.MutableInteger) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) ArchiveMarkFile(io.aeron.archive.ArchiveMarkFile) File(java.io.File) ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile)

Example 44 with MutableInteger

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

the class SystemTestWatcher method countArchiveMarkFileErrors.

private int countArchiveMarkFileErrors(final List<Path> paths, final Predicate<String> filter) {
    final MutableInteger errorCount = new MutableInteger();
    for (final Path path : paths) {
        try (ArchiveMarkFile archive = openArchiveMarkFile(path)) {
            final AtomicBuffer buffer = archive.errorBuffer();
            ErrorLogReader.read(buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> {
                if (filter.test(encodedException)) {
                    errorCount.set(errorCount.get() + observationCount);
                }
            });
        }
    }
    return errorCount.get();
}
Also used : Path(java.nio.file.Path) MutableInteger(org.agrona.collections.MutableInteger) ArchiveMarkFile(io.aeron.archive.ArchiveMarkFile) AtomicBuffer(org.agrona.concurrent.AtomicBuffer)

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

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