Search in sources :

Example 16 with Context

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

the class ArchiveTest method recordChecksumBufferReturnsDataBufferIfThreadingModeIsNotDEDICATED.

@ParameterizedTest
@EnumSource(value = ArchiveThreadingMode.class, mode = EXCLUDE, names = "DEDICATED")
void recordChecksumBufferReturnsDataBufferIfThreadingModeIsNotDEDICATED(final ArchiveThreadingMode threadingMode) {
    final Checksum recordChecksum = mock(Checksum.class);
    final Archive.Context context = new Archive.Context().recordChecksum(recordChecksum).threadingMode(threadingMode);
    final UnsafeBuffer buffer = context.recordChecksumBuffer();
    assertSame(context.dataBuffer(), buffer);
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) AeronArchive(io.aeron.archive.client.AeronArchive) Checksum(io.aeron.archive.checksum.Checksum) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Context(io.aeron.archive.Archive.Context) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 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 18 with Context

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

the class RecordingWriterTest method onBlockShouldWriteHeaderAndContentsOfTheNonPaddingFrame.

@Test
void onBlockShouldWriteHeaderAndContentsOfTheNonPaddingFrame() throws IOException {
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    recordingWriter.init();
    final UnsafeBuffer termBuffer = new UnsafeBuffer(allocate(128));
    frameType(termBuffer, 0, HDR_TYPE_DATA);
    frameLengthOrdered(termBuffer, 0, 128);
    final byte[] data = new byte[96];
    fill(data, (byte) 7);
    termBuffer.putBytes(HEADER_LENGTH, data);
    recordingWriter.onBlock(termBuffer, 0, 128, -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_DATA, frameType(fileBuffer, 0));
    assertEquals(128, frameLength(fileBuffer, 0));
    assertEquals(0, frameSessionId(fileBuffer, 0));
    final byte[] fileBytes = new byte[96];
    fileBuffer.getBytes(HEADER_LENGTH, fileBytes, 0, 96);
    assertArrayEquals(data, 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 19 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)

Example 20 with Context

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

the class RecordingWriterTest method onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted.

@Test
void onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted() throws IOException {
    final Image image = mockImage(0L);
    final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
    recordingWriter.init();
    assertFalse(Thread.interrupted());
    try {
        Thread.currentThread().interrupt();
        final ArchiveException exception = assertThrows(ArchiveException.class, () -> recordingWriter.onBlock(new UnsafeBuffer(allocate(32)), 0, 10, 5, 8));
        assertEquals(GENERIC, exception.errorCode());
        assertEquals("ERROR - file closed by interrupt, recording aborted", exception.getMessage());
    } finally {
        assertTrue(Thread.interrupted());
    }
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) ArchiveException(io.aeron.archive.client.ArchiveException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) 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