Hello,
I have written some integration tests for my project which uses ElasticSearch as database.
I was using Rest High Level Client with ElasticSearch version 6.6.0. But recently I upgraded the version to 7.0.0. Now, my Integration tests are failing to connect with ElasticSearch on Rest High Level Client. Earlier with 6.6.0, I was using org.elasticsearch.common.network.NetworkModule.HTTP_ENABLED
setting to enable HTTP. But now it's deprecated and somehow the HTTP is not getting enabled. It seems nodes created by ESIntegTestCase do not have HTTP enabled by default.
Error
java.net.ConnectException: Timeout connecting to [/0.0.0.0:80]
pom.xml
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.test</groupId>
<artifactId>framework</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
Test class
package com.rp;
import com.carrotsearch.randomizedtesting.RandomizedRunner;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.transport.Netty4Plugin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import static com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope.NONE;
@ThreadLeakScope(NONE)
@ClusterScope(numDataNodes = 1)
@RunWith(RandomizedRunner.class)
public class CommonUtilTests extends ESIntegTestCase {
private RestHighLevelClient esClient;
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.build();
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
final Collection<Class<? extends Plugin>> plugins = new ArrayList<>();
plugins.add(Netty4Plugin.class);
return plugins;
}
@Before
public void initialize() {
esClient = new RestHighLevelClient(RestClient.builder(getRestClient().getNodes().get(0)));
}
@Test
public void test_createIndex() throws IOException {
Boolean isCreated = CommonUtil.createIndex(esClient, "my-index");
assertTrue(isCreated);
assertTrue(indexExists("my-index"));
}
}
How can I get RestHighLevelClient in ESIntegTestCase?