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