Skip to content

Commit

Permalink
Configure inmemory storage backend
Browse files Browse the repository at this point in the history
  • Loading branch information
rngcntr committed Mar 22, 2023
1 parent cf06c59 commit bb6bb7e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/Testcontainers.JanusGraph/JanusGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected override JanusGraphBuilder Init()
return base.Init()
.WithImage(JanusGraphImage)
.WithPortBinding(JanusGraphPort, true)
.WithEnvironment("janusgraph.storage.backend", "inmemory")
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Channel started at port"));
}

Expand Down
21 changes: 0 additions & 21 deletions src/Testcontainers.JanusGraph/JanusGraphContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace Testcontainers.JanusGraph;
[PublicAPI]
public sealed class JanusGraphContainer : DockerContainer
{

private IGremlinClient _client;

/// <summary>
/// Initializes a new instance of the <see cref="JanusGraphContainer" /> class.
/// </summary>
Expand All @@ -16,22 +13,4 @@ public JanusGraphContainer(JanusGraphConfiguration configuration, ILogger logger
: base(configuration, logger)
{
}

/// <summary>
/// Gets a GraphTraversalSource to execute traversals.
/// </summary>
/// <returns>The GraphTraversalSource which uses a GremlinClient to connect to JanusGraph.</returns>
public GraphTraversalSource GetGraphTraversalSource()
{
return Traversal().WithRemote(new DriverRemoteConnection(GetGremlinClient()));
}

/// <summary>
/// Gets a connected GremlinClient.
/// </summary>
/// <returns>A GremlinClient which operates on this JanusGraph instance.</returns>
private IGremlinClient GetGremlinClient()
{
return _client ?? new GremlinClient(new GremlinServer(Hostname, GetMappedPublicPort(JanusGraphBuilder.JanusGraphPort)), new JanusGraphGraphSONMessageSerializer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="JanusGraph.Net" Version="0.4.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj" />
Expand Down
5 changes: 0 additions & 5 deletions src/Testcontainers.JanusGraph/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
global using Gremlin.Net.Driver;
global using Gremlin.Net.Driver.Remote;
global using Gremlin.Net.Process.Traversal;
global using JanusGraph.Net.IO.GraphSON;
global using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
13 changes: 12 additions & 1 deletion tests/Testcontainers.JanusGraph.Tests/JanusGraphContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public sealed class JanusGraphContainerTest : IAsyncLifetime
{
private readonly JanusGraphContainer _janusGraphContainer = new JanusGraphBuilder().Build();

private IGremlinClient _client;

public Task InitializeAsync()
{
return _janusGraphContainer.StartAsync();
Expand All @@ -14,11 +16,20 @@ public Task DisposeAsync()
return _janusGraphContainer.DisposeAsync().AsTask();
}

private GraphTraversalSource GraphTraversalSource => Traversal().WithRemote(new DriverRemoteConnection(GremlinClient()));

private IGremlinClient GremlinClient()
{
_client ??= new GremlinClient(new GremlinServer(_janusGraphContainer.Hostname,
_janusGraphContainer.GetMappedPublicPort(JanusGraphBuilder.JanusGraphPort)), new JanusGraphGraphSONMessageSerializer());
return _client;
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task InsertedVertexCanBeFound()
{
var g = _janusGraphContainer.GetGraphTraversalSource();
var g = GraphTraversalSource;
await g.AddV("testLabel").Promise(t => t.Iterate());

var actualCount = await g.V().HasLabel("testLabel").Count().Promise(t => t.Next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="JanusGraph.Net" Version="0.4.3" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
5 changes: 5 additions & 0 deletions tests/Testcontainers.JanusGraph.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using Xunit;
global using Gremlin.Net.Driver;
global using Gremlin.Net.Driver.Remote;
global using Gremlin.Net.Process.Traversal;
global using JanusGraph.Net.IO.GraphSON;
global using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;

0 comments on commit bb6bb7e

Please sign in to comment.