Http.enabled with ESIntegTestCase

I'm new to writing elastic search plugin and I am still getting through the basics. I'd like to be able to test and debug my plugin from IDE. I rely on breakpoints and tracing the code to figure out what is going on.

I just realized that with ESIntegTestCase the mock cluster is not bound to http. I prefer to be able to interact with the server from the browser. I understand that this practice has been continued for good reasons and is not the default anymore. However, I'm wondering if it is possible to have http enabled anyhow. Thanks.

Here is the class I have

public class BasicPluginIntegrationTest extends ESIntegTestCase {
	private Client client;

	@Override
	protected Collection<Class<? extends Plugin>> nodePlugins() {
		return Collections.singleton(BasicPlugin.class);
	}


	@Override
	protected Settings nodeSettings(int nodeOrdinal) {
		int randomPort = 9200; // randomIntBetween(49152, 65525);
		System.out.println("Hani " + NetworkModule.HTTP_ENABLED.getKey());
		Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal))
				.put(NetworkModule.HTTP_ENABLED.getKey(), true)
				.put(HttpTransportSettings.SETTING_HTTP_PORT.getKey(), randomPort).put("network.host", "127.0.0.1");
		Settings settings = builder.build();

		return settings;
	}

	
	@Test
	public void testLive() {
		System.out.println("Server live, hit enter to quit");
		(new Scanner(System.in)).nextLine();

	}

}

I am getting the following error

java.lang.IllegalStateException: Unsupported http.type []
	at org.elasticsearch.common.network.NetworkModule.getHttpServerTransportSupplier(NetworkModule.java:194)
	at org.elasticsearch.node.Node.<init>(Node.java:396)
	at org.elasticsearch.node.MockNode.<init>(MockNode.java:61)
	at org.elasticsearch.test.InternalTestCluster.buildNode(InternalTestCluster.java:616)
	at org.elasticsearch.test.InternalTestCluster.reset(InternalTestCluster.java:1048)
	at org.elasticsearch.test.InternalTestCluster.beforeTest(InternalTestCluster.java:986)
	at org.elasticsearch.test.ESIntegTestCase.beforeInternal(ESIntegTestCase.java:353)
	at org.elasticsearch.test.ESIntegTestCase.before(ESIntegTestCase.java:1989)
	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:497)
	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 o...

Enabling http requires having an http transport implementation. This is handled in elasticsearch in a module called transport-netty4, but modules are not added to the classpath of plugins. If you use the official gradle plugin for building your elasticsearch plugin, you automatically get a integTest task which you can write http based REST tests against, just like we test our official plugins.

I'm using Maven and I have netty4 as test task dependency. I guess the question is how to "run it" within the ESIntegTestCase. I got it to work by changing the BasicPlugin class to extend Netty4Plugin rather than Plugin, but then the plugin refused to work in the real Elasticsearch server, presumably because netty4 was already enabled.

		<dependency>
			<groupId>org.elasticsearch.plugin</groupId>
			<artifactId>transport-netty4-client</artifactId>
			<version>${elasticsearch.version}</version>
			<scope>test</scope>
		</dependency>

I just got it to work. It turns out I needed to have the two plugin in nodePlugins(). Thanks

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
	Collection<Class<? extends Plugin>> al = new ArrayList<Class<? extends Plugin>>();
	al.add(Netty4Plugin.class);
	al.add(BasicPlugin.class);
	return  al;
}

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