From 1e7f61b4c8f1ae210c7b7c424509d3c08a8ad1b0 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 20 Jun 2017 14:17:36 +0200 Subject: [PATCH] Tests: Ensure watcher index templates are installed in REST tests (elastic/x-pack-elasticsearch#1784) The current testing setup only checked if watcher was started, but it also needs to check for the index template in order to be sure that everything is set up correctly, before trying to put a watch. relates elastic/x-pack-elasticsearch#1762 Original commit: elastic/x-pack-elasticsearch@3ed78b15a1be457e7cc7cf6c68fbb6d2bb776cc1 --- .../watcher/support/WatcherIndexTemplateRegistry.java | 4 ++++ .../org/elasticsearch/xpack/test/rest/XPackRestIT.java | 2 ++ .../elasticsearch/smoketest/WatcherWithMustacheIT.java | 9 +++++++++ .../elasticsearch/smoketest/WatcherWithPainlessIT.java | 9 +++++++++ ...mokeTestWatcherWithSecurityClientYamlTestSuiteIT.java | 9 +++++++++ .../smoketest/SmokeTestWatcherClientYamlTestSuiteIT.java | 9 +++++++++ 6 files changed, 42 insertions(+) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java b/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java index 963c5e11dbb..4039d9171de 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java @@ -37,6 +37,10 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C public static final String TRIGGERED_TEMPLATE_NAME = ".triggered_watches"; public static final String WATCHES_TEMPLATE_NAME = ".watches"; + public static final String[] TEMPLATE_NAMES = new String[] { + HISTORY_TEMPLATE_NAME, TRIGGERED_TEMPLATE_NAME, WATCHES_TEMPLATE_NAME + }; + public static final TemplateConfig[] TEMPLATE_CONFIGS = new TemplateConfig[]{ new TemplateConfig(TRIGGERED_TEMPLATE_NAME, "triggered-watches"), new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch-history"), diff --git a/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java b/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java index 375a71d9756..b6285c93f9d 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java @@ -17,6 +17,7 @@ import org.elasticsearch.test.rest.yaml.ClientYamlTestResponseException; import org.elasticsearch.xpack.ml.MachineLearningTemplateRegistry; import org.elasticsearch.xpack.ml.integration.MlRestTestStateCleaner; import org.elasticsearch.xpack.security.SecurityLifecycleService; +import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.junit.After; import org.junit.Before; @@ -51,6 +52,7 @@ public class XPackRestIT extends XPackRestTestCase { List templates = new ArrayList<>(); templates.add(SecurityLifecycleService.SECURITY_TEMPLATE_NAME); templates.addAll(Arrays.asList(MachineLearningTemplateRegistry.TEMPLATE_NAMES)); + templates.addAll(Arrays.asList(WatcherIndexTemplateRegistry.TEMPLATE_NAMES)); for (String template : templates) { awaitCallApi("indices.exists_template", singletonMap("name", template), emptyList(), diff --git a/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherWithMustacheIT.java b/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherWithMustacheIT.java index 09ce8eeb2a9..60e7401ae07 100644 --- a/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherWithMustacheIT.java +++ b/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherWithMustacheIT.java @@ -10,6 +10,7 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.junit.After; import org.junit.Before; @@ -17,6 +18,7 @@ import java.io.IOException; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.is; /** Runs rest tests against external cluster */ @@ -36,6 +38,13 @@ public class WatcherWithMustacheIT extends ESClientYamlSuiteTestCase { assertBusy(() -> { try { getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap()); + + for (String template : WatcherIndexTemplateRegistry.TEMPLATE_NAMES) { + ClientYamlTestResponse templateExistsResponse = getAdminExecutionContext().callApi("indices.exists_template", + singletonMap("name", template), emptyList(), emptyMap()); + assertThat(templateExistsResponse.getStatusCode(), is(200)); + } + ClientYamlTestResponse response = getAdminExecutionContext().callApi("xpack.watcher.stats", emptyMap(), emptyList(), emptyMap()); String state = (String) response.evaluate("stats.0.watcher_state"); diff --git a/qa/smoke-test-watcher-with-painless/src/test/java/org/elasticsearch/smoketest/WatcherWithPainlessIT.java b/qa/smoke-test-watcher-with-painless/src/test/java/org/elasticsearch/smoketest/WatcherWithPainlessIT.java index d6eaf543000..605ac8b343f 100644 --- a/qa/smoke-test-watcher-with-painless/src/test/java/org/elasticsearch/smoketest/WatcherWithPainlessIT.java +++ b/qa/smoke-test-watcher-with-painless/src/test/java/org/elasticsearch/smoketest/WatcherWithPainlessIT.java @@ -9,6 +9,7 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.junit.After; import org.junit.Before; @@ -16,6 +17,7 @@ import java.io.IOException; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.is; /** Runs rest tests against external cluster */ @@ -35,6 +37,13 @@ public class WatcherWithPainlessIT extends ESClientYamlSuiteTestCase { assertBusy(() -> { try { getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap()); + + for (String template : WatcherIndexTemplateRegistry.TEMPLATE_NAMES) { + ClientYamlTestResponse templateExistsResponse = getAdminExecutionContext().callApi("indices.exists_template", + singletonMap("name", template), emptyList(), emptyMap()); + assertThat(templateExistsResponse.getStatusCode(), is(200)); + } + ClientYamlTestResponse response = getAdminExecutionContext().callApi("xpack.watcher.stats", emptyMap(), emptyList(), emptyMap()); String state = (String) response.evaluate("stats.0.watcher_state"); diff --git a/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java b/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java index 43d1f693c11..c655fac5e20 100644 --- a/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java +++ b/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.junit.After; import org.junit.Before; @@ -20,6 +21,7 @@ import java.io.IOException; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.is; @@ -42,6 +44,13 @@ public class SmokeTestWatcherWithSecurityClientYamlTestSuiteIT extends ESClientY assertBusy(() -> { try { getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap()); + + for (String template : WatcherIndexTemplateRegistry.TEMPLATE_NAMES) { + ClientYamlTestResponse templateExistsResponse = getAdminExecutionContext().callApi("indices.exists_template", + singletonMap("name", template), emptyList(), emptyMap()); + assertThat(templateExistsResponse.getStatusCode(), is(200)); + } + ClientYamlTestResponse response = getAdminExecutionContext().callApi("xpack.watcher.stats", emptyMap(), emptyList(), emptyMap()); String state = (String) response.evaluate("stats.0.watcher_state"); diff --git a/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherClientYamlTestSuiteIT.java b/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherClientYamlTestSuiteIT.java index 7ab4eb2770c..0b7bcd68bbd 100644 --- a/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherClientYamlTestSuiteIT.java +++ b/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherClientYamlTestSuiteIT.java @@ -11,6 +11,7 @@ import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.junit.After; import org.junit.Before; @@ -18,6 +19,7 @@ import java.io.IOException; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.is; /** Runs rest tests against external cluster */ @@ -38,6 +40,13 @@ public class SmokeTestWatcherClientYamlTestSuiteIT extends ESClientYamlSuiteTest assertBusy(() -> { try { getAdminExecutionContext().callApi("xpack.watcher.start", emptyMap(), emptyList(), emptyMap()); + + for (String template : WatcherIndexTemplateRegistry.TEMPLATE_NAMES) { + ClientYamlTestResponse templateExistsResponse = getAdminExecutionContext().callApi("indices.exists_template", + singletonMap("name", template), emptyList(), emptyMap()); + assertThat(templateExistsResponse.getStatusCode(), is(200)); + } + ClientYamlTestResponse response = getAdminExecutionContext().callApi("xpack.watcher.stats", emptyMap(), emptyList(), emptyMap()); String state = (String) response.evaluate("stats.0.watcher_state");