Search in sources :

Example 1 with RecordingSignal

use of io.aeron.archive.codecs.RecordingSignal in project Aeron by real-logic.

the class LogReplicationTest method shouldFailIfRecordingLogIsDeletedDuringReplication.

@Test
void shouldFailIfRecordingLogIsDeletedDuringReplication() {
    final RecordingSignal recordingSignal = RecordingSignal.DELETE;
    final long stopPosition = 982734;
    final long nowNs = 0;
    final LogReplication logReplication = new LogReplication(aeronArchive, SRC_RECORDING_ID, DST_RECORDING_ID, stopPosition, ENDPOINT, REPLICATION_CHANNEL, PROGRESS_CHECK_TIMEOUT_NS, PROGRESS_CHECK_INTERVAL_NS, nowNs);
    assertThrows(ClusterException.class, () -> logReplication.onSignal(REPLICATION_ID, DST_RECORDING_ID, stopPosition - 1, recordingSignal));
}
Also used : RecordingSignal(io.aeron.archive.codecs.RecordingSignal) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RecordingSignal

use of io.aeron.archive.codecs.RecordingSignal in project Aeron by real-logic.

the class ReplicateRecordingTest method shouldReplicateMoreThanOnce.

@Test
@InterruptAfter(10)
public void shouldReplicateMoreThanOnce() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, 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 recordingIdRef = new MutableLong();
        final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
        final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, recordingIdRef);
        long replicationId = dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
        assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
        assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
        final CountersReader dstCounters = dstAeron.countersReader();
        final long dstRecordingId = recordingIdRef.get();
        int dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId);
        awaitPosition(dstCounters, dstCounterId, publication.position());
        dstAeronArchive.stopReplication(replicationId);
        assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
        replicationId = dstAeronArchive.replicate(srcRecordingId, dstRecordingId, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
        assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
        dstCounterId = RecordingPos.findCounterIdByRecording(dstCounters, dstRecordingId);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(dstCounters, dstCounterId, publication.position());
        dstAeronArchive.stopReplication(replicationId);
    }
    srcAeronArchive.stopRecording(subscriptionId);
}
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 3 with RecordingSignal

use of io.aeron.archive.codecs.RecordingSignal in project Aeron by real-logic.

the class ReplicateRecordingTest method shouldReplicateLiveRecordingAndStopAtSpecifiedPosition.

@Test
@InterruptAfter(10)
public void shouldReplicateLiveRecordingAndStopAtSpecifiedPosition() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
        final CountersReader srcCounters = srcAeron.countersReader();
        final int counterId = awaitRecordingCounterId(srcCounters, publication.sessionId());
        srcRecordingId = RecordingPos.getRecordingId(srcCounters, counterId);
        offer(publication, messageCount, messagePrefix);
        final long firstPosition = publication.position();
        awaitPosition(srcCounters, counterId, firstPosition);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(srcCounters, counterId, publication.position());
        final MutableLong dstRecordingId = new MutableLong();
        final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
        final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
        dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, firstPosition, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null, null);
        assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
        assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
        assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
        offer(publication, messageCount, messagePrefix);
        final int srcCounterId = RecordingPos.findCounterIdByRecording(srcCounters, srcRecordingId);
        awaitPosition(srcCounters, srcCounterId, publication.position());
        assertTrue(firstPosition < publication.position());
        long dstStopPosition;
        while (NULL_POSITION == (dstStopPosition = dstAeronArchive.getStopPosition(dstRecordingId.get()))) {
            Tests.yield();
        }
        assertEquals(firstPosition, dstStopPosition);
    }
    srcAeronArchive.stopRecording(subscriptionId);
}
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 4 with RecordingSignal

use of io.aeron.archive.codecs.RecordingSignal 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 5 with RecordingSignal

use of io.aeron.archive.codecs.RecordingSignal in project aeron by real-logic.

the class LogReplicationTest method shouldFailIfRecordingLogIsDeletedDuringReplication.

@Test
void shouldFailIfRecordingLogIsDeletedDuringReplication() {
    final RecordingSignal recordingSignal = RecordingSignal.DELETE;
    final long stopPosition = 982734;
    final long nowNs = 0;
    final LogReplication logReplication = new LogReplication(aeronArchive, SRC_RECORDING_ID, DST_RECORDING_ID, stopPosition, ENDPOINT, REPLICATION_CHANNEL, PROGRESS_CHECK_TIMEOUT_NS, PROGRESS_CHECK_INTERVAL_NS, nowNs);
    assertThrows(ClusterException.class, () -> logReplication.onSignal(REPLICATION_ID, DST_RECORDING_ID, stopPosition - 1, recordingSignal));
}
Also used : RecordingSignal(io.aeron.archive.codecs.RecordingSignal) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RecordingSignal (io.aeron.archive.codecs.RecordingSignal)22 Test (org.junit.jupiter.api.Test)22 InterruptAfter (io.aeron.test.InterruptAfter)20 MutableReference (org.agrona.collections.MutableReference)20 MutableLong (org.agrona.collections.MutableLong)18 CountersReader (org.agrona.concurrent.status.CountersReader)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 Aeron (io.aeron.Aeron)2 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)2 Publication (io.aeron.Publication)2 ArchiveSystemTests (io.aeron.archive.ArchiveSystemTests)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 RecordingSignalAdapter (io.aeron.archive.client.RecordingSignalAdapter)2 RecordingSignalConsumer (io.aeron.archive.client.RecordingSignalConsumer)2 RecordingPos (io.aeron.archive.status.RecordingPos)2 MediaDriver (io.aeron.driver.MediaDriver)2 ThreadingMode (io.aeron.driver.ThreadingMode)2 FRAME_ALIGNMENT (io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT)2 LogBufferDescriptor (io.aeron.logbuffer.LogBufferDescriptor)2 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)2