Search in sources :

Example 46 with Catalog

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());
    }
}
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 47 with Catalog

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

Example 48 with Catalog

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);
    }
}
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 49 with Catalog

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));
        }));
    }
}
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 50 with Catalog

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