Many thanks to DJPorv who created the first version of this.
This is a fully embedded version of Elasticsearch for integration tests. When the instance is created both the jvm and elasticsearch itself is extracted to a temporary location (2-3 seconds in my tests) and started (5-6 seconds in my tests). Once disposed everything is removed again.
The instance will be started on a random port - full url available as Url property.
To use elasticsearch in integration tests simply instantiate it - in these tests I'm using the excellent client Elasticsearch-NEST:
using (var elasticsearch = new Elasticsearch())
{
////Arrange
var client = new ElasticClient(new ConnectionSettings(elasticsearch.Url));
////Act
var result = client.Ping();
////Assert
Assert.That(result.IsValid);
}
A few settings can be modified via the constructor. In this example I change the port and add a custom commandline argument for the elasticsearch startup:
using (var elasticsearch = new Elasticsearch(c => c
.Port(444)
.AddArgument("-Des.script.engine.groovy.file.aggs=on")))
{
////Arrange
var client = new ElasticClient(new ConnectionSettings(elasticsearch.Url));
////Act
var result = client.Ping();
////Assert
Assert.That(result.IsValid);
Assert.That(elasticsearch.Url.Port, Is.EqualTo(444));
}
By default nothing is being logged, logging to trace can be enabled with EnableLogging() and can be customized to log to somewhere else with the LogTo() statement:
Console output is by default being written to Trace.Write but can be customized by providing a custom logging-lambda:
using (new Elasticsearch(c => c.EnableLogging().LogTo(Console.WriteLine)))
{
}
Simply add the Nuget package:
PM> Install-Package elasticsearch-inside
You'll need .NET Framework 4.5.1 or later to use the precompiled binaries.
Elasticsearch Inside is under the MIT license.