13
13
import org .elasticsearch .common .settings .Settings ;
14
14
import org .elasticsearch .common .util .concurrent .ThreadContext ;
15
15
import org .elasticsearch .common .xcontent .XContentBuilder ;
16
+ import org .elasticsearch .common .xcontent .XContentType ;
16
17
import org .elasticsearch .test .rest .ESRestTestCase ;
17
18
import org .elasticsearch .test .rest .yaml .ObjectPath ;
18
19
import org .elasticsearch .xpack .test .rest .XPackRestTestConstants ;
@@ -109,9 +110,8 @@ protected Settings restAdminSettings() {
109
110
return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).build ();
110
111
}
111
112
112
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/32299" )
113
113
public void testMonitorClusterHealth () throws Exception {
114
- String watchId = "cluster_health_watch" ;
114
+ final String watchId = "cluster_health_watch" ;
115
115
116
116
// get master publish address
117
117
Response clusterStateResponse = adminClient ().performRequest (new Request ("GET" , "/_cluster/state" ));
@@ -157,8 +157,9 @@ public void testMonitorClusterHealth() throws Exception {
157
157
158
158
// check watch history
159
159
ObjectPath objectPath = getWatchHistoryEntry (watchId );
160
- boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
161
- assertThat (conditionMet , is (true ));
160
+ Boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
161
+ String historyEntriesAsString = Strings .toString (objectPath .toXContentBuilder (XContentType .JSON .xContent ()));
162
+ assertThat ("condition not met in response [" + historyEntriesAsString + "]" , conditionMet , is (true ));
162
163
163
164
deleteWatch (watchId );
164
165
// Wrap inside an assertBusy(...), because watch may execute just after being deleted,
@@ -193,19 +194,51 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
193
194
try {
194
195
client ().performRequest (new Request ("POST" , "/.watcher-history-*/_refresh" ));
195
196
} catch (ResponseException e ) {
196
- final String err = "Failed to perform refresh of watcher history - " + e ;
197
- logger .info (err );
198
- fail (err );
197
+ final String err = "Failed to perform refresh of watcher history" ;
198
+ logger .error (err , e );
199
+ throw new AssertionError (err , e );
199
200
}
200
201
201
202
try (XContentBuilder builder = jsonBuilder ()) {
202
203
builder .startObject ();
203
- builder .startObject ("query" ).startObject ("bool" ).startArray ("must" );
204
- builder .startObject ().startObject ("term" ).startObject ("watch_id" ).field ("value" , watchId ).endObject ().endObject ()
205
- .endObject ();
206
- builder .endArray ().endObject ().endObject ();
207
- builder .startArray ("sort" ).startObject ().startObject ("trigger_event.triggered_time" ).field ("order" , "desc" ).endObject ()
208
- .endObject ().endArray ();
204
+ {
205
+ builder .startObject ("query" );
206
+ {
207
+ builder .startObject ("bool" );
208
+ builder .startArray ("must" );
209
+ builder .startObject ();
210
+ {
211
+ builder .startObject ("term" );
212
+ builder .startObject ("watch_id" );
213
+ builder .field ("value" , watchId );
214
+ builder .endObject ();
215
+ builder .endObject ();
216
+ }
217
+ builder .endObject ();
218
+ builder .startObject ();
219
+ {
220
+ builder .startObject ("term" );
221
+ builder .startObject ("state" );
222
+ builder .field ("value" , "executed" );
223
+ builder .endObject ();
224
+ builder .endObject ();
225
+ }
226
+ builder .endObject ();
227
+ builder .endArray ();
228
+ builder .endObject ();
229
+ }
230
+ builder .endObject ();
231
+ builder .startArray ("sort" );
232
+ builder .startObject ();
233
+ {
234
+
235
+ builder .startObject ("result.execution_time" );
236
+ builder .field ("order" , "desc" );
237
+ builder .endObject ();
238
+ }
239
+ builder .endObject ();
240
+ builder .endArray ();
241
+ }
209
242
builder .endObject ();
210
243
211
244
logger .info ("Searching watcher history" );
@@ -223,8 +256,8 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
223
256
objectPathReference .set (objectPath );
224
257
} catch (ResponseException e ) {
225
258
final String err = "Failed to perform search of watcher history" ;
226
- logger .info (err , e );
227
- fail (err );
259
+ logger .error (err , e );
260
+ throw new AssertionError (err , e );
228
261
}
229
262
});
230
263
return objectPathReference .get ();
0 commit comments