diff --git a/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java b/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java index c8da689716..eefb2cd5d8 100644 --- a/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java +++ b/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java @@ -17,12 +17,10 @@ import io.aeron.archive.client.AeronArchive; import io.aeron.driver.MediaDriver; +import org.agrona.concurrent.ManyToOneConcurrentLinkedQueue; import org.junit.Test; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -47,19 +45,20 @@ public void shouldAllowMultipleConnectionsInParallel() throws InterruptedExcepti final int numberOfArchiveClients = 5; final CountDownLatch latch = new CountDownLatch(numberOfArchiveClients); final ExecutorService executorService = Executors.newFixedThreadPool(numberOfArchiveClients); - + final ManyToOneConcurrentLinkedQueue archiveClientQueue = new ManyToOneConcurrentLinkedQueue<>(); final MediaDriver.Context driverCtx = new MediaDriver.Context(); final Archive.Context archiveCtx = new Archive.Context(); - try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) + try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) { for (int i = 0; i < numberOfArchiveClients; i++) { - executorService.execute(() -> - { - AeronArchive.connect(); - latch.countDown(); - }); + executorService.execute( + () -> + { + archiveClientQueue.add(AeronArchive.connect()); + latch.countDown(); + }); } latch.await(10, TimeUnit.SECONDS); @@ -68,6 +67,14 @@ public void shouldAllowMultipleConnectionsInParallel() throws InterruptedExcepti } finally { + executorService.shutdownNow(); + + AeronArchive archiveClient; + while (null != (archiveClient = archiveClientQueue.poll())) + { + archiveClient.close(); + } + archiveCtx.deleteArchiveDirectory(); driverCtx.deleteAeronDirectory(); }