Search in sources :

Example 26 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class CatalogTest method startPositionShouldUpdateChecksum.

@Test
void startPositionShouldUpdateChecksum() {
    final Checksum checksum = crc32();
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
        assertChecksum(catalog, recordingThreeId, 0);
        catalog.startPosition(recordingThreeId, 123);
        assertChecksum(catalog, recordingThreeId, -160510802);
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class ArchiveTest method recordChecksumBufferIsAllocatedOnDemandIfThreadingModeIsDEDICATED.

@Test
void recordChecksumBufferIsAllocatedOnDemandIfThreadingModeIsDEDICATED() {
    final Checksum recordChecksum = mock(Checksum.class);
    final Archive.Context context = new Archive.Context().recordChecksum(recordChecksum).threadingMode(DEDICATED);
    final UnsafeBuffer buffer = context.recordChecksumBuffer();
    assertNotNull(buffer);
    assertEquals(context.fileIoMaxLength(), buffer.capacity());
    assertSame(buffer, context.recordChecksumBuffer());
    assertNotSame(context.dataBuffer(), buffer);
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) AeronArchive(io.aeron.archive.client.AeronArchive) Checksum(io.aeron.archive.checksum.Checksum) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class ReplaySession method replay.

private int replay() throws IOException {
    if (!publication.isConnected()) {
        state(State.INACTIVE);
        return 0;
    }
    if (replayPosition >= stopPosition && null != limitPosition && noNewData(replayPosition, stopPosition)) {
        return 0;
    }
    if (termOffset == termLength) {
        nextTerm();
    }
    int workCount = 0;
    final int bytesRead = readRecording(stopPosition - replayPosition);
    if (bytesRead > 0) {
        int batchOffset = 0;
        int paddingFrameLength = 0;
        final int sessionId = publication.sessionId();
        final int streamId = publication.streamId();
        final long remaining = replayLimit - replayPosition;
        final Checksum checksum = this.checksum;
        final UnsafeBuffer replayBuffer = this.replayBuffer;
        while (batchOffset < bytesRead && batchOffset < remaining) {
            final int frameLength = frameLength(replayBuffer, batchOffset);
            if (frameLength <= 0) {
                raiseError(frameLength, bytesRead, batchOffset, remaining);
            }
            final int frameType = frameType(replayBuffer, batchOffset);
            final int alignedLength = align(frameLength, FRAME_ALIGNMENT);
            if (HDR_TYPE_DATA == frameType) {
                if (batchOffset + alignedLength > bytesRead) {
                    break;
                }
                if (null != checksum) {
                    verifyChecksum(checksum, batchOffset, alignedLength);
                }
                replayBuffer.putInt(batchOffset + SESSION_ID_FIELD_OFFSET, sessionId, LITTLE_ENDIAN);
                replayBuffer.putInt(batchOffset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
                batchOffset += alignedLength;
            } else if (HDR_TYPE_PAD == frameType) {
                paddingFrameLength = frameLength;
                break;
            }
        }
        if (batchOffset > 0) {
            final long position = publication.offerBlock(replayBuffer, 0, batchOffset);
            if (hasPublicationAdvanced(position, batchOffset)) {
                workCount++;
            } else {
                paddingFrameLength = 0;
            }
        }
        if (paddingFrameLength > 0) {
            final long position = publication.appendPadding(paddingFrameLength - HEADER_LENGTH);
            if (hasPublicationAdvanced(position, align(paddingFrameLength, FRAME_ALIGNMENT))) {
                workCount++;
            }
        }
    }
    return workCount;
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 29 with Checksum

use of io.aeron.archive.checksum.Checksum in project aeron by real-logic.

the class ArchiveTest method recordChecksumBufferIsAllocatedOnDemandIfThreadingModeIsDEDICATED.

@Test
void recordChecksumBufferIsAllocatedOnDemandIfThreadingModeIsDEDICATED() {
    final Checksum recordChecksum = mock(Checksum.class);
    final Archive.Context context = new Archive.Context().recordChecksum(recordChecksum).threadingMode(DEDICATED);
    final UnsafeBuffer buffer = context.recordChecksumBuffer();
    assertNotNull(buffer);
    assertEquals(context.fileIoMaxLength(), buffer.capacity());
    assertSame(buffer, context.recordChecksumBuffer());
    assertNotSame(context.dataBuffer(), buffer);
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) AeronArchive(io.aeron.archive.client.AeronArchive) Checksum(io.aeron.archive.checksum.Checksum) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with Checksum

use of io.aeron.archive.checksum.Checksum in project aeron by real-logic.

the class CatalogTest method shouldComputeChecksumOfTheRecordingDescriptorUponAddingToTheCatalog.

@Test
void shouldComputeChecksumOfTheRecordingDescriptorUponAddingToTheCatalog() {
    final Checksum checksum = crc32();
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
        final long recordingId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 6, 1, "channelNew", "channelNew?tag=X", "sourceX");
        final long recordingId2 = catalog.addNewRecording(1, 100, 2, 222, 111, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 16, 12, "channelNew2", "channelNew?tag=X2", "sourceX2");
        catalog.forEach((recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
            if (recordingId == descriptorDecoder.recordingId()) {
                assertEquals(1691549102, headerDecoder.checksum());
            } else if (recordingId2 == descriptorDecoder.recordingId()) {
                assertEquals(1452384985, headerDecoder.checksum());
            } else {
                assertEquals(0, headerDecoder.checksum());
            }
        });
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Checksum (io.aeron.archive.checksum.Checksum)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Catalog (io.aeron.archive.Catalog)22 AeronArchive (io.aeron.archive.client.AeronArchive)16 Test (org.junit.jupiter.api.Test)16 INVALID (io.aeron.archive.codecs.RecordingState.INVALID)14 VALID (io.aeron.archive.codecs.RecordingState.VALID)14 File (java.io.File)14 IOException (java.io.IOException)14 ByteBuffer (java.nio.ByteBuffer)14 FileChannel (java.nio.channels.FileChannel)14 EpochClock (org.agrona.concurrent.EpochClock)14 RECORDING_SEGMENT_SUFFIX (io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX)12 APPLY_CHECKSUM (io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM)12 VERIFY_ALL_SEGMENT_FILES (io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES)12 LogBufferDescriptor.computeTermIdFromPosition (io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition)12 LogBufferDescriptor.positionBitsToShift (io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift)12 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)12 PrintStream (java.io.PrintStream)12 Path (java.nio.file.Path)12