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));
}
}
Aggregations