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 findLastReturnsLastFoundRecordingMatchingGivenCriteria.
@Test
void findLastReturnsLastFoundRecordingMatchingGivenCriteria() {
final int sessionId = 6;
final int streamId = 1;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
final long recordingF = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, sessionId, streamId, "F", "channelG?tag=f", "sourceA");
catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, sessionId, streamId, "X", "channelG?tag=x", "sourceA");
catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, sessionId, streamId + 1, "F", "channelG?tag=f", "sourceA");
catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, sessionId + 1, streamId, "F", "channelG?tag=f", "sourceA");
assertEquals(recordingF, catalog.findLast(recordingOneId, sessionId, streamId, "channelG?tag=f".getBytes(US_ASCII)));
}
}
use of io.aeron.archive.Catalog in project aeron by real-logic.
the class CatalogTest method shouldReloadExistingIndex.
@Test
void shouldReloadExistingIndex() {
try (Catalog catalog = new Catalog(archiveDir, clock)) {
verifyRecordingForId(catalog, recordingOneId, 160, 6, 1, "channelG", "sourceA");
verifyRecordingForId(catalog, recordingTwoId, 160, 7, 2, "channelH", "sourceV");
verifyRecordingForId(catalog, recordingThreeId, 352, 8, 3, "channelThatIsVeryLongAndShouldNotBeTruncated", "source can also be a very very very long String and it will not be truncated even " + "if gets very very long");
}
}
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 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());
}
}
Aggregations