use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.
the class ExtendRecordingTest method launchAeronAndArchive.
private void launchAeronAndArchive() {
final String aeronDirectoryName = CommonContext.generateRandomDirName();
if (null == archiveDir) {
archiveDir = new File(IoUtil.tmpDirName(), "archive");
}
archivingMediaDriver = ArchivingMediaDriver.launch(new MediaDriver.Context().aeronDirectoryName(aeronDirectoryName).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).errorHandler(Throwable::printStackTrace).spiesSimulateConnection(false).dirDeleteOnStart(true), new Archive.Context().maxCatalogEntries(MAX_CATALOG_ENTRIES).aeronDirectoryName(aeronDirectoryName).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED));
aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron));
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveTest method shouldErrorWhenUnauthorised.
@Test
@InterruptAfter(10)
public void shouldErrorWhenUnauthorised() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final AuthorisationServiceSupplier authorisationServiceSupplier = () -> (protocolId, actionId, type, encodedPrincipal) -> {
return actionId != TruncateRecordingRequestDecoder.TEMPLATE_ID;
};
final Archive.Context archiveCtx = new Archive.Context().deleteArchiveOnStart(true).authorisationServiceSupplier(authorisationServiceSupplier).threadingMode(SHARED);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
AeronArchive archive = AeronArchive.connect()) {
try {
archive.truncateRecording(0, 0);
} catch (final ArchiveException ex) {
assertEquals(ArchiveException.UNAUTHORISED_ACTION, 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 shouldAllowMultipleConnectionsInParallel.
@Test
public void shouldAllowMultipleConnectionsInParallel() throws InterruptedException {
final int numberOfArchiveClients = 5;
final long connectTimeoutNs = TimeUnit.SECONDS.toNanos(10);
final CountDownLatch latch = new CountDownLatch(numberOfArchiveClients);
final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(numberOfArchiveClients);
final ManyToOneConcurrentLinkedQueue<AeronArchive> archiveClientQueue = new ManyToOneConcurrentLinkedQueue<>();
final MediaDriver.Context driverCtx = new MediaDriver.Context().errorHandler(Tests::onError).clientLivenessTimeoutNs(connectTimeoutNs).dirDeleteOnStart(true).publicationUnblockTimeoutNs(connectTimeoutNs * 2).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED).connectTimeoutNs(connectTimeoutNs);
executor.prestartAllCoreThreads();
try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) {
for (int i = 0; i < numberOfArchiveClients; i++) {
executor.execute(() -> {
final AeronArchive.Context ctx = new AeronArchive.Context().messageTimeoutNs(connectTimeoutNs);
final AeronArchive archive = AeronArchive.connect(ctx);
archiveClientQueue.add(archive);
latch.countDown();
});
}
assertTrue(latch.await(driver.archive().context().connectTimeoutNs() * 2, TimeUnit.NANOSECONDS));
AeronArchive archiveClient;
while (null != (archiveClient = archiveClientQueue.poll())) {
archiveClient.close();
}
} finally {
executor.shutdownNow();
archiveCtx.deleteDirectory();
driverCtx.deleteDirectory();
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ArchiveTest method shouldResolveControlResponseEndpointAddress.
@ParameterizedTest
@ValueSource(strings = { "localhost:0", "localhost:8888" })
public void shouldResolveControlResponseEndpointAddress(final String endpoint) {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED);
final String controlResponseChannel = "aeron:udp?endpoint=" + endpoint;
final AeronArchive.Context clientContext = new AeronArchive.Context().controlResponseChannel(controlResponseChannel);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
AeronArchive archive = AeronArchive.connect(clientContext)) {
final int count = archive.listRecordings(0, 10, (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> {
});
assertEquals(0, count);
} finally {
archiveCtx.deleteDirectory();
driverCtx.deleteDirectory();
}
}
use of io.aeron.archive.client.AeronArchive in project Aeron by real-logic.
the class ExtendRecordingTest method before.
@BeforeEach
void before() {
final String aeronDirectoryName = CommonContext.generateRandomDirName();
if (null == archiveDir) {
archiveDir = new File(SystemUtil.tmpDirName(), "archive");
}
final MediaDriver.Context driverCtx = new MediaDriver.Context().aeronDirectoryName(aeronDirectoryName).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).spiesSimulateConnection(false).dirDeleteOnStart(true);
final Archive.Context archiveCtx = new Archive.Context().catalogCapacity(ArchiveSystemTests.CATALOG_CAPACITY).aeronDirectoryName(aeronDirectoryName).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED);
try {
driver = TestMediaDriver.launch(driverCtx, systemTestWatcher);
archive = Archive.launch(archiveCtx);
} finally {
systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
}
aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
aeronArchive = AeronArchive.connect(new AeronArchive.Context().recordingSignalConsumer(mockRecordingSignalConsumer).aeron(aeron));
}
Aggregations