Search in sources :

Example 1 with PAGE_SIZE

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

the class CatalogTest method shouldFixTimestampAndPositionAfterFailurePageStraddle.

@Test
public void shouldFixTimestampAndPositionAfterFailurePageStraddle() 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 = ByteBuffer.allocateDirect(HEADER_LENGTH);
        final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
        flyweight.frameLength(PAGE_SIZE - 32);
        log.write(bb);
        bb.clear();
        flyweight.frameLength(128);
        log.write(bb, PAGE_SIZE - 32);
        bb.clear();
        flyweight.frameLength(0);
        log.write(bb, PAGE_SIZE - 32 + 128);
    }
    try (Catalog catalog = new Catalog(archiveDir, clock)) {
        catalog.forEntry((he, hd, e, decoder) -> {
            assertThat(decoder.stopTimestamp(), is(NULL_TIMESTAMP));
            assertThat(decoder.stopPosition(), is(NULL_POSITION));
        }, newRecordingId);
    }
    currentTimeMs = 42L;
    try (Catalog catalog = new Catalog(archiveDir, null, 0, MAX_ENTRIES, clock)) {
        assertTrue(catalog.forEntry((he, hd, e, decoder) -> {
            assertThat(decoder.stopTimestamp(), is(42L));
            assertThat(decoder.stopPosition(), is((long) PAGE_SIZE - 32));
        }, newRecordingId));
    }
}
Also used : Catalog.wrapDescriptorDecoder(io.aeron.archive.Catalog.wrapDescriptorDecoder) HEADER_LENGTH(io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH) StandardOpenOption(java.nio.file.StandardOpenOption) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test) PAGE_SIZE(io.aeron.archive.Catalog.PAGE_SIZE) IoUtil(org.agrona.IoUtil) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) NULL_TIMESTAMP(io.aeron.archive.client.AeronArchive.NULL_TIMESTAMP) RecordingDescriptorDecoder(io.aeron.archive.codecs.RecordingDescriptorDecoder) After(org.junit.After) EpochClock(org.agrona.concurrent.EpochClock) Matchers.is(org.hamcrest.Matchers.is) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Archive.segmentFileName(io.aeron.archive.Archive.segmentFileName) Assert(org.junit.Assert) FileChannel(java.nio.channels.FileChannel) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) Before(org.junit.Before) FileChannel(java.nio.channels.FileChannel) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Archive.segmentFileName (io.aeron.archive.Archive.segmentFileName)1 PAGE_SIZE (io.aeron.archive.Catalog.PAGE_SIZE)1 Catalog.wrapDescriptorDecoder (io.aeron.archive.Catalog.wrapDescriptorDecoder)1 NULL_POSITION (io.aeron.archive.client.AeronArchive.NULL_POSITION)1 NULL_TIMESTAMP (io.aeron.archive.client.AeronArchive.NULL_TIMESTAMP)1 RecordingDescriptorDecoder (io.aeron.archive.codecs.RecordingDescriptorDecoder)1 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)1 HEADER_LENGTH (io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH)1 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 IoUtil (org.agrona.IoUtil)1 EpochClock (org.agrona.concurrent.EpochClock)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Matchers.is (org.hamcrest.Matchers.is)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Test (org.junit.Test)1