use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldAllowMultipleInstancesForSameStream.
@Test
void shouldAllowMultipleInstancesForSameStream() {
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertEquals(CAPACITY, catalog.capacity());
final long newRecordingId = newRecording();
assertNotEquals(recordingOneId, newRecordingId);
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method stopPositionShouldUpdateChecksum.
@Test
void stopPositionShouldUpdateChecksum() {
final Checksum checksum = crc32();
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
assertChecksum(catalog, recordingTwoId, 0);
catalog.stopPosition(recordingTwoId, 7777);
assertChecksum(catalog, recordingTwoId, -1985007076);
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldNotThrowWhenOldRecordingLogsAreDeleted.
@Test
void shouldNotThrowWhenOldRecordingLogsAreDeleted() throws IOException {
final File segmentFile = new File(archiveDir, segmentFileName(recordingThreeId, SEGMENT_LENGTH * 2));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(256);
log.write(bb);
}
final Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer);
catalog.close();
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureFullSegment.
@Test
void shouldFixTimestampAndPositionAfterFailureFullSegment() throws Exception {
final long newRecordingId = newRecording();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 0));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(SEGMENT_LENGTH - 128);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, SEGMENT_LENGTH - 128);
log.truncate(SEGMENT_LENGTH);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(NULL_TIMESTAMP));
assertThat(descriptorDecoder.stopPosition(), is(NULL_POSITION));
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(42L));
assertThat(descriptorDecoder.stopPosition(), is((long) SEGMENT_LENGTH));
}));
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class ArchiveToolTests method verifyChecksum.
@Test
void verifyChecksum() {
final Checksum checksum = crc32();
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
assertRecording(catalog, validRecording51, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> catalog.updateChecksum(recordingDescriptorOffset));
assertRecording(catalog, validRecording6, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> catalog.updateChecksum(recordingDescriptorOffset));
}
assertFalse(verify(out, archiveDir, of(APPLY_CHECKSUM), checksum, epochClock, (file) -> true));
try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
assertRecording(catalog, validRecording0, INVALID, 0, 0, NULL_POSITION, 15, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording1, INVALID, 0, 1024, NULL_POSITION, 16, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording2, INVALID, 0, TERM_LENGTH * 3 + 96, NULL_POSITION, 17, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording3, INVALID, 0, 7 * TERM_LENGTH + 96, 7 * TERM_LENGTH + 128, 18, NULL_TIMESTAMP, 7, 13, "ch2", "src2");
assertRecording(catalog, validRecording4, INVALID, 0, 21 * TERM_LENGTH + (TERM_LENGTH - 64), 22 * TERM_LENGTH + 992, 19, 1, -25, 7, "ch2", "src2");
assertRecording(catalog, validRecording51, VALID, -940881948, 0, 64 + PAGE_SIZE, 20, 777, 0, 20, "ch2", "src2");
assertRecording(catalog, validRecording52, INVALID, 0, 0, NULL_POSITION, 21, NULL_TIMESTAMP, 0, 52, "ch2", "src2");
assertRecording(catalog, validRecording53, INVALID, 0, 0, NULL_POSITION, 22, NULL_TIMESTAMP, 0, 53, "ch2", "src2");
assertRecording(catalog, validRecording6, VALID, -175549265, 352, 960, 23, 100, 0, 6, "ch2", "src2");
}
Mockito.verify(out, times(24)).println(any(String.class));
}
Aggregations