Search in sources :

Example 1 with LITTLE_ENDIAN

use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.

the class ArchiveTool method createVerifyEntryProcessor.

private static CatalogEntryProcessor createVerifyEntryProcessor(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Catalog catalog, final Checksum checksum, final EpochClock epochClock, final MutableInteger errorCount, final ActionConfirmation<File> truncateOnPageStraddle) {
    final ByteBuffer buffer = BufferUtil.allocateDirectAligned(FILE_IO_MAX_LENGTH_DEFAULT, CACHE_LINE_LENGTH);
    buffer.order(LITTLE_ENDIAN);
    final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight(buffer);
    return (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> verifyRecording(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle, headerFlyweight, recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder);
}
Also used : CACHE_LINE_LENGTH(org.agrona.BitUtil.CACHE_LINE_LENGTH) MigrationUtils.fullVersionString(io.aeron.archive.MigrationUtils.fullVersionString) NATIVE_BYTE_ORDER(org.agrona.BufferUtil.NATIVE_BYTE_ORDER) IntConsumer(java.util.function.IntConsumer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) FILE_IO_MAX_LENGTH_DEFAULT(io.aeron.archive.Archive.Configuration.FILE_IO_MAX_LENGTH_DEFAULT) org.agrona(org.agrona) Collectors.toMap(java.util.stream.Collectors.toMap) Path(java.nio.file.Path) HDR_TYPE_PAD(io.aeron.protocol.HeaderFlyweight.HDR_TYPE_PAD) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) LogBufferDescriptor.positionBitsToShift(io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift) HEADER_LENGTH(io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH) VERIFY_ALL_SEGMENT_FILES(io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES) StandardOpenOption(java.nio.file.StandardOpenOption) Math.min(java.lang.Math.min) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) Stream(java.util.stream.Stream) LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN) EpochClock(org.agrona.concurrent.EpochClock) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) ReplaySession.isInvalidHeader(io.aeron.archive.ReplaySession.isInvalidHeader) java.util(java.util) Checksums.newInstance(io.aeron.archive.checksum.Checksums.newInstance) Catalog(io.aeron.archive.Catalog) HeaderFlyweight(io.aeron.protocol.HeaderFlyweight) Configuration(io.aeron.driver.Configuration) READ_WRITE(java.nio.channels.FileChannel.MapMode.READ_WRITE) io.aeron.archive.codecs(io.aeron.archive.codecs) MutableInteger(org.agrona.collections.MutableInteger) PrintStream(java.io.PrintStream) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) Collections.emptySet(java.util.Collections.emptySet) Files(java.nio.file.Files) SESSION_ID_FIELD_OFFSET(io.aeron.protocol.DataHeaderFlyweight.SESSION_ID_FIELD_OFFSET) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) AeronException(io.aeron.exceptions.AeronException) File(java.io.File) INSTANCE(org.agrona.concurrent.SystemEpochClock.INSTANCE) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) APPLY_CHECKSUM(io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM) CncFileDescriptor(io.aeron.CncFileDescriptor) MarkFileHeaderDecoder(io.aeron.archive.codecs.mark.MarkFileHeaderDecoder) HDR_TYPE_DATA(io.aeron.protocol.HeaderFlyweight.HDR_TYPE_DATA) FileChannel(java.nio.channels.FileChannel) BitUtil.align(org.agrona.BitUtil.align) CATALOG_FILE_NAME(io.aeron.archive.Archive.Configuration.CATALOG_FILE_NAME) MappedByteBuffer(java.nio.MappedByteBuffer) LogBufferDescriptor.computeTermIdFromPosition(io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer)

Example 2 with LITTLE_ENDIAN

use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.

the class ClusterTest method shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot.

@SuppressWarnings("MethodLength")
@Test
@InterruptAfter(30)
public void shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot() {
    final int originalTermLength = 256 * 1024;
    final int originalMtu = 1408;
    final int newTermLength = 2 * 1024 * 1024;
    final int newMtu = 8992;
    final CRC32 crc32 = new CRC32();
    cluster = aCluster().withStaticNodes(3).withLogChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withIngressChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withEgressChannel("aeron:udp?endpoint=localhost:0|term-length=" + originalTermLength + "|mtu=" + originalMtu).withServiceSupplier((i) -> new TestNode.TestService[] { new TestNode.TestService(), new TestNode.ChecksumService() }).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    for (int i = 0; i < 3; i++) {
        assertEquals(2, cluster.node(i).services().length);
    }
    cluster.connectClient();
    final int firstBatch = 9;
    int messageLength = computeMaxMessageLength(originalTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
    int payloadLength = messageLength - SIZE_OF_INT;
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'x');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    int msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    long checksum = 0;
    for (int i = 0; i < firstBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
        checksum = Hashing.hash(checksum ^ msgChecksum);
    }
    cluster.awaitResponseMessageCount(firstBatch);
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(1);
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'y');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    final int secondBatch = 11;
    for (int i = 0; i < secondBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
    }
    cluster.awaitResponseMessageCount(firstBatch + secondBatch);
    cluster.stopAllNodes();
    // seed all recording logs from the latest snapshot
    for (int i = 0; i < 3; i++) {
        ClusterTool.seedRecordingLogFromSnapshot(cluster.node(i).consensusModule().context().clusterDir());
    }
    cluster.logChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.ingressChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.egressChannel("aeron:udp?endpoint=localhost:0|term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    assertEquals(2, cluster.followers().size());
    for (int i = 0; i < 3; i++) {
        assertEquals(2, cluster.node(i).services().length);
    }
    cluster.awaitSnapshotsLoaded();
    cluster.reconnectClient();
    messageLength = computeMaxMessageLength(newTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
    payloadLength = messageLength - SIZE_OF_INT;
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'z');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    final int thirdBatch = 5;
    for (int i = 0; i < thirdBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
        checksum = Hashing.hash(checksum ^ msgChecksum);
    }
    cluster.awaitResponseMessageCount(firstBatch + secondBatch + thirdBatch);
    final int finalMessageCount = firstBatch + thirdBatch;
    final long finalChecksum = checksum;
    final Predicate<TestNode> finalServiceState = node -> {
        final TestNode.TestService[] services = node.services();
        return finalMessageCount == services[0].messageCount() && finalChecksum == ((TestNode.ChecksumService) services[1]).checksum();
    };
    for (int i = 0; i < 3; i++) {
        final TestNode node = cluster.node(i);
        cluster.awaitServiceState(node, finalServiceState);
    }
}
Also used : UNKNOWN_HOST_FILTER(io.aeron.test.SystemTestWatcher.UNKNOWN_HOST_FILTER) ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) ControlledEgressListener(io.aeron.cluster.client.ControlledEgressListener) io.aeron.test(io.aeron.test) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) io.aeron.cluster.codecs(io.aeron.cluster.codecs) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SIZE_OF_INT(org.agrona.BitUtil.SIZE_OF_INT) FrameDescriptor.computeMaxMessageLength(io.aeron.logbuffer.FrameDescriptor.computeMaxMessageLength) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AeronArchive(io.aeron.archive.client.AeronArchive) AuthorisationService(io.aeron.security.AuthorisationService) FOLLOWER(io.aeron.cluster.service.Cluster.Role.FOLLOWER) Publication(io.aeron.Publication) MutableInteger(org.agrona.collections.MutableInteger) EventLogExtension(io.aeron.log.EventLogExtension) MutableBoolean(org.agrona.collections.MutableBoolean) Aeron(io.aeron.Aeron) Tests.awaitAvailableWindow(io.aeron.test.Tests.awaitAvailableWindow) ControlledFragmentHandler(io.aeron.logbuffer.ControlledFragmentHandler) TestNode(io.aeron.test.cluster.TestNode) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) EgressListener(io.aeron.cluster.client.EgressListener) List(java.util.List) Header(io.aeron.logbuffer.Header) Hashing(org.agrona.collections.Hashing) LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN) LEADER(io.aeron.cluster.service.Cluster.Role.LEADER) Assertions(org.junit.jupiter.api.Assertions) CRC32(java.util.zip.CRC32) TestCluster(io.aeron.test.cluster.TestCluster) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) DirectBuffer(org.agrona.DirectBuffer) CRC32(java.util.zip.CRC32) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 3 with LITTLE_ENDIAN

use of java.nio.ByteOrder.LITTLE_ENDIAN in project aeron by real-logic.

the class ExclusivePublicationTest method offerBlockAcceptsUpToAnEntireTermOfData.

@Test
@InterruptAfter(10)
void offerBlockAcceptsUpToAnEntireTermOfData() {
    final String channel = "aeron:ipc?term-length=64k";
    try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
        ExclusivePublication publication = aeron.addExclusivePublication(channel, STREAM_ID)) {
        final int sessionId = publication.sessionId();
        final int streamId = publication.streamId();
        final int currentTermId = publication.termId();
        final int termBufferLength = publication.termBufferLength();
        final int offset = 1024;
        final RawBlockHandler rawBlockHandler = (fileChannel, fileOffset, termBuffer, termOffset, length, pollSessionId, termId) -> {
            assertEquals(HDR_TYPE_DATA, frameType(termBuffer, termOffset));
            assertEquals(termBufferLength, frameLength(termBuffer, termOffset));
            assertEquals(sessionId, frameSessionId(termBuffer, termOffset));
            assertEquals(streamId, termBuffer.getInt(termOffset + STREAM_ID_FIELD_OFFSET, LITTLE_ENDIAN));
        };
        frameType(srcBuffer, offset, HDR_TYPE_DATA);
        frameLengthOrdered(srcBuffer, offset, termBufferLength);
        frameSessionId(srcBuffer, offset, sessionId);
        srcBuffer.putInt(offset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
        srcBuffer.putInt(offset + TERM_ID_FIELD_OFFSET, currentTermId, LITTLE_ENDIAN);
        srcBuffer.setMemory(offset + DATA_OFFSET, termBufferLength - HEADER_LENGTH, (byte) 13);
        Tests.awaitConnections(subscription, 1);
        while (publication.availableWindow() <= 0) {
            Tests.yield();
        }
        final long position = publication.position();
        final long result = publication.offerBlock(srcBuffer, offset, termBufferLength);
        assertEquals(position + termBufferLength, result);
        final long pollBytes = subscription.rawPoll(rawBlockHandler, termBufferLength);
        assertEquals(termBufferLength, pollBytes);
        assertEquals(publication.termBufferLength(), publication.termOffset());
        assertEquals(currentTermId, publication.termId());
    }
}
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) RawBlockHandler(io.aeron.logbuffer.RawBlockHandler) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 4 with LITTLE_ENDIAN

use of java.nio.ByteOrder.LITTLE_ENDIAN in project Aeron by real-logic.

the class ExclusivePublicationTest method offerBlockAcceptsUpToAnEntireTermOfData.

@Test
@InterruptAfter(10)
void offerBlockAcceptsUpToAnEntireTermOfData() {
    final String channel = "aeron:ipc?term-length=64k";
    try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
        ExclusivePublication publication = aeron.addExclusivePublication(channel, STREAM_ID)) {
        final int sessionId = publication.sessionId();
        final int streamId = publication.streamId();
        final int currentTermId = publication.termId();
        final int termBufferLength = publication.termBufferLength();
        final int offset = 1024;
        final RawBlockHandler rawBlockHandler = (fileChannel, fileOffset, termBuffer, termOffset, length, pollSessionId, termId) -> {
            assertEquals(HDR_TYPE_DATA, frameType(termBuffer, termOffset));
            assertEquals(termBufferLength, frameLength(termBuffer, termOffset));
            assertEquals(sessionId, frameSessionId(termBuffer, termOffset));
            assertEquals(streamId, termBuffer.getInt(termOffset + STREAM_ID_FIELD_OFFSET, LITTLE_ENDIAN));
        };
        frameType(srcBuffer, offset, HDR_TYPE_DATA);
        frameLengthOrdered(srcBuffer, offset, termBufferLength);
        frameSessionId(srcBuffer, offset, sessionId);
        srcBuffer.putInt(offset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
        srcBuffer.putInt(offset + TERM_ID_FIELD_OFFSET, currentTermId, LITTLE_ENDIAN);
        srcBuffer.setMemory(offset + DATA_OFFSET, termBufferLength - HEADER_LENGTH, (byte) 13);
        Tests.awaitConnections(subscription, 1);
        while (publication.availableWindow() <= 0) {
            Tests.yield();
        }
        final long position = publication.position();
        final long result = publication.offerBlock(srcBuffer, offset, termBufferLength);
        assertEquals(position + termBufferLength, result);
        final long pollBytes = subscription.rawPoll(rawBlockHandler, termBufferLength);
        assertEquals(termBufferLength, pollBytes);
        assertEquals(publication.termBufferLength(), publication.termOffset());
        assertEquals(currentTermId, publication.termId());
    }
}
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) RawBlockHandler(io.aeron.logbuffer.RawBlockHandler) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 5 with LITTLE_ENDIAN

use of java.nio.ByteOrder.LITTLE_ENDIAN in project aeron by real-logic.

the class ClusterTest method shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot.

@SuppressWarnings("MethodLength")
@Test
@InterruptAfter(30)
public void shouldAllowChangingTermBufferLengthAndMtuAfterRecordingLogIsTruncatedToTheLatestSnapshot() {
    final int originalTermLength = 256 * 1024;
    final int originalMtu = 1408;
    final int newTermLength = 2 * 1024 * 1024;
    final int newMtu = 8992;
    final CRC32 crc32 = new CRC32();
    cluster = aCluster().withStaticNodes(3).withLogChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withIngressChannel("aeron:udp?term-length=" + originalTermLength + "|mtu=" + originalMtu).withEgressChannel("aeron:udp?endpoint=localhost:0|term-length=" + originalTermLength + "|mtu=" + originalMtu).withServiceSupplier((i) -> new TestNode.TestService[] { new TestNode.TestService(), new TestNode.ChecksumService() }).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    for (int i = 0; i < 3; i++) {
        assertEquals(2, cluster.node(i).services().length);
    }
    cluster.connectClient();
    final int firstBatch = 9;
    int messageLength = computeMaxMessageLength(originalTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
    int payloadLength = messageLength - SIZE_OF_INT;
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'x');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    int msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    long checksum = 0;
    for (int i = 0; i < firstBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
        checksum = Hashing.hash(checksum ^ msgChecksum);
    }
    cluster.awaitResponseMessageCount(firstBatch);
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(1);
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'y');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    final int secondBatch = 11;
    for (int i = 0; i < secondBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
    }
    cluster.awaitResponseMessageCount(firstBatch + secondBatch);
    cluster.stopAllNodes();
    // seed all recording logs from the latest snapshot
    for (int i = 0; i < 3; i++) {
        ClusterTool.seedRecordingLogFromSnapshot(cluster.node(i).consensusModule().context().clusterDir());
    }
    cluster.logChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.ingressChannel("aeron:udp?term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.egressChannel("aeron:udp?endpoint=localhost:0|term-length=" + newTermLength + "|mtu=" + newMtu);
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    assertEquals(2, cluster.followers().size());
    for (int i = 0; i < 3; i++) {
        assertEquals(2, cluster.node(i).services().length);
    }
    cluster.awaitSnapshotsLoaded();
    cluster.reconnectClient();
    messageLength = computeMaxMessageLength(newTermLength) - AeronCluster.SESSION_HEADER_LENGTH;
    payloadLength = messageLength - SIZE_OF_INT;
    cluster.msgBuffer().setMemory(0, payloadLength, (byte) 'z');
    crc32.reset();
    crc32.update(cluster.msgBuffer().byteArray(), 0, payloadLength);
    msgChecksum = (int) crc32.getValue();
    cluster.msgBuffer().putInt(payloadLength, msgChecksum, LITTLE_ENDIAN);
    final int thirdBatch = 5;
    for (int i = 0; i < thirdBatch; i++) {
        cluster.pollUntilMessageSent(messageLength);
        checksum = Hashing.hash(checksum ^ msgChecksum);
    }
    cluster.awaitResponseMessageCount(firstBatch + secondBatch + thirdBatch);
    final int finalMessageCount = firstBatch + thirdBatch;
    final long finalChecksum = checksum;
    final Predicate<TestNode> finalServiceState = node -> {
        final TestNode.TestService[] services = node.services();
        return finalMessageCount == services[0].messageCount() && finalChecksum == ((TestNode.ChecksumService) services[1]).checksum();
    };
    for (int i = 0; i < 3; i++) {
        final TestNode node = cluster.node(i);
        cluster.awaitServiceState(node, finalServiceState);
    }
}
Also used : UNKNOWN_HOST_FILTER(io.aeron.test.SystemTestWatcher.UNKNOWN_HOST_FILTER) ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) ControlledEgressListener(io.aeron.cluster.client.ControlledEgressListener) io.aeron.test(io.aeron.test) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) io.aeron.cluster.codecs(io.aeron.cluster.codecs) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SIZE_OF_INT(org.agrona.BitUtil.SIZE_OF_INT) FrameDescriptor.computeMaxMessageLength(io.aeron.logbuffer.FrameDescriptor.computeMaxMessageLength) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AeronArchive(io.aeron.archive.client.AeronArchive) AuthorisationService(io.aeron.security.AuthorisationService) FOLLOWER(io.aeron.cluster.service.Cluster.Role.FOLLOWER) Publication(io.aeron.Publication) MutableInteger(org.agrona.collections.MutableInteger) EventLogExtension(io.aeron.log.EventLogExtension) MutableBoolean(org.agrona.collections.MutableBoolean) Aeron(io.aeron.Aeron) Tests.awaitAvailableWindow(io.aeron.test.Tests.awaitAvailableWindow) ControlledFragmentHandler(io.aeron.logbuffer.ControlledFragmentHandler) TestNode(io.aeron.test.cluster.TestNode) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) EgressListener(io.aeron.cluster.client.EgressListener) List(java.util.List) Header(io.aeron.logbuffer.Header) Hashing(org.agrona.collections.Hashing) LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN) LEADER(io.aeron.cluster.service.Cluster.Role.LEADER) Assertions(org.junit.jupiter.api.Assertions) CRC32(java.util.zip.CRC32) TestCluster(io.aeron.test.cluster.TestCluster) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) DirectBuffer(org.agrona.DirectBuffer) CRC32(java.util.zip.CRC32) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Aggregations

LITTLE_ENDIAN (java.nio.ByteOrder.LITTLE_ENDIAN)6 MutableInteger (org.agrona.collections.MutableInteger)6 FrameDescriptor (io.aeron.logbuffer.FrameDescriptor)4 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 SIZE_OF_INT (org.agrona.BitUtil.SIZE_OF_INT)4 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)4 Assertions (org.junit.jupiter.api.Assertions)4 Test (org.junit.jupiter.api.Test)4 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)4 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)4 Aeron (io.aeron.Aeron)2 CncFileDescriptor (io.aeron.CncFileDescriptor)2 CommonContext (io.aeron.CommonContext)2 Publication (io.aeron.Publication)2 BACK_PRESSURED (io.aeron.Publication.BACK_PRESSURED)2 CLOSED (io.aeron.Publication.CLOSED)2 CATALOG_FILE_NAME (io.aeron.archive.Archive.Configuration.CATALOG_FILE_NAME)2 FILE_IO_MAX_LENGTH_DEFAULT (io.aeron.archive.Archive.Configuration.FILE_IO_MAX_LENGTH_DEFAULT)2