we have been using Elasticsearch in our project. For testing our code we use ElasticsearchIntegrationTest class. Within our business code we close the client connection.
It seems like Elasticsearch testing library closes node on every test case completion. Since we already close the client in our business code, getting org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
is there a way to skip the closing of nodes by the test library ?
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class PerkesoImporterTest extends ElasticsearchIntegrationTest{
@Test
public void createIndex() throws Exception {
csvImporter.client = internalCluster().client();
boolean isIndexCreated = csvImporter.createIndex();//at the end of this function we close the connection
assertTrue(isIndexCreated);
logger.info("createIndex : index is created ");
}
}
The simplest way to use the superclass properly is probably to wrap the client that you give to the csvImporter with one that just sets a bool to true instead of closes the client. You can probably do it with FilterClient. Then assert that the importer tried to close the client.
The point of that superclass is that it manages the cluster for you. If you want something that doesn't manage the cluster for you I'd just use a regular test run during some integration test phase that has already started elasticsearch. It is more real but much more effort. If you happen to build your project with maven you can look at how Elasticsearch does this in its 2.x branch. If you happen to build with gradle you can look at the elasticsearch master branch.
I tried with the following, still get the same exception. Works only is i comment client.close() from my business method. So closing the client happens in two places, one at my business code and one by the test library after test case completes. That's why i asked, is there a way to skip the closing of the clients by the test library?
public CustomClient extends FilterClient {
CustomClient (Client in) {
super(in);
}
}
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class PerkesoImporterTest extends ElasticsearchIntegrationTest{
@Test
public void createIndex() throws Exception {
csvImporter.client = new CustomClient(client());
boolean isIndexCreated = csvImporter.createIndex();//at the end of this function we close the connection
assertTrue(isIndexCreated);
logger.info("createIndex : index is created ");
}
}
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.