Search in sources :

Example 16 with Catalog

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

the class CatalogTest method before.

@BeforeEach
void before() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        recordingOneId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 6, 1, "channelG", "channelG?tag=f", "sourceA");
        recordingTwoId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 7, 2, "channelH", "channelH?tag=f", "sourceV");
        recordingThreeId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 8, 3, "channelThatIsVeryLongAndShouldNotBeTruncated", "channelThatIsVeryLongAndShouldNotBeTruncated?tag=f", "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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with Catalog

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

the class CatalogTest method growCatalogThrowsArchiveExceptionIfCatalogIsFull.

@Test
void growCatalogThrowsArchiveExceptionIfCatalogIsFull() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        final ArchiveException exception = assertThrows(ArchiveException.class, () -> catalog.growCatalog(CAPACITY, (int) (CAPACITY + 1)));
        assertEquals("ERROR - catalog is full, max capacity reached: " + CAPACITY, 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 18 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 19 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 20 with Catalog

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

the class CatalogTest method shouldContainChannelFragment.

@Test
void shouldContainChannelFragment() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        final String originalChannel = "aeron:udp?endpoint=localhost:7777|tags=777|alias=TestString";
        final String strippedChannel = "strippedChannelUri";
        final long recordingId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 6, 1, strippedChannel, originalChannel, "sourceA");
        assertTrue(catalog.wrapDescriptor(recordingId, unsafeBuffer));
        recordingDescriptorDecoder.wrap(unsafeBuffer, RecordingDescriptorHeaderDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.BLOCK_LENGTH, RecordingDescriptorDecoder.SCHEMA_VERSION);
        assertTrue(originalChannelContains(recordingDescriptorDecoder, ArrayUtil.EMPTY_BYTE_ARRAY));
        final byte[] originalChannelBytes = originalChannel.getBytes(US_ASCII);
        assertTrue(originalChannelContains(recordingDescriptorDecoder, originalChannelBytes));
        final byte[] tagsBytes = "tags=777".getBytes(US_ASCII);
        assertTrue(originalChannelContains(recordingDescriptorDecoder, tagsBytes));
        final byte[] testBytes = "TestString".getBytes(US_ASCII);
        assertTrue(originalChannelContains(recordingDescriptorDecoder, testBytes));
        final byte[] wrongBytes = "wrong".getBytes(US_ASCII);
        assertFalse(originalChannelContains(recordingDescriptorDecoder, wrongBytes));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) 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