We are using Elasticsearch and planning to have JUnits for our modules. These JUnits run during our product build infact as a first step... we are looking for a kind of embedded Elasticsearch which we can use for our JUnits as we don't want to have a running instance in a VM and use it... (or) are there any recommendations to mock Elasticsearch APIs?
One of the easiest thing to do ATM is to extend ESIntegTestCase
and add this dependency in your project:
<dependency>
<groupId>org.elasticsearch.test</groupId>
<artifactId>framework</artifactId>
<version>5.0.0-alpha3</version>
<scope>test</scope>
</dependency>
And something like this:
<plugin>
<!-- we skip surefire to work with randomized testing above -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>junit4-maven-plugin</artifactId>
<version>2.3.3</version>
<!-- Defaults for all tests (ITs and Unit). -->
<configuration>
<heartbeat>10</heartbeat>
<jvmOutputAction>pipe,ignore</jvmOutputAction>
<leaveTemporary>true</leaveTemporary>
<ifNoTests>warn</ifNoTests>
<parallelism>${tests.jvms}</parallelism>
<assertions enableSystemAssertions="false">
<enable/>
<disable package="${tests.assertion.disabled}"/>
<!-- pass org.elasticsearch to run without assertions -->
</assertions>
<listeners>
<report-text showThrowable="true" showStackTraces="true" showOutput="${tests.output}" showStatusOk="true"
showStatusError="true" showStatusFailure="true" showStatusIgnored="true" showSuiteSummary="true" />
</listeners>
<seed>${tests.seed}</seed>
<systemProperties combine.children="append">
<arg.common>arg.common</arg.common>
<tests.locale>${tests.locale}</tests.locale>
<tests.nightly>${tests.nightly}</tests.nightly>
</systemProperties>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>junit4</goal>
</goals>
</execution>
</executions>
</plugin>
Hope this helps
Thanks for the reply. I haven't understood the usage of what you have said.
Where do the Elasticsearch run?
How do I use it in my JUnit class?
We are looking for something like the one below ,
Endpoint.publish("http://localhost:9292/ws/milli", new HelloWorld()); which opens up a http port on 9292..
similar thing for Elasticsearch... !!!
@Before
start the Elasticsearch
Run the junits
@Shutdown
shutdown the Elasticsearch
The test framework will start an embedded cluster for you if you extend the class I mentioned.