Discovery Service for Unit Testing?

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)?

Thanks for your help!

Hi,

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.

Yeah, that's not going to work for me. I want my monitoring code to be able to instantiate its own TransportClient and connect to the cluster.

Is that possible?

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
}

in your test class subclassing ESIntegTestCase