Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Adaptive.Aeron.Tests/CncFileDescriptorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class CncFileDescriptorTest
[Test]
public void ShouldAllocateCapacityForCounterMetadataBuffer()
{
string aeronDir = Aeron.Context.GetAeronDirectoryName();

MappedByteBuffer cncByteBuffer = IoUtil.MapExistingFile(
Path.Combine(aeronDir, "cnc.dat"),
Path.Combine(_driver.AeronDirectoryName, "cnc.dat"),
MapMode.ReadOnly
);

Expand Down
19 changes: 10 additions & 9 deletions src/Adaptive.Aeron.Tests/ContextText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,31 @@ namespace Adaptive.Aeron.Tests
public class ContextText
{
private EmbeddedMediaDriver _driver;
private Aeron.Context _ctx;

[SetUp]
public void StartDriver() => _driver = new EmbeddedMediaDriver();
public void SetUp()
{
_driver = new EmbeddedMediaDriver();
_ctx = new Aeron.Context().AeronDirectoryName(_driver.AeronDirectoryName);
}

[TearDown]
public void StopDriver() => _driver?.Dispose();

[Test]
public void ShouldNotAllowConcludeMoreThanOnce()
{
var ctx = new Aeron.Context();

ctx.Conclude();
Assert.Throws(typeof(ConcurrentConcludeException), () => ctx.Conclude());
_ctx.Conclude();
Assert.Throws(typeof(ConcurrentConcludeException), () => _ctx.Conclude());
}

[Test]
public void ShouldAllowConcludeOfClonedContext()
{
var ctx = new Aeron.Context();

var ctx2 = ctx.Clone();
var ctx2 = _ctx.Clone();

ctx.Conclude();
_ctx.Conclude();
ctx2.Conclude();
}
}
Expand Down
68 changes: 62 additions & 6 deletions src/Adaptive.Aeron.Tests/EmbeddedMediaDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal sealed class EmbeddedMediaDriver : IDisposable

public EmbeddedMediaDriver()
{
_aeronDir = Aeron.Context.GetAeronDirectoryName();
_aeronDir = Path.Combine(Path.GetTempPath(), "aeron-" + Guid.NewGuid().ToString("N"));
if (Directory.Exists(_aeronDir))
{
try
Expand Down Expand Up @@ -72,11 +72,21 @@ public EmbeddedMediaDriver()
"-Daeron.driver.termination.validator=io.aeron.driver.DefaultAllowTerminationValidator"
);
psi.ArgumentList.Add("-Daeron.threading.mode=SHARED");
psi.ArgumentList.Add("-Daeron.dir.delete.on.shutdown=true");
psi.ArgumentList.Add("io.aeron.driver.MediaDriver");

_driver = Process.Start(psi) ?? throw new InvalidOperationException("failed to start media driver");

WaitForDriverReady();
try
{
WaitForDriverReady();
}
catch
{
ShutdownDriver();
_driver.Dispose();
throw;
}
}

public string AeronDirectoryName => _aeronDir;
Expand All @@ -94,30 +104,76 @@ public void Dispose()
}

if (!_driver.WaitForExit(ShutdownTimeoutMs))
{
ShutdownDriver();
}

bool exited;
try
{
exited = _driver.HasExited;
}
catch
{
exited = false;
}

_driver.Dispose();

if (exited)
{
try
{
_driver.Kill(entireProcessTree: true);
if (Directory.Exists(_aeronDir))
{
Directory.Delete(_aeronDir, recursive: true);
}
}
catch
{
}
}
}

private void ShutdownDriver()
{
try
{
if (!_driver.HasExited)
{
_driver.Kill(entireProcessTree: true);
}
}
catch
{
}

try
{
_driver.WaitForExit(ShutdownTimeoutMs);
}
_driver.Dispose();
catch
{
}
}

private static void WaitForDriverReady()
private void WaitForDriverReady()
{
var clock = new SystemEpochClock();
var deadline = clock.Time() + StartupTimeoutMs;
Exception last = null;

while (clock.Time() < deadline)
{
if (_driver.HasExited)
{
throw new InvalidOperationException(
$"driver process exited prematurely with code {_driver.ExitCode}");
}

try
{
using var aeron = Aeron.Connect();
using var aeron = Aeron.Connect(new Aeron.Context().AeronDirectoryName(_aeronDir));
return;
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion src/Adaptive.Aeron.Tests/SystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SystemTest
[Test]
public void BasicMessageTest()
{
using var aeron = Aeron.Connect();
using var aeron = Aeron.Connect(new Aeron.Context().AeronDirectoryName(_driver.AeronDirectoryName));
var publication = aeron.AddPublication("aeron:ipc", 1);
var subscription = aeron.AddSubscription("aeron:ipc", 1);
Await(() => publication.IsConnected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2087,8 +2087,6 @@ public void ShouldContinueConsumingFromLiveWhileArchiveIsUnavailable()

// Kill the archive JVM. PS is already in LIVE so its archive control session is idle;
// it should keep consuming the live channel without noticing.
DisposeWithTimeout(AeronArchive, 3_000, "AeronArchive (mid-test)");
AeronArchive = null;
Archive.Dispose();
Archive = null;

Expand Down
Loading