Access to Netty4Plugin(transport-netty4) in custom plugins to run test codes with RestClient and ESIntegTestCase in version 8.0.0

Hello!

First of all, I'd like to say thank you for maintaining such great projects and communities. I'm big fan of Elasticsearch.

I wrote several custom plugins for Elasticsearch, and I have some test codes which use ESIntegTestCase.

As I know, getRestClient() in ESIntegTestCase use dummy MockHttpTransport for default, and cannot be used to perform actual REST actions for testing.

Therefore, I add Netty4Plugin module to the test codes like below,

// build.gradle
dependencies {
    testImplementation "org.elasticsearch.plugin:transport-netty4-client:7.17.0"
    // ...
}
// test code
public class HelloWorldIntegTests extends ESIntegTestCase() {
    @Override
    public Collection<Class<? extends Plugin>> nodePlugins() {
        return Arrays.asList(
            HelloWorldPlugin.class,
            Netty4Plugin.class
        );
    }

    @Override
    public Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
        final Settings defaultSettings = super.nodeSettings(nodeOrdinal, otherSettings);
        return Settings.builder()
            .put(defaultSettings)
            .put(NetworkModule.HTTP_TYPE_SETTING.key, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
            .put("my.settings", "my-settings-value")
            .build();
    }

    @Test
    public void testSomething() {
        final RestClient restClient = getRestClient();
        // do test with RestClient ...
    }
}

However, after 8.0 release, transport-netty4-client distribution has stopped. and I lose ways to access Netty4Plugin module in our plugin level. Is there any other proper ways to get actual working RestClient in the plugin test code level?

I tried javaRestTest and yamlRestTest with elasticsearch.java-rest-test and elasticsearch.yaml-rest-test plugins. It worked, but those were little bit complex for our small plugins and If possible, I want to resuse existing ESIntegTestCase codes in 8.0 too.

Thank you.

Hey,

while this does not solve the netty issue per se, have you considered using Testcontainers instead. For an example, see this blog post Using Testcontainers To Test Elasticsearch Plugins

This way you can install the plugin as part of testcontainers and basically ensure, that the plugin can also be installed correctly.

IIRC the netty4 transport has been moved to a module and is no more a plugin, thus it is packaged within the Elasticsearch distribution only.

Hope this helps!

--Alex

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