use of io.aeron.archive.Catalog in project aeron by real-logic.
the class CatalogTest method growCatalogThrowsArchiveExceptionIfRecordingIsTooBig.
@Test
void growCatalogThrowsArchiveExceptionIfRecordingIsTooBig() {
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
final ArchiveException exception = assertThrows(ArchiveException.class, () -> catalog.growCatalog(CAPACITY * 2, Integer.MAX_VALUE));
assertEquals("ERROR - recording is too big: total recording length is " + Integer.MAX_VALUE + " bytes, available space is " + (CAPACITY * 2 - 800) + " bytes", exception.getMessage());
}
}
use of io.aeron.archive.Catalog in project aeron by real-logic.
the class CatalogTest method findLastReturnsNullRecordingIdIfRecordingIsInTheInvalidState.
@Test
void findLastReturnsNullRecordingIdIfRecordingIsInTheInvalidState() {
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.invalidateRecording(recordingOneId));
assertEquals(NULL_RECORD_ID, catalog.findLast(0, 6, 1, "channelG?tag=f".getBytes(US_ASCII)));
}
}
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 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 CatalogTest method shouldThrowIllegalArgumentExceptionIfCatalogCapacityIsLessThanMinimalCapacity.
@ParameterizedTest
@ValueSource(longs = { -1, 0, MIN_CAPACITY - 1 })
void shouldThrowIllegalArgumentExceptionIfCatalogCapacityIsLessThanMinimalCapacity(final long capacity) {
final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new Catalog(archiveDir, null, 0, capacity, clock, null, segmentFileBuffer));
assertEquals("Invalid catalog capacity provided: expected value >= " + MIN_CAPACITY + ", got " + capacity, exception.getMessage());
}
Aggregations