|
|
@@ -9,10 +9,14 @@ package org.elasticsearch.upgrades;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.Response;
|
|
|
+import org.elasticsearch.client.ResponseException;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.is;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
|
|
|
public class WatcherRestartIT extends AbstractUpgradeTestCase {
|
|
|
@@ -25,6 +29,34 @@ public class WatcherRestartIT extends AbstractUpgradeTestCase {
|
|
|
ensureWatcherStarted();
|
|
|
}
|
|
|
|
|
|
+ public void testEnsureWatcherDeletesLegacyTemplates() throws Exception {
|
|
|
+ client().performRequest(new Request("POST", "/_watcher/_start"));
|
|
|
+ ensureWatcherStarted();
|
|
|
+
|
|
|
+ if (CLUSTER_TYPE.equals(ClusterType.UPGRADED)) {
|
|
|
+ // legacy index template created in previous releases should not be present anymore
|
|
|
+ assertBusy(() -> {
|
|
|
+ Request request = new Request("GET", "/_template/*watch*");
|
|
|
+ try {
|
|
|
+ Response response = client().performRequest(request);
|
|
|
+ Map<String, Object> responseLevel = entityAsMap(response);
|
|
|
+ assertNotNull(responseLevel);
|
|
|
+
|
|
|
+ assertThat(responseLevel.containsKey(".watches"), is(false));
|
|
|
+ assertThat(responseLevel.containsKey(".triggered_watches"), is(false));
|
|
|
+ assertThat(responseLevel.containsKey(".watch-history-9"), is(false));
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ // Not found is fine
|
|
|
+ assertThat(
|
|
|
+ "Unexpected failure getting templates: " + e.getResponse().getStatusLine(),
|
|
|
+ e.getResponse().getStatusLine().getStatusCode(),
|
|
|
+ is(404)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void ensureWatcherStopped() throws Exception {
|
|
|
assertBusy(() -> {
|
|
|
Response stats = client().performRequest(new Request("GET", "_watcher/stats"));
|