use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureSamePage.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void shouldFixTimestampAndPositionAfterFailureSamePage() throws Exception {
final long newRecordingId = newRecording();
new File(archiveDir, segmentFileName(newRecordingId, 0)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, SEGMENT_LENGTH)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, 2 * SEGMENT_LENGTH)).createNewFile();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 3 * SEGMENT_LENGTH));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(1024);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, 1024);
bb.clear();
flyweight.frameLength(0);
log.write(bb, 1024 + 128);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(NULL_TIMESTAMP, descriptorDecoder.stopTimestamp());
assertEquals(NULL_POSITION, descriptorDecoder.stopPosition());
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(42L, descriptorDecoder.stopTimestamp());
assertEquals(SEGMENT_LENGTH * 3 + 1024L + 128L, descriptorDecoder.stopPosition());
}));
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampForEmptyRecordingAfterFailure.
@Test
void shouldFixTimestampForEmptyRecordingAfterFailure() {
final long newRecordingId = newRecording();
try (Catalog catalog = new Catalog(archiveDir, clock)) {
final CatalogEntryProcessor entryProcessor = (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> assertEquals(NULL_TIMESTAMP, descriptorDecoder.stopTimestamp());
assertTrue(catalog.forEntry(newRecordingId, entryProcessor));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
final CatalogEntryProcessor entryProcessor = (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> assertEquals(42L, descriptorDecoder.stopTimestamp());
assertTrue(catalog.forEntry(newRecordingId, entryProcessor));
}
}
use of io.aeron.archive.Catalog 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());
}
});
}
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog.
@Test
void shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog() throws IOException {
setNextRecordingId(recordingTwoId);
final ArchiveException exception = assertThrows(ArchiveException.class, () -> new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer));
assertEquals("ERROR - invalid nextRecordingId: expected value greater or equal to " + (recordingThreeId + 1) + ", was " + recordingTwoId, exception.getMessage());
}
use of io.aeron.archive.Catalog in project Aeron by real-logic.
the class CatalogTest method shouldThrowExceptionAfterFailureOnPageStraddle.
@Test
void shouldThrowExceptionAfterFailureOnPageStraddle() 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);
log.write(bb, PAGE_SIZE - 128);
bb.clear();
bb.put(0, (byte) 0).limit(1).position(0);
log.write(bb, PAGE_SIZE + 127);
}
final ArchiveException exception = assertThrows(ArchiveException.class, () -> {
final Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer);
catalog.close();
});
assertThat(exception.getMessage(), containsString(segmentFile.getAbsolutePath()));
}
Aggregations