Search in sources :

Example 86 with Catalog

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();
}
Also used : FileChannel(java.nio.channels.FileChannel) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) 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 87 with Catalog

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

Example 88 with Catalog

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

Example 89 with Catalog

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());
        }));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Catalog(io.aeron.archive.Catalog) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) IoUtil(org.agrona.IoUtil) ByteBuffer(java.nio.ByteBuffer) FILE_IO_MAX_LENGTH_DEFAULT(io.aeron.archive.Archive.Configuration.FILE_IO_MAX_LENGTH_DEFAULT) CatalogHeaderEncoder(io.aeron.archive.codecs.CatalogHeaderEncoder) ByteBuffer.allocate(java.nio.ByteBuffer.allocate) READ_WRITE(java.nio.channels.FileChannel.MapMode.READ_WRITE) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) HEADER_LENGTH(io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH) RecordingDescriptorHeaderDecoder(io.aeron.archive.codecs.RecordingDescriptorHeaderDecoder) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) BufferUtil(org.agrona.BufferUtil) Checksum(io.aeron.archive.checksum.Checksum) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayUtil(org.agrona.collections.ArrayUtil) File(java.io.File) NULL_TIMESTAMP(io.aeron.archive.client.AeronArchive.NULL_TIMESTAMP) RecordingDescriptorDecoder(io.aeron.archive.codecs.RecordingDescriptorDecoder) Test(org.junit.jupiter.api.Test) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) ArchiveException(io.aeron.archive.client.ArchiveException) Assertions(org.junit.jupiter.api.Assertions) EpochClock(org.agrona.concurrent.EpochClock) Matchers.is(org.hamcrest.Matchers.is) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Checksums.crc32(io.aeron.archive.checksum.Checksums.crc32) Archive.segmentFileName(io.aeron.archive.Archive.segmentFileName) FileChannel(java.nio.channels.FileChannel) Matchers.containsString(org.hamcrest.Matchers.containsString) CATALOG_FILE_NAME(io.aeron.archive.Archive.Configuration.CATALOG_FILE_NAME) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) 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 90 with Catalog

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());
    }
}
Also used : File(java.io.File) 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