Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Jan 23, 2025
1 parent cc6fbe7 commit b59d17f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;

import java.util.Arrays;
import java.util.Map;

import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
Expand Down Expand Up @@ -56,14 +57,15 @@ public void testHistoryOnRejection() throws Exception {
flushAndRefresh(".watcher-history-*");
assertResponse(prepareSearch(".watcher-history-*"), searchResponse -> {
assertThat("Watcher history not found", searchResponse.getHits().getTotalHits().value(), greaterThanOrEqualTo(2L));

assertThat(
"Did not find watcher history for rejected watch",
Arrays.stream(searchResponse.getHits().getHits())
.anyMatch(
hit -> hit.getSourceAsMap() != null
&& hit.getSourceAsMap().get("messages") != null
&& hit.getSourceAsMap().get("messages").toString().contains("due to thread pool capacity")
),
Arrays.stream(searchResponse.getHits().getHits()).anyMatch(hit -> {
Map<String, Object> source = hit.getSourceAsMap();
return source != null
&& source.get("messages") != null
&& source.get("messages").toString().contains("due to thread pool capacity");
}),
equalTo(true)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ public void testScriptTransform() throws Exception {

assertNoFailuresAndResponse(prepareSearch("output1"), response -> {
assertThat(response.getHits().getTotalHits().value(), greaterThanOrEqualTo(1L));
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key3").toString(), equalTo("20"));
Map<String, Object> source = response.getHits().getAt(0).getSourceAsMap();
assertThat(source.size(), equalTo(1));
assertThat(source.get("key3").toString(), equalTo("20"));
});

assertNoFailuresAndResponse(prepareSearch("output2"), response -> {
assertThat(response.getHits().getTotalHits().value(), greaterThanOrEqualTo(1L));
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key3").toString(), equalTo("20"));
Map<String, Object> source = response.getHits().getAt(0).getSourceAsMap();
assertThat(source.size(), equalTo(1));
assertThat(source.get("key3").toString(), equalTo("20"));
});
}

Expand Down Expand Up @@ -224,14 +226,16 @@ public void testChainTransform() throws Exception {

assertNoFailuresAndResponse(prepareSearch("output1"), response -> {
assertThat(response.getHits().getTotalHits().value(), greaterThanOrEqualTo(1L));
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30"));
Map<String, Object> source = response.getHits().getAt(0).getSourceAsMap();
assertThat(source.size(), equalTo(1));
assertThat(source.get("key4").toString(), equalTo("30"));
});

assertNoFailuresAndResponse(prepareSearch("output2"), response -> {
assertThat(response.getHits().getTotalHits().value(), greaterThanOrEqualTo(1L));
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30"));
Map<String, Object> source = response.getHits().getAt(0).getSourceAsMap();
assertThat(source.size(), equalTo(1));
assertThat(source.get("key4").toString(), equalTo("30"));
});
}

Expand Down

0 comments on commit b59d17f

Please sign in to comment.