I've written some monitoring stuff that I'd really like to be able to unit test.
To do this well, it requires me to be able to run up a multi-node cluster.
As far as I understand it, I can run up multiple nodes with the same cluster name, but they won't actually join into one cluster without some sort of discovery service running. Is that correct?
Can anyone point me to some docs on how to run up a multi-node cluster for unit testing (ie: how to run a discovery service as part of testing)?
Elasticsearch has a good testing framework that allows you to test your code against a testing cluster with random number of nodes. Have a look at ESIntegTestCase and classes that inherit from it. Note that this is used for integration tests, not unit tests.
Thanks for that! I did see that, but they are integration tests, so they make the client available to you. Can you still connect to the "fake" cluster using a transport client?
My monitoring code uses a TransportClient to connect and perform health checks is all...
If your test class extend ESIntegTestCase you can get a Client instance using the client()method. The client will be either a TransportClient or a node Client, this is randomized. Most of the time your custom code should work with a Client instance.
yes, in that case you need to know which port to connect to. Either you use the client() provided by ESIntegTestCase to find out what the port is, or you fix the port as part of the cluster setup, which can be done by overriding the method:
@Override
protected Settings nodeSettings(int nodeOrdinal) {
// add setting specifying transport port
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.