Search in sources :

Example 1 with ManyToOneConcurrentLinkedQueue

use of org.agrona.concurrent.ManyToOneConcurrentLinkedQueue 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)

Aggregations

CommonContext (io.aeron.CommonContext)1 Context (io.aeron.archive.Archive.Context)1 AeronArchive (io.aeron.archive.client.AeronArchive)1 MediaDriver (io.aeron.driver.MediaDriver)1 Tests (io.aeron.test.Tests)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ManyToOneConcurrentLinkedQueue (org.agrona.concurrent.ManyToOneConcurrentLinkedQueue)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1