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 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 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 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 RecordingDescriptorCollectorTest method shouldAllowUserToRetainDescriptorsToPreventReuse.
@Test
void shouldAllowUserToRetainDescriptorsToPreventReuse(@TempDir final Path tempDir) {
try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
createRecordings(aeronArchive, 3);
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(1);
long fromRecordingId = 0;
int count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
assertEquals(1, count);
final RecordingDescriptor desc0 = collector.descriptors().get(0);
fromRecordingId += count;
count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
assertEquals(1, count);
final RecordingDescriptor desc1 = collector.descriptors().get(0);
assertEquals(desc0.recordingId(), desc1.recordingId());
desc1.retain();
fromRecordingId += count;
count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset());
assertEquals(1, count);
final RecordingDescriptor desc2 = collector.descriptors().get(0);
assertNotEquals(desc1.recordingId(), desc2.recordingId());
}
}
Aggregations