Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add rolling upgrade tests for watcher #32428

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.upgrades;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;

import java.nio.charset.StandardCharsets;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

public class WatcherRestartIT extends AbstractUpgradeTestCase {

public void testWatcherRestart() throws Exception {
client().performRequest(new Request("POST", "/_xpack/watcher/_stop"));
ensureWatcherStopped();

client().performRequest(new Request("POST", "/_xpack/watcher/_start"));
ensureWatcherStarted();
}

private void ensureWatcherStopped() throws Exception {
assertBusy(() -> {
Response stats = client().performRequest(new Request("GET", "_xpack/watcher/stats"));
String responseBody = EntityUtils.toString(stats.getEntity(), StandardCharsets.UTF_8);
assertThat(responseBody, containsString("\"watcher_state\":\"stopped\""));
assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"started\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
});
}

private void ensureWatcherStarted() throws Exception {
assertBusy(() -> {
Response response = client().performRequest(new Request("GET", "_xpack/watcher/stats"));
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
assertThat(responseBody, containsString("\"watcher_state\":\"started\""));
assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\"")));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
"CRUD watch APIs":

# no need to put watch, exists already
- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }


# execute watch
- do:
xpack.watcher.execute_watch:
id: "my_watch"
- match: { watch_record.watch_id: "my_watch" }
- match: { watch_record.trigger_event.type: "manual" }
- match: { watch_record.state: "executed" }
- match: { watch_record.status.execution_state: "executed" }
- match: { watch_record.status.state.active: true }

# deactivate watch, check with GET API as well
- do:
xpack.watcher.deactivate_watch:
watch_id: "my_watch"
- match: { status.state.active : false }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: false }


# activate watch again, check with GET API as well
- do:
xpack.watcher.activate_watch:
watch_id: "my_watch"
- match: { status.state.active : true }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: true }


---
"Test watcher stats output":
- do:
xpack.watcher.stats: {}
- match: { "manually_stopped": false }
- match: { "stats.0.watcher_state": "started" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
"CRUD watch APIs":

- do:
xpack.watcher.put_watch:
id: "my_watch"
body: >
{
"trigger": {
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
},
"input": {
"simple": {}
},
"actions": {
"logging": {
"logging": {
"text": "my logging action"
}
}
}
}
- match: { _id: "my_watch" }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }


# execute watch
- do:
xpack.watcher.execute_watch:
id: "my_watch"
- match: { watch_record.watch_id: "my_watch" }
- match: { watch_record.trigger_event.type: "manual" }
- match: { watch_record.state: "executed" }
- match: { watch_record.status.execution_state: "executed" }
- match: { watch_record.status.state.active: true }

# deactivate watch, check with GET API as well
- do:
xpack.watcher.deactivate_watch:
watch_id: "my_watch"
- match: { status.state.active : false }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: false }


# activate watch again, check with GET API as well
- do:
xpack.watcher.activate_watch:
watch_id: "my_watch"
- match: { status.state.active : true }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: true }


---
"Test watcher stats output":
- do:
xpack.watcher.stats: {}
- match: { "manually_stopped": false }
- match: { "stats.0.watcher_state": "started" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
"CRUD watch APIs":

# no need to put watch, exists already
- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }


# execute watch
- do:
xpack.watcher.execute_watch:
id: "my_watch"
- match: { watch_record.watch_id: "my_watch" }
- match: { watch_record.trigger_event.type: "manual" }
- match: { watch_record.state: "executed" }
- match: { watch_record.status.execution_state: "executed" }
- match: { watch_record.status.state.active: true }

# deactivate watch, check with GET API as well
- do:
xpack.watcher.deactivate_watch:
watch_id: "my_watch"
- match: { status.state.active : false }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: false }


# activate watch again, check with GET API as well
- do:
xpack.watcher.activate_watch:
watch_id: "my_watch"
- match: { status.state.active : true }

- do:
xpack.watcher.get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }
- match: { status.state.active: true }

---
"Test watcher stats output":
- do:
xpack.watcher.stats: {}
- match: { "manually_stopped": false }
- match: { "stats.0.watcher_state": "started" }