Search in sources :

Example 1 with RecordingDescriptorCollector

use of io.aeron.samples.archive.RecordingDescriptorCollector in project Aeron by real-logic.

the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.

@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
    final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
    buffer.setMemory(0, buffer.capacity(), (byte) 'z');
    AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
    final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
    final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    final long position1 = recordedPublication1.position();
    final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to record data");
    }
    recordedPublication1.close();
    aeronArchive.stopRecording(subscriptionId);
    while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to stop recording");
    }
    aeronArchive.close();
    archive.close();
    archive.context().deleteDirectory();
    archive = Archive.launch(archiveContext.clone());
    aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
    aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
Also used : RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) ExclusivePublication(io.aeron.ExclusivePublication) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AeronArchive(io.aeron.archive.client.AeronArchive) InterruptAfter(io.aeron.test.InterruptAfter) Test(org.junit.jupiter.api.Test)

Example 2 with RecordingDescriptorCollector

use of io.aeron.samples.archive.RecordingDescriptorCollector in project Aeron by real-logic.

the class ExtendRecordingTest method shouldExtendRecordingAndReplay.

@InterruptAfter(10)
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldExtendRecordingAndReplay(final boolean exclusive) {
    final long controlSessionId = aeronArchive.controlSessionId();
    final int messageCount = 10;
    final long subscriptionIdOne;
    final long subscriptionIdTwo;
    final long stopOne;
    final long stopTwo;
    final long recordingId;
    final PublicationFactory publicationFactory = exclusive ? Aeron::addExclusivePublication : Aeron::addPublication;
    try (Publication publication = publicationFactory.create(aeron, RECORDED_CHANNEL, RECORDED_STREAM_ID);
        Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
        subscriptionIdOne = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
        pollForRecordingSignal(aeronArchive);
        try {
            offer(publication, 0, messageCount);
            final CountersReader counters = aeron.countersReader();
            final int counterId = RecordingPos.findCounterIdBySession(counters, publication.sessionId());
            recordingId = RecordingPos.getRecordingId(counters, counterId);
            consume(subscription, 0, messageCount);
            stopOne = publication.position();
            ArchiveSystemTests.awaitPosition(counters, counterId, stopOne);
        } finally {
            aeronArchive.stopRecording(subscriptionIdOne);
            pollForRecordingSignal(aeronArchive);
        }
    }
    final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
    assertEquals(1L, aeronArchive.listRecordingsForUri(0, 1, "alias=" + MY_ALIAS, RECORDED_STREAM_ID, collector.reset()));
    final RecordingDescriptor recording = collector.descriptors().get(0);
    assertEquals(recordingId, recording.recordingId());
    final String publicationExtendChannel = new ChannelUriStringBuilder().media("udp").endpoint("localhost:3333").initialPosition(recording.stopPosition(), recording.initialTermId(), recording.termBufferLength()).mtu(recording.mtuLength()).alias(MY_ALIAS).build();
    try (Subscription subscription = Tests.reAddSubscription(aeron, EXTEND_CHANNEL, RECORDED_STREAM_ID);
        Publication publication = publicationFactory.create(aeron, publicationExtendChannel, RECORDED_STREAM_ID)) {
        subscriptionIdTwo = aeronArchive.extendRecording(recordingId, EXTEND_CHANNEL, RECORDED_STREAM_ID, LOCAL);
        pollForRecordingSignal(aeronArchive);
        try {
            offer(publication, messageCount, messageCount);
            final CountersReader counters = aeron.countersReader();
            final int counterId = RecordingPos.findCounterIdBySession(counters, publication.sessionId());
            consume(subscription, messageCount, messageCount);
            stopTwo = publication.position();
            ArchiveSystemTests.awaitPosition(counters, counterId, stopTwo);
        } finally {
            aeronArchive.stopRecording(subscriptionIdTwo);
            pollForRecordingSignal(aeronArchive);
        }
    }
    replay(messageCount, stopTwo, recordingId);
    final InOrder inOrder = Mockito.inOrder(mockRecordingSignalConsumer);
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdOne), eq(0L), eq(START));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdOne), eq(stopOne), eq(STOP));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdTwo), eq(stopOne), eq(EXTEND));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdTwo), eq(stopTwo), eq(STOP));
}
Also used : InOrder(org.mockito.InOrder) RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) RecordingDescriptor(io.aeron.samples.archive.RecordingDescriptor) CountersReader(org.agrona.concurrent.status.CountersReader) InterruptAfter(io.aeron.test.InterruptAfter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with RecordingDescriptorCollector

use of io.aeron.samples.archive.RecordingDescriptorCollector in project aeron by real-logic.

the class ExtendRecordingTest method shouldExtendRecordingAndReplay.

@InterruptAfter(10)
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldExtendRecordingAndReplay(final boolean exclusive) {
    final long controlSessionId = aeronArchive.controlSessionId();
    final int messageCount = 10;
    final long subscriptionIdOne;
    final long subscriptionIdTwo;
    final long stopOne;
    final long stopTwo;
    final long recordingId;
    final PublicationFactory publicationFactory = exclusive ? Aeron::addExclusivePublication : Aeron::addPublication;
    try (Publication publication = publicationFactory.create(aeron, RECORDED_CHANNEL, RECORDED_STREAM_ID);
        Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
        subscriptionIdOne = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
        pollForRecordingSignal(aeronArchive);
        try {
            offer(publication, 0, messageCount);
            final CountersReader counters = aeron.countersReader();
            final int counterId = RecordingPos.findCounterIdBySession(counters, publication.sessionId());
            recordingId = RecordingPos.getRecordingId(counters, counterId);
            consume(subscription, 0, messageCount);
            stopOne = publication.position();
            ArchiveSystemTests.awaitPosition(counters, counterId, stopOne);
        } finally {
            aeronArchive.stopRecording(subscriptionIdOne);
            pollForRecordingSignal(aeronArchive);
        }
    }
    final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
    assertEquals(1L, aeronArchive.listRecordingsForUri(0, 1, "alias=" + MY_ALIAS, RECORDED_STREAM_ID, collector.reset()));
    final RecordingDescriptor recording = collector.descriptors().get(0);
    assertEquals(recordingId, recording.recordingId());
    final String publicationExtendChannel = new ChannelUriStringBuilder().media("udp").endpoint("localhost:3333").initialPosition(recording.stopPosition(), recording.initialTermId(), recording.termBufferLength()).mtu(recording.mtuLength()).alias(MY_ALIAS).build();
    try (Subscription subscription = Tests.reAddSubscription(aeron, EXTEND_CHANNEL, RECORDED_STREAM_ID);
        Publication publication = publicationFactory.create(aeron, publicationExtendChannel, RECORDED_STREAM_ID)) {
        subscriptionIdTwo = aeronArchive.extendRecording(recordingId, EXTEND_CHANNEL, RECORDED_STREAM_ID, LOCAL);
        pollForRecordingSignal(aeronArchive);
        try {
            offer(publication, messageCount, messageCount);
            final CountersReader counters = aeron.countersReader();
            final int counterId = RecordingPos.findCounterIdBySession(counters, publication.sessionId());
            consume(subscription, messageCount, messageCount);
            stopTwo = publication.position();
            ArchiveSystemTests.awaitPosition(counters, counterId, stopTwo);
        } finally {
            aeronArchive.stopRecording(subscriptionIdTwo);
            pollForRecordingSignal(aeronArchive);
        }
    }
    replay(messageCount, stopTwo, recordingId);
    final InOrder inOrder = Mockito.inOrder(mockRecordingSignalConsumer);
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdOne), eq(0L), eq(START));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdOne), eq(stopOne), eq(STOP));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdTwo), eq(stopOne), eq(EXTEND));
    inOrder.verify(mockRecordingSignalConsumer).onSignal(eq(controlSessionId), anyLong(), eq(recordingId), eq(subscriptionIdTwo), eq(stopTwo), eq(STOP));
}
Also used : InOrder(org.mockito.InOrder) RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) RecordingDescriptor(io.aeron.samples.archive.RecordingDescriptor) CountersReader(org.agrona.concurrent.status.CountersReader) InterruptAfter(io.aeron.test.InterruptAfter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with RecordingDescriptorCollector

use of io.aeron.samples.archive.RecordingDescriptorCollector in project aeron by real-logic.

the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.

@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
    final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
    buffer.setMemory(0, buffer.capacity(), (byte) 'z');
    AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
    final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
    final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    final long position1 = recordedPublication1.position();
    final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to record data");
    }
    recordedPublication1.close();
    aeronArchive.stopRecording(subscriptionId);
    while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
        Tests.yieldingIdle("Failed to stop recording");
    }
    aeronArchive.close();
    archive.close();
    archive.context().deleteDirectory();
    archive = Archive.launch(archiveContext.clone());
    aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
    final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
    aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
    for (int i = 0; i < 10; i++) {
        while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
            Tests.yieldingIdle("Failed to offer data");
        }
    }
    while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
        Tests.yieldingIdle("Didn't find recording");
    }
    assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
Also used : RecordingDescriptorCollector(io.aeron.samples.archive.RecordingDescriptorCollector) ExclusivePublication(io.aeron.ExclusivePublication) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AeronArchive(io.aeron.archive.client.AeronArchive) InterruptAfter(io.aeron.test.InterruptAfter) Test(org.junit.jupiter.api.Test)

Aggregations

RecordingDescriptorCollector (io.aeron.samples.archive.RecordingDescriptorCollector)4 InterruptAfter (io.aeron.test.InterruptAfter)4 ExclusivePublication (io.aeron.ExclusivePublication)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 RecordingDescriptor (io.aeron.samples.archive.RecordingDescriptor)2 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 CountersReader (org.agrona.concurrent.status.CountersReader)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 InOrder (org.mockito.InOrder)2