From 0ec1f66c60372d5acf10df1600417c349622bbfd Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 27 Nov 2014 17:20:32 +0100 Subject: [PATCH] Test: Run refresh before the search on metadata occurs. Original commit: elastic/x-pack-elasticsearch@2097f01458d82c3c9a97410dad3deb707ad8c039 --- .../elasticsearch/alerts/AlertMetadataTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/elasticsearch/alerts/AlertMetadataTest.java b/src/test/java/org/elasticsearch/alerts/AlertMetadataTest.java index a083079b450..ff3993ff0e0 100644 --- a/src/test/java/org/elasticsearch/alerts/AlertMetadataTest.java +++ b/src/test/java/org/elasticsearch/alerts/AlertMetadataTest.java @@ -7,7 +7,6 @@ package org.elasticsearch.alerts; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.alerts.actions.AlertActionManager; import org.junit.Test; import java.util.ArrayList; @@ -15,6 +14,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.elasticsearch.alerts.actions.AlertActionManager.ALERT_HISTORY_INDEX_PREFIX; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; @@ -35,17 +35,16 @@ public class AlertMetadataTest extends AbstractAlertingTests { metaList.add("test"); metadata.put("baz", metaList); - SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(matchAllQuery())); + SearchRequest triggerRequest = createTriggerSearchRequest("my-index").source(searchSource().query(matchAllQuery())); alertClient().preparePutAlert("1") - .setAlertSource(createAlertSource("0/5 * * * * ? *", searchRequest, "hits.total == 1", metadata)) + .setAlertSource(createAlertSource("0/5 * * * * ? *", triggerRequest, "hits.total == 1", metadata)) .get(); assertAlertTriggered("1", 0, false); - searchRequest = client() - .prepareSearch(AlertActionManager.ALERT_HISTORY_INDEX_PREFIX+"*").request(); - - searchRequest.source(searchSource().query(termQuery("meta.foo", "bar"))); - SearchResponse searchResponse = client().search(searchRequest).actionGet(); + refresh(); + SearchResponse searchResponse = client().prepareSearch(ALERT_HISTORY_INDEX_PREFIX + "*") + .setQuery(termQuery("meta.foo", "bar")) + .get(); assertThat(searchResponse.getHits().getTotalHits(), greaterThan(0L)); }