|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
[[testing-intro]]
|
|
|
|
|
|
-Testing is a crucial part of your application, and as information retrieval itself is already a complex topic, there should not be any additional complexity in setting up a testing infrastructure, which uses elasticsearch. This is the main reason why we decided to release an additional file to the release, which allows you to use the same testing infrastructure we do in the elasticsearch core. The testing framework allows you to setup clusters with multiple nodes in order to check if your code covers everything needed to run in a cluster. The framework prevents you from writing complex code yourself to start, stop or manage several test nodes in a cluster. In addition there is another very important feature called randomized testing, which you are getting for free as it is part of the elasticsearch infrastructure.
|
|
|
+Testing is a crucial part of your application, and as information retrieval itself is already a complex topic, there should not be any additional complexity in setting up a testing infrastructure, which uses Elasticsearch. This is the main reason why we decided to release an additional file to the release, which allows you to use the same testing infrastructure we do in the Elasticsearch core. The testing framework allows you to setup clusters with multiple nodes in order to check if your code covers everything needed to run in a cluster. The framework prevents you from writing complex code yourself to start, stop or manage several test nodes in a cluster. In addition there is another very important feature called randomized testing, which you are getting for free as it is part of the Elasticsearch infrastructure.
|
|
|
|
|
|
|
|
|
|
|
@@ -16,9 +16,9 @@ All of the tests are run using a custom junit runner, the `RandomizedRunner` pro
|
|
|
|
|
|
|
|
|
[[using-elasticsearch-test-classes]]
|
|
|
-=== Using the elasticsearch test classes
|
|
|
+=== Using the Elasticsearch test classes
|
|
|
|
|
|
-First, you need to include the testing dependency in your project, along with the elasticsearch dependency you have already added. If you use maven and its `pom.xml` file, it looks like this
|
|
|
+First, you need to include the testing dependency in your project, along with the Elasticsearch dependency you have already added. If you use maven and its `pom.xml` file, it looks like this
|
|
|
|
|
|
[source,xml]
|
|
|
--------------------------------------------------
|
|
@@ -50,7 +50,7 @@ We provide a few classes that you can inherit from in your own test classes whic
|
|
|
[[unit-tests]]
|
|
|
=== unit tests
|
|
|
|
|
|
-If your test is a well isolated unit test which doesn't need a running elasticsearch cluster, you can use the `ESTestCase`. If you are testing lucene features, use `ESTestCase` and if you are testing concrete token streams, use the `ESTokenStreamTestCase` class. Those specific classes execute additional checks which ensure that no resources leaks are happening, after the test has run.
|
|
|
+If your test is a well isolated unit test which doesn't need a running Elasticsearch cluster, you can use the `ESTestCase`. If you are testing lucene features, use `ESTestCase` and if you are testing concrete token streams, use the `ESTokenStreamTestCase` class. Those specific classes execute additional checks which ensure that no resources leaks are happening, after the test has run.
|
|
|
|
|
|
|
|
|
[[integration-tests]]
|
|
@@ -58,7 +58,7 @@ If your test is a well isolated unit test which doesn't need a running elasticse
|
|
|
|
|
|
These kind of tests require firing up a whole cluster of nodes, before the tests can actually be run. Compared to unit tests they are obviously way more time consuming, but the test infrastructure tries to minimize the time cost by only restarting the whole cluster, if this is configured explicitly.
|
|
|
|
|
|
-The class your tests have to inherit from is `ESIntegTestCase`. By inheriting from this class, you will no longer need to start elasticsearch nodes manually in your test, although you might need to ensure that at least a certain number of nodes are up. The integration test behaviour can be configured heavily by specifying different system properties on test runs. See the `TESTING.asciidoc` documentation in the https://github.com/elastic/elasticsearch/blob/master/TESTING.asciidoc[source repository] for more information.
|
|
|
+The class your tests have to inherit from is `ESIntegTestCase`. By inheriting from this class, you will no longer need to start Elasticsearch nodes manually in your test, although you might need to ensure that at least a certain number of nodes are up. The integration test behaviour can be configured heavily by specifying different system properties on test runs. See the `TESTING.asciidoc` documentation in the https://github.com/elastic/elasticsearch/blob/master/TESTING.asciidoc[source repository] for more information.
|
|
|
|
|
|
|
|
|
[[number-of-shards]]
|
|
@@ -100,8 +100,8 @@ The `InternalTestCluster` class is the heart of the cluster functionality in a r
|
|
|
`stopRandomNode()`:: Stop a random node in your cluster to mimic an outage
|
|
|
`stopCurrentMasterNode()`:: Stop the current master node to force a new election
|
|
|
`stopRandomNonMaster()`:: Stop a random non master node to mimic an outage
|
|
|
-`buildNode()`:: Create a new elasticsearch node
|
|
|
-`startNode(settings)`:: Create and start a new elasticsearch node
|
|
|
+`buildNode()`:: Create a new Elasticsearch node
|
|
|
+`startNode(settings)`:: Create and start a new Elasticsearch node
|
|
|
|
|
|
|
|
|
[[changing-node-settings]]
|
|
@@ -165,7 +165,7 @@ data nodes will be allowed to become masters as well.
|
|
|
[[changing-node-configuration]]
|
|
|
==== Changing plugins via configuration
|
|
|
|
|
|
-As elasticsearch is using JUnit 4, using the `@Before` and `@After` annotations is not a problem. However you should keep in mind, that this does not have any effect in your cluster setup, as the cluster is already up and running when those methods are run. So in case you want to configure settings - like loading a plugin on node startup - before the node is actually running, you should overwrite the `nodePlugins()` method from the `ESIntegTestCase` class and return the plugin classes each node should load.
|
|
|
+As Elasticsearch is using JUnit 4, using the `@Before` and `@After` annotations is not a problem. However you should keep in mind, that this does not have any effect in your cluster setup, as the cluster is already up and running when those methods are run. So in case you want to configure settings - like loading a plugin on node startup - before the node is actually running, you should overwrite the `nodePlugins()` method from the `ESIntegTestCase` class and return the plugin classes each node should load.
|
|
|
|
|
|
[source,java]
|
|
|
-----------------------------------------
|
|
@@ -191,7 +191,7 @@ The next step is to convert your test using static test data into a test using r
|
|
|
* Changing your response sizes/configurable limits with each run
|
|
|
* Changing the number of shards/replicas when creating an index
|
|
|
|
|
|
-So, how can you create random data. The most important thing to know is, that you never should instantiate your own `Random` instance, but use the one provided in the `RandomizedTest`, from which all elasticsearch dependent test classes inherit from.
|
|
|
+So, how can you create random data. The most important thing to know is, that you never should instantiate your own `Random` instance, but use the one provided in the `RandomizedTest`, from which all Elasticsearch dependent test classes inherit from.
|
|
|
|
|
|
[horizontal]
|
|
|
`getRandom()`:: Returns the random instance, which can recreated when calling the test with specific parameters
|
|
@@ -221,7 +221,7 @@ If you want to debug a specific problem with a specific random seed, you can use
|
|
|
[[assertions]]
|
|
|
=== Assertions
|
|
|
|
|
|
-As many elasticsearch tests are checking for a similar output, like the amount of hits or the first hit or special highlighting, a couple of predefined assertions have been created. Those have been put into the `ElasticsearchAssertions` class. There is also a specific geo assertions in `ElasticsearchGeoAssertions`.
|
|
|
+As many Elasticsearch tests are checking for a similar output, like the amount of hits or the first hit or special highlighting, a couple of predefined assertions have been created. Those have been put into the `ElasticsearchAssertions` class. There is also a specific geo assertions in `ElasticsearchGeoAssertions`.
|
|
|
|
|
|
[horizontal]
|
|
|
`assertHitCount()`:: Checks hit count of a search or count request
|