use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveLoggingAgentTest method testArchiveLogging.
@SuppressWarnings("try")
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents) {
before(enabledEvents, expectedEvents);
final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010").controlRequestStreamId(100).controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:0").controlResponseStreamId(101);
final Archive.Context archiveCtx = new Archive.Context().errorHandler(Tests::onError).archiveDir(new File(testDir, "archive")).deleteArchiveOnStart(true).recordingEventsEnabled(false).controlChannel(aeronArchiveContext.controlRequestChannel()).controlStreamId(aeronArchiveContext.controlRequestStreamId()).localControlStreamId(aeronArchiveContext.controlRequestStreamId()).recordingEventsChannel(aeronArchiveContext.recordingEventsChannel()).threadingMode(ArchiveThreadingMode.SHARED);
try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx)) {
try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext)) {
Tests.await(WAIT_LIST::isEmpty);
}
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveTest method shouldErrorOnLowSpace.
@Test
@InterruptAfter(10)
public void shouldErrorOnLowSpace() throws IOException {
final int streamId = 7;
final String channel = "aeron:ipc";
final long usableSpace = 100;
final long threshold = 101;
final FileStore fileStore = mock(FileStore.class);
when(fileStore.getUsableSpace()).thenReturn(usableSpace);
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().archiveFileStore(fileStore).lowStorageSpaceThreshold(threshold).deleteArchiveOnStart(true).threadingMode(SHARED);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
AeronArchive archive = AeronArchive.connect()) {
try {
archive.startRecording(channel, streamId, LOCAL);
} catch (final ArchiveException ex) {
assertEquals(ArchiveException.STORAGE_SPACE, ex.errorCode());
return;
}
fail("Expected exception");
} finally {
archiveCtx.deleteDirectory();
driverCtx.deleteDirectory();
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveTest method shouldListRegisteredRecordingSubscriptions.
@Test
@InterruptAfter(10)
public void shouldListRegisteredRecordingSubscriptions() {
final int expectedStreamId = 7;
final String channelOne = "aeron:ipc";
final String channelTwo = "aeron:udp?endpoint=localhost:5678";
final String channelThree = "aeron:udp?endpoint=localhost:4321";
final ArrayList<SubscriptionDescriptor> descriptors = new ArrayList<>();
@SuppressWarnings("Indentation") final RecordingSubscriptionDescriptorConsumer consumer = (controlSessionId, correlationId, subscriptionId, streamId, strippedChannel) -> descriptors.add(new SubscriptionDescriptor(controlSessionId, correlationId, subscriptionId, streamId, strippedChannel));
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
AeronArchive archive = AeronArchive.connect()) {
final long subIdOne = archive.startRecording(channelOne, expectedStreamId, LOCAL);
final long subIdTwo = archive.startRecording(channelTwo, expectedStreamId + 1, LOCAL);
final long subOdThree = archive.startRecording(channelThree, expectedStreamId + 2, LOCAL);
final int countOne = archive.listRecordingSubscriptions(0, 5, "ipc", expectedStreamId, true, consumer);
assertEquals(1, descriptors.size());
assertEquals(1, countOne);
descriptors.clear();
final int countTwo = archive.listRecordingSubscriptions(0, 5, "", expectedStreamId, false, consumer);
assertEquals(3, descriptors.size());
assertEquals(3, countTwo);
archive.stopRecording(subIdTwo);
descriptors.clear();
final int countThree = archive.listRecordingSubscriptions(0, 5, "", expectedStreamId, false, consumer);
assertEquals(2, descriptors.size());
assertEquals(2, countThree);
assertEquals(1L, descriptors.stream().filter((sd) -> sd.subscriptionId == subIdOne).count());
assertEquals(1L, descriptors.stream().filter((sd) -> sd.subscriptionId == subOdThree).count());
} finally {
archiveCtx.deleteDirectory();
driverCtx.deleteDirectory();
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveTest method shouldRecoverRecordingWithNonZeroStartPosition.
@Test
public void shouldRecoverRecordingWithNonZeroStartPosition() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED);
long resultingPosition;
final int initialPosition = DataHeaderFlyweight.HEADER_LENGTH * 9;
final long recordingId;
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx.clone(), archiveCtx.clone());
AeronArchive archive = AeronArchive.connect()) {
final int termLength = 128 * 1024;
final int initialTermId = 29;
final String channel = new ChannelUriStringBuilder().media(CommonContext.IPC_MEDIA).initialPosition(initialPosition, initialTermId, termLength).build();
final Publication publication = archive.addRecordedExclusivePublication(channel, 1);
final DirectBuffer buffer = new UnsafeBuffer("Hello World".getBytes(StandardCharsets.US_ASCII));
while ((resultingPosition = publication.offer(buffer)) <= 0) {
Tests.yield();
}
final Aeron aeron = archive.context().aeron();
int counterId;
final int sessionId = publication.sessionId();
final CountersReader countersReader = aeron.countersReader();
while (Aeron.NULL_VALUE == (counterId = RecordingPos.findCounterIdBySession(countersReader, sessionId))) {
Tests.yield();
}
recordingId = RecordingPos.getRecordingId(countersReader, counterId);
while (countersReader.getCounterValue(counterId) < resultingPosition) {
Tests.yield();
}
}
try (Catalog catalog = openCatalog(archiveCtx)) {
final Catalog.CatalogEntryProcessor catalogEntryProcessor = (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> descriptorEncoder.stopPosition(Aeron.NULL_VALUE);
assertTrue(catalog.forEntry(recordingId, catalogEntryProcessor));
}
final Archive.Context archiveCtxClone = archiveCtx.clone();
final MediaDriver.Context driverCtxClone = driverCtx.clone();
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtxClone, archiveCtxClone);
AeronArchive archive = AeronArchive.connect()) {
assertEquals(initialPosition, archive.getStartPosition(recordingId));
assertEquals(resultingPosition, archive.getStopPosition(recordingId));
} finally {
archiveCtxClone.deleteDirectory();
driverCtxClone.deleteDirectory();
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ClusteredServiceAgent method loadSnapshot.
private void loadSnapshot(final long recordingId) {
try (AeronArchive archive = AeronArchive.connect(ctx.archiveContext().clone())) {
final String channel = ctx.replayChannel();
final int streamId = ctx.replayStreamId();
final int sessionId = (int) archive.startReplay(recordingId, 0, NULL_VALUE, channel, streamId);
final String replaySessionChannel = ChannelUri.addSessionId(channel, sessionId);
try (Subscription subscription = aeron.addSubscription(replaySessionChannel, streamId)) {
final Image image = awaitImage(sessionId, subscription);
loadState(image, archive);
service.onStart(this, image);
}
}
}
Aggregations