Skip to content

Commit

Permalink
Merge pull request #634 from JPWatson/archive-client
Browse files Browse the repository at this point in the history
[Java] Fix issue where multiple archive clients are trying to connect.
  • Loading branch information
mjpt777 committed Feb 11, 2019
2 parents 50ccd3e + ad2547b commit 6f6bed0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Expand Up @@ -28,7 +28,7 @@
*/
public class ControlResponsePoller implements ControlledFragmentHandler
{
private static final int FRAGMENT_LIMIT = 10;
private static final int FRAGMENT_LIMIT = 1;

private final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder();
private final ControlResponseDecoder controlResponseDecoder = new ControlResponseDecoder();
Expand Down
39 changes: 39 additions & 0 deletions aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java
Expand Up @@ -15,8 +15,15 @@
*/
package io.aeron.archive;

import io.aeron.archive.client.AeronArchive;
import io.aeron.driver.MediaDriver;
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 static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

Expand All @@ -33,4 +40,36 @@ public void shouldGenerateRecordingName()

assertThat(actual, is(expected));
}

@Test
public void shouldAllowMultipleConnectionsInParallel() throws InterruptedException
{
final int numberOfArchiveClients = 5;
final CountDownLatch latch = new CountDownLatch(numberOfArchiveClients);
final ExecutorService executorService = Executors.newFixedThreadPool(numberOfArchiveClients);

final MediaDriver.Context driverCtx = new MediaDriver.Context();
final Archive.Context archiveCtx = new Archive.Context();

try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(driverCtx, archiveCtx))
{
for (int i = 0; i < numberOfArchiveClients; i++)
{
executorService.execute(() ->
{
AeronArchive.connect();
latch.countDown();
});
}

latch.await(10, TimeUnit.SECONDS);

assertThat(latch.getCount(), is(0L));
}
finally
{
archiveCtx.deleteArchiveDirectory();
driverCtx.deleteAeronDirectory();
}
}
}

0 comments on commit 6f6bed0

Please sign in to comment.