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);
}
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);
}
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);
}
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();
}
}
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());
}
}
Aggregations