Add plugins from classpath in embedded Elasticsearch client node

I'm unsure if this would help, but here is what I'm doing in tests.

Create a MockNode class:

public class MockNode extends Node {

    // these are kept here so a copy of this MockNode can be created, since Node does not store them
    private Version version;
    private Collection<Class<? extends Plugin>> plugins;

    public MockNode(Settings settings, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
        super(settings, version, classpathPlugins);
        this.version = version;
        this.plugins = classpathPlugins;
    }

    public Collection<Class<? extends Plugin>> getPlugins() {
        return plugins;
    }

    public Version getVersion() {
        return version;
    }
}

Then starts a Node this way:

    public static void main(String[] args) throws Throwable {
        Settings.Builder settings = Settings.builder().build();
        final CountDownLatch latch = new CountDownLatch(1);
        final Node node = new MockNode(settings.build(), Version.CURRENT, Collections.singletonList(MyClassPlugin.class));
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                node.close();
                latch.countDown();
            }
        });
        node.start();
        latch.await();
    }

Does this help?

2 Likes