Search in sources :

Example 1 with RecordingSignalAdapter

use of io.aeron.archive.client.RecordingSignalAdapter 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

Aeron (io.aeron.Aeron)1 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)1 Publication (io.aeron.Publication)1 ArchiveSystemTests (io.aeron.archive.ArchiveSystemTests)1 AeronArchive (io.aeron.archive.client.AeronArchive)1 RecordingSignalAdapter (io.aeron.archive.client.RecordingSignalAdapter)1 RecordingSignalConsumer (io.aeron.archive.client.RecordingSignalConsumer)1 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)1 RecordingPos (io.aeron.archive.status.RecordingPos)1 MediaDriver (io.aeron.driver.MediaDriver)1 ThreadingMode (io.aeron.driver.ThreadingMode)1 FRAME_ALIGNMENT (io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT)1 LogBufferDescriptor (io.aeron.logbuffer.LogBufferDescriptor)1 InterruptAfter (io.aeron.test.InterruptAfter)1 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)1 SystemTestWatcher (io.aeron.test.SystemTestWatcher)1 Tests (io.aeron.test.Tests)1 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)1 File (java.io.File)1 IOException (java.io.IOException)1