use of io.aeron.Image 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.Image in project aeron by real-logic.
the class RecordingWriterTest method mockImage.
private Image mockImage(final long joinPosition) {
final Image image = mock(Image.class);
when(image.termBufferLength()).thenReturn(TERM_LENGTH);
when(image.joinPosition()).thenReturn(joinPosition);
return image;
}
use of io.aeron.Image 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());
}
}
use of io.aeron.Image in project aeron by real-logic.
the class EmbeddedPingPong method roundTripMessages.
private static void roundTripMessages(final FragmentHandler fragmentHandler, final Publication pingPublication, final Subscription pongSubscription, final long numMessages) {
while (!pongSubscription.isConnected()) {
Thread.yield();
}
final Image image = pongSubscription.imageAtIndex(0);
for (long i = 0; i < numMessages; i++) {
long offeredPosition;
do {
OFFER_BUFFER.putLong(0, System.nanoTime());
} while ((offeredPosition = pingPublication.offer(OFFER_BUFFER, 0, MESSAGE_LENGTH, null)) < 0L);
while (image.position() < offeredPosition) {
final int fragments = image.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT);
PONG_HANDLER_IDLE_STRATEGY.idle(fragments);
}
}
}
use of io.aeron.Image in project aeron by real-logic.
the class RecordingSessionTest method mockImage.
private Image mockImage(final int sessionId, final int initialTermId, final String sourceIdentity, final int termBufferLength, final Subscription subscription) {
final Image image = mock(Image.class);
when(image.sessionId()).thenReturn(sessionId);
when(image.initialTermId()).thenReturn(initialTermId);
when(image.sourceIdentity()).thenReturn(sourceIdentity);
when(image.termBufferLength()).thenReturn(termBufferLength);
when(image.subscription()).thenReturn(subscription);
when(image.mtuLength()).thenReturn(MTU_LENGTH);
when(image.joinPosition()).thenReturn(START_POSITION);
return image;
}
Aggregations