Search in sources :

Example 26 with AeronArchive

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));
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) File(java.io.File) AeronArchive(io.aeron.archive.client.AeronArchive)

Example 27 with AeronArchive

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 28 with AeronArchive

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) AeronArchive(io.aeron.archive.client.AeronArchive) CountDownLatch(java.util.concurrent.CountDownLatch) AeronArchive(io.aeron.archive.client.AeronArchive) Tests(io.aeron.test.Tests) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with AeronArchive

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with AeronArchive

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));
}
Also used : AeronArchive(io.aeron.archive.client.AeronArchive) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AeronArchive (io.aeron.archive.client.AeronArchive)54 Test (org.junit.jupiter.api.Test)28 MediaDriver (io.aeron.driver.MediaDriver)26 File (java.io.File)17 Aeron (io.aeron.Aeron)14 CommonContext (io.aeron.CommonContext)12 Context (io.aeron.archive.Archive.Context)12 InterruptAfter (io.aeron.test.InterruptAfter)12 Tests (io.aeron.test.Tests)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Archive (io.aeron.archive.Archive)10 ArchiveException (io.aeron.archive.client.ArchiveException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 Publication (io.aeron.Publication)8 FileStore (java.nio.file.FileStore)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)7 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)6