Skip to content
Permalink
Browse files
IGNITE-16382 .NET: Speed up tests by reusing server node (#587)
Do not start/stop a new node for every test class, use one for everything, stop on test process exit.
  • Loading branch information
ptupitsyn committed Jan 25, 2022
1 parent 8db3c70 commit 0e2cd84dce7be1a7d3b3c0238dc55c2ad939ece3
Showing 4 changed files with 17 additions and 9 deletions.
@@ -17,6 +17,7 @@

namespace Apache.Ignite.Tests
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Ignite.Table;
@@ -34,11 +35,18 @@ public class IgniteTestsBase

protected const string ValCol = "val";

private JavaServer? _serverNode;
private static readonly JavaServer ServerNode;

private TestEventListener _eventListener = null!;

protected int ServerPort => _serverNode?.Port ?? 0;
static IgniteTestsBase()
{
ServerNode = JavaServer.StartAsync().GetAwaiter().GetResult();

AppDomain.CurrentDomain.ProcessExit += (_, _) => ServerNode.Dispose();
}

protected static int ServerPort => ServerNode.Port;

protected IIgniteClient Client { get; private set; } = null!;

@@ -53,7 +61,6 @@ public async Task OneTimeSetUp()
{
_eventListener = new TestEventListener();

_serverNode = await JavaServer.StartAsync();
Client = await IgniteClient.StartAsync(GetConfig());

Table = (await Client.Tables.GetTableAsync(TableName))!;
@@ -66,7 +73,6 @@ public void OneTimeTearDown()
{
// ReSharper disable once ConstantConditionalAccessQualifier
Client?.Dispose();
_serverNode?.Dispose();

Assert.Greater(_eventListener.BuffersRented, 0);
Assert.AreEqual(_eventListener.BuffersReturned, _eventListener.BuffersRented);
@@ -76,7 +82,7 @@ public void OneTimeTearDown()
[TearDown]
public async Task TearDown()
{
await TupleView.DeleteAllAsync(null, Enumerable.Range(1, 10).Select(x => GetTuple(x)));
await TupleView.DeleteAllAsync(null, Enumerable.Range(-5, 20).Select(x => GetTuple(x)));

Assert.AreEqual(_eventListener.BuffersReturned, _eventListener.BuffersRented);
}
@@ -86,9 +92,9 @@ public async Task TearDown()

protected static Poco GetPoco(long id, string? val = null) => new() {Key = id, Val = val};

protected IgniteClientConfiguration GetConfig() => new()
protected static IgniteClientConfiguration GetConfig() => new()
{
Endpoints = { "127.0.0.1:" + _serverNode?.Port }
Endpoints = { "127.0.0.1:" + ServerNode.Port }
};
}
}
@@ -121,6 +121,7 @@ public void Dispose()
{
_process?.Kill();
_process?.Dispose();
Log(">>> Java server stopped.");
}

/// <summary>
@@ -120,7 +120,7 @@ private static unsafe void WriteHandshake(Stream stream, int majorVersion = 3)
stream.Write(bufferWriter.WrittenSpan);
}

private async Task<NetworkStream> Connect()
private static async Task<NetworkStream> Connect()
{
Socket socket = new(SocketType.Stream, ProtocolType.Tcp)
{
@@ -10,7 +10,8 @@ In repo root: `mvn clean install -DskipTests`
In this dir: `dotnet build`

## Run Tests
In this dir: `dotnet test`
In this dir: `dotnet test --logger "console;verbosity=normal"`
Specific test: `dotnet test --logger "console;verbosity=normal" --filter ClientSocketTests`

## Start a Test Node
* cd `modules/runner`

0 comments on commit 0e2cd84

Please sign in to comment.