Search in sources :

Example 11 with Image

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 12 with Image

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;
}
Also used : Image(io.aeron.Image)

Example 13 with 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());
    }
}
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)

Example 14 with Image

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);
        }
    }
}
Also used : Image(io.aeron.Image)

Example 15 with Image

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;
}
Also used : Image(io.aeron.Image)

Aggregations

Image (io.aeron.Image)34 Test (org.junit.jupiter.api.Test)26 Context (io.aeron.archive.Archive.Context)20 File (java.io.File)20 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)14 ClusteredService (io.aeron.cluster.service.ClusteredService)7 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)7 ExclusivePublication (io.aeron.ExclusivePublication)6 Archive (io.aeron.archive.Archive)6 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)6 CLUSTER_MEMBERS (io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS)6 INGRESS_ENDPOINTS (io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS)6 AeronCluster (io.aeron.cluster.client.AeronCluster)6 ClientSession (io.aeron.cluster.service.ClientSession)6 Cluster (io.aeron.cluster.service.Cluster)6 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)6 MediaDriver (io.aeron.driver.MediaDriver)6 ThreadingMode (io.aeron.driver.ThreadingMode)6 FragmentHandler (io.aeron.logbuffer.FragmentHandler)6 ClusterTests (io.aeron.test.cluster.ClusterTests)6