Test: make sure a refresh has ran.

Original commit: elastic/x-pack-elasticsearch@db9a8c417c
This commit is contained in:
Martijn van Groningen 2015-04-01 17:45:36 +02:00
parent efb6ae8e1f
commit 3a37ebca41
2 changed files with 5 additions and 4 deletions

View File

@ -293,11 +293,13 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
assertWatchWithNoActionNeeded("_name2", 1); assertWatchWithNoActionNeeded("_name2", 1);
// Check that the input result payload has been filtered // Check that the input result payload has been filtered
refresh();
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*")
.setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setQuery(matchQuery("watch_name", "_name1")) .setQuery(matchQuery("watch_name", "_name1"))
.setSize(1) .setSize(1)
.get(); .get();
assertHitCount(searchResponse, 1);
Map payload = (Map) ((Map)((Map)((Map) searchResponse.getHits().getAt(0).sourceAsMap().get("watch_execution")).get("input_result")).get("search")).get("payload"); Map payload = (Map) ((Map)((Map)((Map) searchResponse.getHits().getAt(0).sourceAsMap().get("watch_execution")).get("input_result")).get("search")).get("payload");
assertThat(payload.size(), equalTo(1)); assertThat(payload.size(), equalTo(1));
assertThat(((Map) payload.get("hits")).size(), equalTo(1)); assertThat(((Map) payload.get("hits")).size(), equalTo(1));

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.test.integration; package org.elasticsearch.watcher.test.integration;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
@ -28,12 +27,11 @@ import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction; import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
import static org.elasticsearch.watcher.client.WatchSourceBuilder.watchSourceBuilder; import static org.elasticsearch.watcher.client.WatchSourceBuilder.watchSourceBuilder;
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition; import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
import static org.elasticsearch.watcher.input.InputBuilders.httpInput; import static org.elasticsearch.watcher.input.InputBuilders.httpInput;
import static org.elasticsearch.watcher.test.WatcherTestUtils.newInputSearchRequest;
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval; import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -103,7 +101,6 @@ public class HttpInputIntegrationTest extends AbstractWatcherIntegrationTests {
.setBody(new ScriptTemplate(sc, body)) .setBody(new ScriptTemplate(sc, body))
.addExtractKey("hits.total"); .addExtractKey("hits.total");
SearchRequest searchRequest = newInputSearchRequest("idx").source(searchSource().query(termQuery("field", "value")));
watcherClient.preparePutWatch("_name1") watcherClient.preparePutWatch("_name1")
.source(watchSourceBuilder() .source(watchSourceBuilder()
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS))) .trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
@ -129,11 +126,13 @@ public class HttpInputIntegrationTest extends AbstractWatcherIntegrationTests {
assertWatchWithNoActionNeeded("_name2", 1); assertWatchWithNoActionNeeded("_name2", 1);
// Check that the input result payload has been filtered // Check that the input result payload has been filtered
refresh();
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*") SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*")
.setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setQuery(matchQuery("watch_name", "_name1")) .setQuery(matchQuery("watch_name", "_name1"))
.setSize(1) .setSize(1)
.get(); .get();
assertHitCount(searchResponse, 1);
Map payload = (Map) ((Map)((Map)((Map) searchResponse.getHits().getAt(0).sourceAsMap().get("watch_execution")).get("input_result")).get("http")).get("payload"); Map payload = (Map) ((Map)((Map)((Map) searchResponse.getHits().getAt(0).sourceAsMap().get("watch_execution")).get("input_result")).get("http")).get("payload");
assertThat(payload.size(), equalTo(1)); assertThat(payload.size(), equalTo(1));
assertThat(((Map) payload.get("hits")).size(), equalTo(1)); assertThat(((Map) payload.get("hits")).size(), equalTo(1));