diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 70d83dc75ed7f..71b37d934ab56 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -697,10 +697,12 @@ public List> getContexts() { @Override public void close() throws IOException { - bulkProcessor.flush(); + if (enabled) { + bulkProcessor.flush(); + } IOUtils.closeWhileHandlingException(httpClient); try { - if (bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) { + if (enabled && bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) { logger.warn("failed to properly close watcher bulk processor"); } } catch (InterruptedException e) { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index f5aac53e452d5..02204f3158d89 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.watcher.notification.NotificationService; +import java.io.IOException; import java.util.Collections; import java.util.List; @@ -79,7 +80,7 @@ public void testThreadPoolSize() { assertThat(Watcher.getWatcherThreadPoolSize(noDataNodeSettings), is(1)); } - public void testWatcherDisabledTests() { + public void testWatcherDisabledTests() throws IOException { Settings settings = Settings.builder() .put("xpack.watcher.enabled", false) .put("path.home", createTempDir()) @@ -102,6 +103,8 @@ public void testWatcherDisabledTests() { // also no component creation if not enabled assertThat(watcher.createComponents(null, null, null, null, null, null, null, null, null), hasSize(0)); + + watcher.close(); } public void testReload() {