Help with ESIntegTestCase

So I have Developed a Security plugin and wish to test it using a cluster started via ESIntegTestCase. But whenever I call "getRestClient()" from within my class, I get :-

Throwable #1: java.lang.IllegalArgumentException: no hosts provided
at __randomizedtesting.SeedInfo.seed([794D93C46E1791F4:37B4693F7BCC51CE]:0)
at org.elasticsearch.client.RestClientBuilder.(RestClientBuilder.java:67)
at org.elasticsearch.client.RestClient.builder(RestClient.java:117)

Perhaps there is not Data node present? I've seen that it never gets inside
if (node.getHttp() != null) {

I assume I'm configure it wrong? I'm using :-
@ESIntegTestCase.ClusterScope(scope=ESIntegTestCase.Scope.SUITE, numDataNodes=3)
public class AuthenticatePluginIntegrationTest extends ESIntegTestCase {
Can somebody guide me?

Nodes created by ESIntegTestCase do not have http enabled by default. You will need to override the node settings and set that. See nodeSettings(int nodeOrdinal) method on ESIntegTestCase, and the http.enabled setting. However, a much better method of doing these types of tests is to stand up a real ES cluster (even if single node). If you use the provided ES gradle plugin, this is done automatically for you with the integTest task. If you use maven, see this blog post from last year on how to accomplish this.

1 Like

Setting http.enabled to true leads to this error : (Even If i don't call for REST Client)

Throwable #1: java.lang.IllegalStateException: Unsupported http.type
at org.elasticsearch.common.network.NetworkModule.getHttpServerTransportSupplier(NetworkModule.java:195)
at org.elasticsearch.node.Node.(Node.java:429)
at org.elasticsearch.node.MockNode.(MockNode.java:60)
at org.elasticsearch.test.InternalTestCluster.buildNode(InternalTestCluster.java:622)
at org.elasticsearch.test.InternalTestCluster.reset(InternalTestCluster.java:1044)
at org.elasticsearch.test.InternalTestCluster.beforeTest(InternalTestCluster.java:992)
at org.elasticsearch.test.ESIntegTestCase.beforeInternal(ESIntegTestCase.java:367)
at org.elasticsearch.test.ESIntegTestCase.setupTestCluster(ESIntegTestCase.java:2037)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1713)
at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:941)
at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:957)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:49)
at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
at org.apache.lucene.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:48)
at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:368)
at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:817)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:468)
at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:916)
at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:802)
at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:852)
at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:863)
at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:41)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
at org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:54)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:368)
at java.lang.Thread.run(Thread.java:748)

Out of curiosity, why is there a getRestClient() if http is not enabled by default?
On top of it, in TransportClient:

Client client = client().filterWithHeader(Collections.singletonMap("Authorization", "Basic " +
        "Base64 Of username:password" ));
//Then using this new client variable to make calls.

OR

client().threadPool().getThreadContext().putHeader("Authorization",
    "Basic " + "Base64 Of username:password" );

Is Having no effect whatsoever, any idea?

You don't have any http transport implementations. In ES, this is provided by the netty4 module. However, this is not available in tests. You will need to choose and set an implementation. You can call getTestTransportType() to get a randomized implementation (which chooses between the test nio implementation or a mock tcp implementation).

Sorry to bother you again, do you have any idea why channelType in TransportChannel is 'local' for client() ? Can this be changed somehow?
Doesn't ESIntegTestCase calls getTestTransportType()? https://github.com/elastic/elasticsearch/blob/master/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java#L1823
Btw it only exists from 6.x, I'm using 5.4 and 5.6.

For 5.x, see the reindex module for an example of how to enable http. I believe you will need to add a test dependency on the netty4 module.

Could you provide me with some reference/source for ES gradle plugin? I'm unable to get it to work [Gradle Project].

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.