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);
}
}
}