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);
}
}
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);
}
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;
}
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);
}
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());
}
});
}
}
Aggregations