ES 5.1 and Local transport for embedded node

Hi

with ES 2.x we have made extensive use of an embedded node with local transport for unit and integration tests (not using the ESIntegTestCase but our own). With something like

masterNode = nodeBuilder().local(local).settings(settings.build()).node();

With the new ES 5.1.1 Java API, I was not immediately able to implement something similar. And also didn't find any reference to the local transport.

Does this feature still exist or should I use a regular Node with a TransportClient in my tests?

CU, Joe

To do integration tests, start a real external elasticsearch node and then use your real client, whatever it is.

With the warning that this feels like a bit of a hack, it does work. This is the way I do "integration" tests in one of my projects. I do have some issues with running the unit tests without doing a clean before the test start.

public abstract class ElasticTestCase {
    private static Node node = null;

    @BeforeClass
    public static void setupOnce() throws NodeValidationException {
        Settings settings = Settings.builder()
                .put("path.home", "target/elasticsearch")
                .put("transport.type", "local")
                .put("http.enabled", true)
                .build();

        Collection plugins = Collections.singletonList(Netty4Plugin.class);
        node = new PluginConfigurableNode(settings, plugins).start();
    }

    @AfterClass
    public static void teardownOnce() throws IOException {
        node.close();
    }

    private static class PluginConfigurableNode extends Node {
        PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
            super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins);
        }
    }
}

Hi Jettro

thanks, exactly what I was looking for! We already made our share of experiences with having to clean stuff before/after unit tests with ES2.

Thanks, I will give it a try and report how it goes

CU, Joe

Yep, that worked, thanks! Now I'm fighting a bit to get a decent logging setup during my tests. My stuff used slf4j/logback and the embedded Elastic server really insists on Log4j2 :slight_smile: But I'll get there

Thanks and CU, Joe

There is an slf4j-log4j2 library that you could use with the test dependency, that might work

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