Elastic search – Testing - elasticsearch - elasticsearch tutorial - elastic search
Elasticsearch Testing
- Elastic search gives a jug document, which can be added to any java IDE and can be utilized to test the code which is identified with Elastic search.
- A scope of tests can be performed by utilizing the system given by Elastic search
- Unit testing
- Integration testing
- Randomized testing
- To start with testing, you need to add the Elastic search testing dependency to your program. You can use maven for this purpose and can add the following in pom.xml.
learn elasticsearch tutorials - elasticsearch-testing-load-testing-endurance-testing-performance-testing Example
- EsSetup has been initialized to start and stop Elastic search node and also to create indices.
- EsSetup esSetup = new EsSetup();
- esSetup.execute() function with createIndex will create the indices, you need to specify the settings, type and data.
Unit Testing:
- Unit test is carried out by using J Unit and Elastic search test framework. Node and indices can be created using Elastic search classes and in test method can be used to perform the testing. ES Test Case and ES Token Stream Test Case classes are used for this testing.
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Integration Testing:
- Integration testing uses multiple nodes in a cluster. ES IntegTestCase class is used for this testing. There are various methods which make the job of preparing a test case easier.
Sr.No | Method & Description |
---|---|
1 | refresh() All the indices in a cluster are refreshed |
2 | ensureGreen() Ensures a green health cluster state |
3 | ensureYellow() Ensures a yellow health cluster state |
4 | createIndex(name) Create index with the name passed to this method |
5 | flush() All indices in cluster are flushed |
6 | flushAndRefresh() flush() and refresh() |
7 | indexExists(name) Verifies the existence of specified index |
8 | clusterService() Returns the cluster service java class |
9 | cluster() Returns the test cluster class |
Test Cluster Methods:
Sr.No | Method & Description |
---|---|
1 |
ensureAtLeastNumNodes(n) Ensures minimum number of nodes up in a cluster is more than or equal to specified number. |
2 |
ensureAtMostNumNodes(n) Ensures maximum number of nodes up in a cluster is less than or equal to specified number. |
3 |
stopRandomNode() To stop a random node in a cluster |
4 |
stopCurrentMasterNode() To stop the master node |
5 |
stopRandomNonMaster() To stop a random node in a cluster, which is not a master node |
6 |
buildNode() Create a new node |
7 |
startNode(settings) Start a new node |
8 |
nodeSettings() Override this method for changing node settings |
Accessing Clients:
- Client is used to access different nodes in a cluster and carry out some action.
- ES IntegTestCase.client() method is used for getting a random client. Elastic search offers other methods also to access client and those methods can be accessed using ESIntegTestCase.internalCluster() method.
Sr.No | Method & Description |
---|---|
1 | iterator() This helps you to access all the available clients. |
2 | masterClient() This returns a client, which is communicating with master node. |
3 | nonMasterClient() This returns a client, which is not communicating with master node. |
4 | clientNodeClient() This returns a client currently up on client node. |
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Randomized Testing:
- This testing is used to test the user’s code with every possible data, so that there will be no failure in future with any type of data. Random data is the best option to carry out this testing.
Generating Random Data:
- In this testing, the Random class is instantiated by the instance provided by Randomized Test and offers many methods for getting different types of data.
Method | Return value |
---|---|
getRandom() | Instance of random class |
randomBoolean() | Random boolean |
randomByte() | Random byte |
randomShort() | Random short |
randomInt() | Random integer |
randomLong() | Random long |
randomFloat() | Random float |
randomDouble() | Random double |
randomLocale() | Random locale |
randomTimeZone() | Random time zone |
randomFrom() | Random element from array |
Assertions:
- Elastic search Assertions and Elastic search Geo Assertions classes contain assertions, which are used for performing some common checks at the time of testing. For example,