Search in sources :

Example 16 with RecordingSignal

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

the class ReplicateRecordingTest method shouldReplicateLiveRecordingAndMerge.

@Test
@InterruptAfter(10)
public void shouldReplicateLiveRecordingAndMerge() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    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)) {
        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.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, LIVE_CHANNEL);
        offer(publication, 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);
        awaitPosition(dstCounters, dstCounterId, publication.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 17 with RecordingSignal

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

the class ReplicateRecordingTest method shouldReplicateStoppedRecording.

@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
    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 counters = srcAeron.countersReader();
        final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
        srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(counters, counterId, publication.position());
    }
    srcAeronArchive.stopRecording(subscriptionId);
    final MutableLong dstRecordingId = new MutableLong();
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
    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 ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
    assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
Also used : MutableLong(org.agrona.collections.MutableLong) ObjectHashSet(org.agrona.collections.ObjectHashSet) 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 18 with RecordingSignal

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

the class ReplicateRecordingTest method shouldThrowExceptionWhenSrcRecordingIdUnknown.

@Test
@InterruptAfter(10)
public void shouldThrowExceptionWhenSrcRecordingIdUnknown() {
    final long unknownId = 7L;
    final ControlEventListener listener = mock(ControlEventListener.class);
    final MutableLong dstRecordingId = new MutableLong();
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter = newRecordingSignalAdapter(listener, signalRef, dstRecordingId);
    final long replicationId = dstAeronArchive.replicate(unknownId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
    awaitSignalOrResponse(signalRef, adapter);
    verify(listener).onResponse(eq(dstAeronArchive.controlSessionId()), eq(replicationId), eq((long) ArchiveException.UNKNOWN_RECORDING), eq(ControlResponseCode.ERROR), anyString());
}
Also used : MutableLong(org.agrona.collections.MutableLong) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 19 with RecordingSignal

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

the class ReplicateRecordingTest method shouldReplicateStoppedRecordingsConcurrently.

@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecordingsConcurrently() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long[] srcRecordingIds = new long[2];
    long position = 0;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    for (int i = 0; i < 2; i++) {
        try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
            final CountersReader counters = srcAeron.countersReader();
            final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
            srcRecordingIds[i] = RecordingPos.getRecordingId(counters, counterId);
            offer(publication, messageCount, messagePrefix);
            position = publication.position();
            awaitPosition(counters, counterId, position);
        }
    }
    srcAeronArchive.stopRecording(subscriptionId);
    final MutableLong dstRecordingId = new MutableLong();
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
    for (int i = 0; i < 2; i++) {
        dstAeronArchive.archiveProxy().replicate(srcRecordingIds[i], NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null, dstAeronArchive.context().aeron().nextCorrelationId(), dstAeronArchive.controlSessionId());
    }
    int stopCount = 0;
    while (stopCount < 2) {
        if (RecordingSignal.STOP == awaitSignal(signalRef, adapter)) {
            stopCount++;
        }
    }
    assertEquals(dstAeronArchive.getStopPosition(0), position);
    assertEquals(dstAeronArchive.getStopPosition(1), position);
}
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 20 with RecordingSignal

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

the class ManageRecordingHistoryTest method shouldPurgeRecording.

@Test
@InterruptAfter(10)
void shouldPurgeRecording() throws IOException {
    final String messagePrefix = "Message-Prefix-";
    final long targetPosition = (SEGMENT_LENGTH * 3L) + 1;
    try (Publication publication = aeronArchive.addRecordedPublication(uriBuilder.build(), STREAM_ID)) {
        final CountersReader counters = aeron.countersReader();
        final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
        final long newRecordingId = RecordingPos.getRecordingId(counters, counterId);
        offerToPosition(publication, messagePrefix, targetPosition);
        awaitPosition(counters, counterId, publication.position());
        final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
        final RecordingSignalConsumer consumer = (controlSessionId, correlationId, recordingId, subscriptionId, position, transitionType) -> {
            if (newRecordingId == recordingId) {
                signalRef.set(transitionType);
            }
        };
        final RecordingSignalAdapter adapter = new RecordingSignalAdapter(aeronArchive.controlSessionId(), ERROR_CONTROL_LISTENER, consumer, aeronArchive.controlResponsePoller().subscription(), FRAGMENT_LIMIT);
        aeronArchive.stopRecording(publication);
        assertEquals(RecordingSignal.STOP, awaitSignal(signalRef, adapter));
        final String prefix = newRecordingId + "-";
        final File archiveDir = archive.context().archiveDir();
        assertTrue(new File(archiveDir, prefix + (SEGMENT_LENGTH * 4L) + ".rec").createNewFile());
        assertTrue(new File(archiveDir, prefix + (SEGMENT_LENGTH * 5L) + ".rec.del").createNewFile());
        aeronArchive.purgeRecording(newRecordingId);
        assertEquals(RecordingSignal.DELETE, awaitSignal(signalRef, adapter));
        assertThat(archiveDir.list(((dir, name) -> name.startsWith(prefix))), arrayWithSize(0));
    }
}
Also used : RecordingSignalConsumer(io.aeron.archive.client.RecordingSignalConsumer) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) FRAME_ALIGNMENT(io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT) CountersReader(org.agrona.concurrent.status.CountersReader) RecordingSignalAdapter(io.aeron.archive.client.RecordingSignalAdapter) RecordingSignalConsumer(io.aeron.archive.client.RecordingSignalConsumer) MutableReference(org.agrona.collections.MutableReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) ArchiveSystemTests(io.aeron.archive.ArchiveSystemTests) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publication(io.aeron.Publication) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) Path(java.nio.file.Path) CloseHelper(org.agrona.CloseHelper) RecordingPos(io.aeron.archive.status.RecordingPos) MediaDriver(io.aeron.driver.MediaDriver) Aeron(io.aeron.Aeron) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) ThreadingMode(io.aeron.driver.ThreadingMode) TempDir(org.junit.jupiter.api.io.TempDir) Assertions(org.junit.jupiter.api.Assertions) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) Publication(io.aeron.Publication) MutableReference(org.agrona.collections.MutableReference) RecordingSignalAdapter(io.aeron.archive.client.RecordingSignalAdapter) File(java.io.File) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

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