Search in sources :

Example 41 with MutableReference

use of org.agrona.collections.MutableReference in project aeron by real-logic.

the class ReplicateRecordingTest method shouldReplicateLiveRecordingAndMergeWhileFollowingWithTaggedSubscription.

@Test
@InterruptAfter(10)
public void shouldReplicateLiveRecordingAndMergeWhileFollowingWithTaggedSubscription() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    final long channelTagId = dstAeron.nextCorrelationId();
    final long subscriptionTagId = dstAeron.nextCorrelationId();
    final String taggedChannel = "aeron:udp?control-mode=manual|rejoin=false|tags=" + channelTagId + "," + subscriptionTagId;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter;
    try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID);
        Subscription taggedSubscription = dstAeron.addSubscription(taggedChannel, LIVE_STREAM_ID)) {
        final CountersReader srcCounters = srcAeron.countersReader();
        final int counterId = awaitRecordingCounterId(srcCounters, publication.sessionId());
        srcRecordingId = RecordingPos.getRecordingId(srcCounters, counterId);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(srcCounters, counterId, publication.position());
        final MutableLong dstRecordingId = new MutableLong();
        adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
        dstAeronArchive.taggedReplicate(srcRecordingId, NULL_VALUE, channelTagId, subscriptionTagId, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, LIVE_CHANNEL);
        consume(taggedSubscription, messageCount, messagePrefix);
        offer(publication, messageCount, messagePrefix);
        consume(taggedSubscription, messageCount, messagePrefix);
        assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
        assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
        assertEquals(RecordingSignal.MERGE, awaitSignal(signalRef, adapter));
        final CountersReader dstCounters = dstAeron.countersReader();
        final int dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId.get());
        offer(publication, messageCount, messagePrefix);
        consume(taggedSubscription, messageCount, messagePrefix);
        awaitPosition(dstCounters, dstCounterId, publication.position());
        final Image image = taggedSubscription.imageBySessionId(publication.sessionId());
        assertEquals(publication.position(), image.position());
    }
    srcAeronArchive.stopRecording(subscriptionId);
    assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
}
Also used : MutableLong(org.agrona.collections.MutableLong) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 42 with MutableReference

use of org.agrona.collections.MutableReference in project aeron by real-logic.

the class ReentrantClientTest method shouldThrowWhenReentering.

@Test
void shouldThrowWhenReentering() {
    final MutableReference<Throwable> expectedException = new MutableReference<>();
    final ErrorHandler errorHandler = expectedException::set;
    try (Aeron aeron = Aeron.connect(new Aeron.Context().errorHandler(errorHandler))) {
        final String channel = CommonContext.IPC_CHANNEL;
        final AvailableImageHandler mockHandler = mock(AvailableImageHandler.class);
        doAnswer((invocation) -> aeron.addSubscription(channel, 3)).when(mockHandler).onAvailableImage(any(Image.class));
        final Subscription sub = aeron.addSubscription(channel, 1001, mockHandler, null);
        final Publication pub = aeron.addPublication(channel, 1001);
        verify(mockHandler, timeout(5000L)).onAvailableImage(any(Image.class));
        pub.close();
        sub.close();
        assertThat(expectedException.get(), instanceOf(AeronException.class));
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) AeronException(io.aeron.exceptions.AeronException) MutableReference(org.agrona.collections.MutableReference) Test(org.junit.jupiter.api.Test)

Aggregations

MutableReference (org.agrona.collections.MutableReference)42 Test (org.junit.jupiter.api.Test)42 InterruptAfter (io.aeron.test.InterruptAfter)34 MutableLong (org.agrona.collections.MutableLong)28 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)20 CountersReader (org.agrona.concurrent.status.CountersReader)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MediaDriver (io.aeron.driver.MediaDriver)10 ThreadingMode (io.aeron.driver.ThreadingMode)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 File (java.io.File)8 CloseHelper (org.agrona.CloseHelper)8 CommonContext (io.aeron.CommonContext)6 AeronCluster (io.aeron.cluster.client.AeronCluster)6 EgressListener (io.aeron.cluster.client.EgressListener)6 io.aeron.test (io.aeron.test)6 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)6 Archive (io.aeron.archive.Archive)4