Search in sources :

Example 41 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class CatalogTest method testInvalidateRecording.

private void testInvalidateRecording(final long recordingId) {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        final int entries = catalog.entryCount();
        assertTrue(catalog.wrapDescriptor(recordingId, unsafeBuffer));
        recordingDescriptorHeaderDecoder.wrap(unsafeBuffer, 0, RecordingDescriptorHeaderDecoder.BLOCK_LENGTH, RecordingDescriptorHeaderDecoder.SCHEMA_VERSION);
        assertTrue(catalog.invalidateRecording(recordingId));
        assertEquals(INVALID, recordingDescriptorHeaderDecoder.state());
        assertEquals(entries - 1, catalog.entryCount());
        assertFalse(catalog.hasRecording(recordingId));
    }
}
Also used : Catalog(io.aeron.archive.Catalog)

Example 42 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class CatalogTest method recordingStoppedShouldUpdateChecksum.

@Test
void recordingStoppedShouldUpdateChecksum() {
    final Checksum checksum = crc32();
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
        assertChecksum(catalog, recordingOneId, 0);
        catalog.recordingStopped(recordingOneId, 140, 231723682323L);
        assertChecksum(catalog, recordingOneId, 1656993099);
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with Catalog

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()));
}
Also used : FileChannel(java.nio.channels.FileChannel) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) ArchiveException(io.aeron.archive.client.ArchiveException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with Catalog

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());
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class CatalogTest method shouldAppendToExistingIndex.

@Test
void shouldAppendToExistingIndex() {
    final long newRecordingId;
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, () -> 3L, null, segmentFileBuffer)) {
        newRecordingId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 9, 4, "channelJ", "channelJ?tag=f", "sourceN");
    }
    try (Catalog catalog = new Catalog(archiveDir, clock)) {
        verifyRecordingForId(catalog, recordingOneId, 160, 6, 1, "channelG", "sourceA");
        verifyRecordingForId(catalog, newRecordingId, 160, 9, 4, "channelJ", "sourceN");
    }
}
Also used : Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Catalog (io.aeron.archive.Catalog)98 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)78 Test (org.junit.jupiter.api.Test)52 File (java.io.File)44 Checksum (io.aeron.archive.checksum.Checksum)40 ByteBuffer (java.nio.ByteBuffer)36 FileChannel (java.nio.channels.FileChannel)36 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)34 IOException (java.io.IOException)34 INVALID (io.aeron.archive.codecs.RecordingState.INVALID)30 VALID (io.aeron.archive.codecs.RecordingState.VALID)30 EpochClock (org.agrona.concurrent.EpochClock)30 Archive.segmentFileName (io.aeron.archive.Archive.segmentFileName)26 Checksums.crc32 (io.aeron.archive.checksum.Checksums.crc32)26 ByteBuffer.allocate (java.nio.ByteBuffer.allocate)26 IoUtil (org.agrona.IoUtil)26 Assertions (org.junit.jupiter.api.Assertions)26 Arguments (org.junit.jupiter.params.provider.Arguments)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)26 Path (java.nio.file.Path)24