Package no.mnemonic.commons.junit.docker
Class ElasticSearchDockerResource
java.lang.Object
org.junit.rules.ExternalResource
no.mnemonic.commons.junit.docker.DockerResource
no.mnemonic.commons.junit.docker.ElasticSearchDockerResource
- All Implemented Interfaces:
org.junit.rules.TestRule
ElasticSearchDockerResource is a JUnit resource which can be used to write integration tests against an ElasticSearch
server executed inside an isolated Docker container. It extends the basic
DockerResource
and makes sure that
the container initialization waits until ElasticSearch is available. Data indexed into ElasticSearch by tests can be
truncated by providing the indices to delete when constructing the resource and calling deleteIndices()
.
Initialize ElasticSearchDockerResource in the following way as a ClassRule
:
@ClassRule
public static ElasticSearchDockerResource elastic = ElasticSearchDockerResource.builder()
.setImageName("elasticsearch")
.addApplicationPort(9200)
.addApplicationPort(9300)
.addDeleteIndex("foo")
.addDeleteIndex("bar")
.addDeleteIndex("baz")
.build();
See DockerResource.Builder
and ElasticSearchDockerResource.Builder
for more information on the
configuration properties.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder to create an ElasticSearchDockerResource which extendsDockerResource.Builder
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Create builder for ElasticSearchDockerResource.void
Truncate data indexed into ElasticSearch by deleting the indices specified when constructing the resource.protected boolean
Verifies that ElasticSearch is reachable by querying the cluster status from inside the Docker container.Methods inherited from class no.mnemonic.commons.junit.docker.DockerResource
additionalContainerConfig, additionalHostConfig, after, before, getContainerID, getDockerClient, getExposedHost, getExposedHostPort, prepareContainer
Methods inherited from class org.junit.rules.ExternalResource
apply
-
Method Details
-
deleteIndices
public void deleteIndices()Truncate data indexed into ElasticSearch by deleting the indices specified when constructing the resource. If no indices were specified all indices will be deleted.- Throws:
IllegalStateException
- If indices could not be deleted
-
builder
Create builder for ElasticSearchDockerResource.- Returns:
- Builder object
-
isContainerReachable
protected boolean isContainerReachable()Verifies that ElasticSearch is reachable by querying the cluster status from inside the Docker container.- Overrides:
isContainerReachable
in classDockerResource
- Returns:
- True if cluster status could be queried successfully
- Throws:
IllegalStateException
- If cluster status could not be queried
-