use of io.aeron.samples.archive.RecordingDescriptor 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));
}
use of io.aeron.samples.archive.RecordingDescriptor 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));
}
Aggregations