Skip to content

Commit f809d6f

Browse files
authored
Tests: Add rolling upgrade tests for watcher (#32428)
These tests ensure, that the basic watch APIs are tested in the rolling upgrade tests. After initially adding a watch, the tests try to get, execute, deactivate and activate a watch. Watcher stats are tested as well, and an own java based test has been added for restarting, as that requires waiting for a state change. Watcher history is also checked. Closes #31216
1 parent 0d60e8a commit f809d6f

File tree

4 files changed

+289
-0
lines changed

4 files changed

+289
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.upgrades;
7+
8+
import org.apache.http.util.EntityUtils;
9+
import org.elasticsearch.client.Request;
10+
import org.elasticsearch.client.Response;
11+
12+
import java.nio.charset.StandardCharsets;
13+
14+
import static org.hamcrest.Matchers.containsString;
15+
import static org.hamcrest.Matchers.not;
16+
17+
public class WatcherRestartIT extends AbstractUpgradeTestCase {
18+
19+
public void testWatcherRestart() throws Exception {
20+
client().performRequest(new Request("POST", "/_xpack/watcher/_stop"));
21+
ensureWatcherStopped();
22+
23+
client().performRequest(new Request("POST", "/_xpack/watcher/_start"));
24+
ensureWatcherStarted();
25+
}
26+
27+
private void ensureWatcherStopped() throws Exception {
28+
assertBusy(() -> {
29+
Response stats = client().performRequest(new Request("GET", "_xpack/watcher/stats"));
30+
String responseBody = EntityUtils.toString(stats.getEntity(), StandardCharsets.UTF_8);
31+
assertThat(responseBody, containsString("\"watcher_state\":\"stopped\""));
32+
assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\"")));
33+
assertThat(responseBody, not(containsString("\"watcher_state\":\"started\"")));
34+
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
35+
});
36+
}
37+
38+
private void ensureWatcherStarted() throws Exception {
39+
assertBusy(() -> {
40+
Response response = client().performRequest(new Request("GET", "_xpack/watcher/stats"));
41+
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
42+
assertThat(responseBody, containsString("\"watcher_state\":\"started\""));
43+
assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\"")));
44+
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
45+
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\"")));
46+
});
47+
}
48+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
"CRUD watch APIs":
3+
4+
# no need to put watch, exists already
5+
- do:
6+
xpack.watcher.get_watch:
7+
id: "my_watch"
8+
- match: { found : true}
9+
- match: { _id: "my_watch" }
10+
11+
12+
# execute watch
13+
- do:
14+
xpack.watcher.execute_watch:
15+
id: "my_watch"
16+
body: >
17+
{
18+
"record_execution" : true
19+
}
20+
- set: { _id : record_id }
21+
- match: { watch_record.watch_id: "my_watch" }
22+
- match: { watch_record.trigger_event.type: "manual" }
23+
- match: { watch_record.state: "executed" }
24+
- match: { watch_record.status.execution_state: "executed" }
25+
- match: { watch_record.status.state.active: true }
26+
27+
# check watch history entry
28+
- do:
29+
indices.refresh:
30+
index: .watcher-history-*
31+
32+
- do:
33+
search:
34+
index: .watcher-history-*
35+
body:
36+
{
37+
"query" : { "term" : { "_id" : "$record_id" } }
38+
}
39+
- match: { hits.total: 1 }
40+
41+
# deactivate watch, check with GET API as well
42+
- do:
43+
xpack.watcher.deactivate_watch:
44+
watch_id: "my_watch"
45+
- match: { status.state.active : false }
46+
47+
- do:
48+
xpack.watcher.get_watch:
49+
id: "my_watch"
50+
- match: { found : true}
51+
- match: { _id: "my_watch" }
52+
- match: { status.state.active: false }
53+
54+
55+
# activate watch again, check with GET API as well
56+
- do:
57+
xpack.watcher.activate_watch:
58+
watch_id: "my_watch"
59+
- match: { status.state.active : true }
60+
61+
- do:
62+
xpack.watcher.get_watch:
63+
id: "my_watch"
64+
- match: { found : true}
65+
- match: { _id: "my_watch" }
66+
- match: { status.state.active: true }
67+
68+
69+
---
70+
"Test watcher stats output":
71+
- do:
72+
xpack.watcher.stats: {}
73+
- match: { "manually_stopped": false }
74+
- match: { "stats.0.watcher_state": "started" }
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
"CRUD watch APIs":
3+
4+
- do:
5+
xpack.watcher.put_watch:
6+
id: "my_watch"
7+
body: >
8+
{
9+
"trigger": {
10+
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
11+
},
12+
"input": {
13+
"simple": {}
14+
},
15+
"actions": {
16+
"logging": {
17+
"logging": {
18+
"text": "my logging action"
19+
}
20+
}
21+
}
22+
}
23+
- match: { _id: "my_watch" }
24+
25+
- do:
26+
xpack.watcher.get_watch:
27+
id: "my_watch"
28+
- match: { found : true}
29+
- match: { _id: "my_watch" }
30+
31+
32+
# execute watch
33+
- do:
34+
xpack.watcher.execute_watch:
35+
id: "my_watch"
36+
body: >
37+
{
38+
"record_execution" : true
39+
}
40+
- set: { _id : record_id }
41+
- match: { watch_record.watch_id: "my_watch" }
42+
- match: { watch_record.trigger_event.type: "manual" }
43+
- match: { watch_record.state: "executed" }
44+
- match: { watch_record.status.execution_state: "executed" }
45+
- match: { watch_record.status.state.active: true }
46+
47+
# check watch history entry
48+
- do:
49+
indices.refresh:
50+
index: .watcher-history-*
51+
52+
- do:
53+
search:
54+
index: .watcher-history-*
55+
body:
56+
{
57+
"query" : { "term" : { "_id" : "$record_id" } }
58+
}
59+
- match: { hits.total: 1 }
60+
61+
# deactivate watch, check with GET API as well
62+
- do:
63+
xpack.watcher.deactivate_watch:
64+
watch_id: "my_watch"
65+
- match: { status.state.active : false }
66+
67+
- do:
68+
xpack.watcher.get_watch:
69+
id: "my_watch"
70+
- match: { found : true}
71+
- match: { _id: "my_watch" }
72+
- match: { status.state.active: false }
73+
74+
75+
# activate watch again, check with GET API as well
76+
- do:
77+
xpack.watcher.activate_watch:
78+
watch_id: "my_watch"
79+
- match: { status.state.active : true }
80+
81+
- do:
82+
xpack.watcher.get_watch:
83+
id: "my_watch"
84+
- match: { found : true}
85+
- match: { _id: "my_watch" }
86+
- match: { status.state.active: true }
87+
88+
89+
---
90+
"Test watcher stats output":
91+
- do:
92+
xpack.watcher.stats: {}
93+
- match: { "manually_stopped": false }
94+
- match: { "stats.0.watcher_state": "started" }
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
"CRUD watch APIs":
3+
4+
# no need to put watch, exists already
5+
- do:
6+
xpack.watcher.get_watch:
7+
id: "my_watch"
8+
- match: { found : true}
9+
- match: { _id: "my_watch" }
10+
11+
12+
# execute watch
13+
- do:
14+
xpack.watcher.execute_watch:
15+
id: "my_watch"
16+
body: >
17+
{
18+
"record_execution" : true
19+
}
20+
- set: { _id : record_id }
21+
- match: { watch_record.watch_id: "my_watch" }
22+
- match: { watch_record.trigger_event.type: "manual" }
23+
- match: { watch_record.state: "executed" }
24+
- match: { watch_record.status.execution_state: "executed" }
25+
- match: { watch_record.status.state.active: true }
26+
27+
# check watch history entry
28+
- do:
29+
indices.refresh:
30+
index: .watcher-history-*
31+
32+
- do:
33+
search:
34+
index: .watcher-history-*
35+
body:
36+
{
37+
"query" : { "term" : { "_id" : "$record_id" } }
38+
}
39+
- match: { hits.total: 1 }
40+
41+
# deactivate watch, check with GET API as well
42+
- do:
43+
xpack.watcher.deactivate_watch:
44+
watch_id: "my_watch"
45+
- match: { status.state.active : false }
46+
47+
- do:
48+
xpack.watcher.get_watch:
49+
id: "my_watch"
50+
- match: { found : true}
51+
- match: { _id: "my_watch" }
52+
- match: { status.state.active: false }
53+
54+
55+
# activate watch again, check with GET API as well
56+
- do:
57+
xpack.watcher.activate_watch:
58+
watch_id: "my_watch"
59+
- match: { status.state.active : true }
60+
61+
- do:
62+
xpack.watcher.get_watch:
63+
id: "my_watch"
64+
- match: { found : true}
65+
- match: { _id: "my_watch" }
66+
- match: { status.state.active: true }
67+
68+
---
69+
"Test watcher stats output":
70+
- do:
71+
xpack.watcher.stats: {}
72+
- match: { "manually_stopped": false }
73+
- match: { "stats.0.watcher_state": "started" }

0 commit comments

Comments
 (0)