use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldReadNextRecordingIdFromCatalogHeader.
@Test
void shouldReadNextRecordingIdFromCatalogHeader() throws IOException {
final long nextRecordingId = 10101010;
setNextRecordingId(nextRecordingId);
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertEquals(nextRecordingId, catalog.nextRecordingId());
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldUseChecksumToVerifyLastFragmentAfterPageStraddle.
@Test
void shouldUseChecksumToVerifyLastFragmentAfterPageStraddle() 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(PAGE_SIZE - 128);
log.write(bb);
bb.clear();
flyweight.frameLength(256);
flyweight.sessionId(1025596259);
log.write(bb, PAGE_SIZE - 128);
bb.clear();
bb.put(0, (byte) 0).limit(1).position(0);
log.write(bb, PAGE_SIZE + 127);
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, crc32(), null)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(42L, descriptorDecoder.stopTimestamp());
assertEquals(PAGE_SIZE + 128, descriptorDecoder.stopPosition());
}));
}
}
use of io.aeron.archive.Catalog 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.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldUse1KBAlignmentWhenReadingFromOldCatalogFile.
@Test
void shouldUse1KBAlignmentWhenReadingFromOldCatalogFile() throws IOException {
final int oldRecordLength = 1024;
final File catalogFile = new File(archiveDir, CATALOG_FILE_NAME);
IoUtil.deleteIfExists(catalogFile);
Files.write(catalogFile.toPath(), new byte[oldRecordLength], CREATE_NEW);
try (Catalog catalog = new Catalog(archiveDir, clock, MIN_CAPACITY, true, null, (version) -> {
})) {
assertEquals(oldRecordLength, catalog.alignment());
}
}
use of io.aeron.archive.Catalog in project aeron by real-logic.
the class ArchiveToolTests method compactDeletesRecordingsInStateInvalidAndDeletesTheCorrespondingSegmentFiles.
@Test
void compactDeletesRecordingsInStateInvalidAndDeletesTheCorrespondingSegmentFiles() {
// Mark recording as INVALID without invoking `invalidateRecording` operation
verifyRecording(out, archiveDir, validRecording3, allOf(VerifyOption.class), crc32(), epochClock, (file) -> false);
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, null, null)) {
assertRecordingState(catalog, validRecording3, INVALID);
assertTrue(catalog.invalidateRecording(validRecording6));
assertRecordingState(catalog, validRecording6, INVALID);
}
final List<String> segmentFiles = new ArrayList<>();
addAll(segmentFiles, listSegmentFiles(archiveDir, validRecording3));
addAll(segmentFiles, listSegmentFiles(archiveDir, validRecording6));
assertTrue(segmentFiles.stream().allMatch(file -> new File(archiveDir, file).exists()), "Non-existing segment files");
compact(out, archiveDir, epochClock);
try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
assertNoRecording(catalog, validRecording3);
assertNoRecording(catalog, validRecording6);
assertEquals(22, catalog.entryCount());
assertRecording(catalog, validRecording0, VALID, 0, 0, NULL_POSITION, 15, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording51, VALID, 0, 0, 64 + PAGE_SIZE, 20, 777, 0, 20, "ch2", "src2");
}
assertTrue(segmentFiles.stream().noneMatch(file -> new File(archiveDir, file).exists()), "Segment files not deleted");
Mockito.verify(out).println("Compaction result: deleted 2 records and reclaimed 384 bytes");
}
Aggregations