Skip to content

Commit

Permalink
Merge pull request #667 from mikeb01/master
Browse files Browse the repository at this point in the history
Add unit tests to validate contexts can't be reused when constructing…
  • Loading branch information
mjpt777 authored May 12, 2019
2 parents 23a8c14 + c917b2b commit c988255
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions aeron-driver/src/test/java/io/aeron/driver/DriverContextTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.aeron.driver;

import io.aeron.driver.exceptions.ActiveDriverException;
import io.aeron.exceptions.ConcurrentConcludeException;
import org.junit.Test;

import static org.junit.Assert.fail;

public class DriverContextTest
{
@Test
public void shouldPreventCreatingMultipleDriversWithTheSameContext()
{
final MediaDriver.Context ctx = new MediaDriver.Context();

try (
MediaDriver mediaDriver1 = MediaDriver.launchEmbedded(ctx);
MediaDriver mediaDriver2 = MediaDriver.launchEmbedded(ctx))
{
fail("Exception should be thrown for reuse of the MediaDriver.Context instance");
}
catch (final ActiveDriverException | ConcurrentConcludeException e)
{
// Expected
}
}
}
25 changes: 25 additions & 0 deletions aeron-system-tests/src/test/java/io/aeron/ClientContextTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.aeron;

import io.aeron.driver.MediaDriver;
import io.aeron.exceptions.ConcurrentConcludeException;
import org.junit.Test;

public class ClientContextTest
{
@Test(expected = ConcurrentConcludeException.class)
public void shouldPreventCreatingMultipleClientsWithTheSameContext()
{
try (MediaDriver mediaDriver = MediaDriver.launchEmbedded())
{
final Aeron.Context ctx = new Aeron.Context()
.aeronDirectoryName(mediaDriver.aeronDirectoryName());

//noinspection EmptyTryBlock
try (
Aeron aeron1 = Aeron.connect(ctx);
Aeron aeron2 = Aeron.connect(ctx))
{
}
}
}
}

0 comments on commit c988255

Please sign in to comment.