Search in sources :

Example 26 with Context

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

the class RecordingWriterTest method onBlockShouldNotComputeCrcForThePaddingFrame.

@Test
void onBlockShouldNotComputeCrcForThePaddingFrame() throws IOException {
    final Image image = mockImage(0L);
    final Context ctx = new Context().archiveDir(archiveDir).recordChecksumBuffer(new UnsafeBuffer(allocateDirectAligned(512, 64))).recordChecksum(crc32());
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, ctx);
    recordingWriter.init();
    final UnsafeBuffer termBuffer = new UnsafeBuffer(allocate(512));
    final int length = 128;
    final byte[] data = new byte[length - HEADER_LENGTH];
    final int sessionId = 5;
    final int termId = 18;
    fill(data, (byte) 99);
    frameType(termBuffer, 0, HDR_TYPE_PAD);
    frameTermId(termBuffer, 0, termId);
    frameLengthOrdered(termBuffer, 0, length);
    frameSessionId(termBuffer, 0, sessionId);
    termBuffer.putBytes(HEADER_LENGTH, data);
    recordingWriter.onBlock(termBuffer, 0, HEADER_LENGTH, -1, -1);
    recordingWriter.close();
    final File segmentFile = segmentFile(1, 0);
    assertTrue(segmentFile.exists());
    assertEquals(SEGMENT_LENGTH, segmentFile.length());
    final UnsafeBuffer fileBuffer = new UnsafeBuffer();
    fileBuffer.wrap(readAllBytes(segmentFile.toPath()));
    assertEquals(HDR_TYPE_PAD, frameType(fileBuffer, 0));
    assertEquals(termId, frameTermId(fileBuffer, 0));
    assertEquals(length, frameLength(fileBuffer, 0));
    assertEquals(sessionId, frameSessionId(fileBuffer, 0));
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 27 with Context

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

the class RecordingWriterTest method onBlockThrowsNullPointerExceptionIfInitWasNotCalled.

@Test
void onBlockThrowsNullPointerExceptionIfInitWasNotCalled() {
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    assertThrows(NullPointerException.class, () -> recordingWriter.onBlock(new UnsafeBuffer(allocate(32)), 0, 10, 5, 8));
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test)

Example 28 with Context

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

the class RecordingWriterTest method initThrowsIOExceptionIfItCannotOpenAFileChannel.

@Test
void initThrowsIOExceptionIfItCannotOpenAFileChannel() throws IOException {
    final File notADirectory = new File(archiveDir, "dummy.txt");
    assertTrue(notADirectory.createNewFile());
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(notADirectory));
    assertThrows(IOException.class, recordingWriter::init);
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 29 with Context

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

the class RecordingWriterTest method onBlockShouldWriteHeaderOfThePaddingFrameAndAdvanceFilePositionByThePaddingLength.

@Test
void onBlockShouldWriteHeaderOfThePaddingFrameAndAdvanceFilePositionByThePaddingLength() throws IOException {
    final int segmentOffset = 96;
    final long startPosition = 7 * TERM_LENGTH + segmentOffset;
    final Image image = mockImage(startPosition);
    final RecordingWriter recordingWriter = new RecordingWriter(5, startPosition, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    recordingWriter.init();
    final UnsafeBuffer termBuffer = new UnsafeBuffer(allocate(1024));
    frameType(termBuffer, 0, HDR_TYPE_PAD);
    frameLengthOrdered(termBuffer, 0, 1024);
    frameSessionId(termBuffer, 0, 111);
    final byte[] data = new byte[992];
    fill(data, (byte) -1);
    termBuffer.putBytes(HEADER_LENGTH, data);
    recordingWriter.onBlock(termBuffer, 0, 1024, -1, -1);
    recordingWriter.close();
    final File segmentFile = segmentFile(5, startPosition);
    assertTrue(segmentFile.exists());
    assertEquals(SEGMENT_LENGTH, segmentFile.length());
    final UnsafeBuffer fileBuffer = new UnsafeBuffer();
    fileBuffer.wrap(readAllBytes(segmentFile.toPath()));
    final byte[] preamble = new byte[segmentOffset];
    fileBuffer.getBytes(0, preamble, 0, segmentOffset);
    assertArrayEquals(new byte[segmentOffset], preamble);
    assertEquals(HDR_TYPE_PAD, frameType(fileBuffer, segmentOffset));
    assertEquals(1024, frameLength(fileBuffer, segmentOffset));
    assertEquals(111, frameSessionId(fileBuffer, segmentOffset));
    final byte[] fileBytes = new byte[992];
    fileBuffer.getBytes(segmentOffset + HEADER_LENGTH, fileBytes, 0, 992);
    assertArrayEquals(new byte[992], fileBytes);
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 30 with Context

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

the class RecordingWriterTest method initShouldOpenAFileChannel.

@Test
void initShouldOpenAFileChannel() throws IOException {
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    final File segmentFile = segmentFile(1, 0);
    assertFalse(segmentFile.exists());
    try {
        recordingWriter.init();
        assertTrue(segmentFile.exists());
    } finally {
        recordingWriter.close();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Context (io.aeron.archive.Archive.Context)40 Test (org.junit.jupiter.api.Test)36 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)30 Image (io.aeron.Image)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 CommonContext (io.aeron.CommonContext)16 File (java.io.File)16 AeronArchive (io.aeron.archive.client.AeronArchive)14 Checksum (io.aeron.archive.checksum.Checksum)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 ArchiveException (io.aeron.archive.client.ArchiveException)2 MediaDriver (io.aeron.driver.MediaDriver)2 Tests (io.aeron.test.Tests)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 ManyToOneConcurrentLinkedQueue (org.agrona.concurrent.ManyToOneConcurrentLinkedQueue)2