Skip to content

Commit

Permalink
Migrate to HofmeisterAn/dotnet-testcontainers
Browse files Browse the repository at this point in the history
This will probably become the official version for
testcontainers-dotnet. So migrating now makes it easier for us to
migrate later to the official version.

Fixes #96.

Signed-off-by: Florian Hockmann <[email protected]>
  • Loading branch information
FlorianHockmann committed Jun 10, 2022
1 parent 2474d8c commit 82a71bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 117 deletions.
91 changes: 0 additions & 91 deletions test/JanusGraph.Net.IntegrationTest/GremlinServerContainer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="TestContainers.Container.Abstractions" Version="1.5.3" />
<PackageReference Include="DotNet.Testcontainers" Version="1.6.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
57 changes: 32 additions & 25 deletions test/JanusGraph.Net.IntegrationTest/JanusGraphServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,54 @@
#endregion

using System;
using System.Net.WebSockets;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Remote;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using TestContainers.Container.Abstractions.Hosting;
using TestContainers.Container.Abstractions.Models;
using Xunit;
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;

namespace JanusGraph.Net.IntegrationTest
{
public class JanusGraphServerFixture : IAsyncLifetime
{
private readonly GremlinServerContainer _container;
private readonly TestcontainersContainer _container;
private const ushort JanusGraphServerPort = 8182;

public JanusGraphServerFixture()
{
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
var dockerImage = config["dockerImage"];
_container = new ContainerBuilder<GremlinServerContainer>()
.ConfigureDockerImageName(dockerImage)
.ConfigureLogging(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureContainer((context, container) =>
{
container.ExposedPorts.Add(GremlinServerContainer.GremlinServerPort);

container.BindMounts.Add(new Bind
{
HostPath = $"{AppContext.BaseDirectory}/load_data.groovy",
ContainerPath = "/docker-entrypoint-initdb.d/load_data.groovy",
AccessMode = AccessMode.ReadOnly
});
})
_container = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage(dockerImage)
.WithName("janusgraph")
.WithPortBinding(JanusGraphServerPort)
.WithBindMount($"{AppContext.BaseDirectory}/load_data.groovy",
"/docker-entrypoint-initdb.d/load_data.groovy", AccessMode.ReadOnly)
.WithWaitStrategy(Wait.ForUnixContainer().UntilOperationIsSucceeded(IsServerReady, 1000))
.Build();
_container.ServerStartedCheckTraversal = "g.V().has('name', 'hercules').hasNext()";
}

public string Host => _container.Host;
public int Port => _container.Port;
private bool IsServerReady()
{
try
{
using var client = JanusGraphClientBuilder.BuildClientForServer(new GremlinServer(Host, Port)).Create();
var g = Traversal().WithRemote(new DriverRemoteConnection(client));
return g.V().Has("name", "hercules").HasNext();
}
catch (AggregateException e) when (e.InnerException is WebSocketException)
{
return false;
}
}

public string Host => _container.Hostname;
public int Port => _container.GetMappedPublicPort(JanusGraphServerPort);

public Task InitializeAsync()
{
Expand Down

0 comments on commit 82a71bf

Please sign in to comment.