test: re-enabled a number of Watcher tests that were disabled
Relates to elastic/elasticsearch#724 Original commit: elastic/x-pack-elasticsearch@3bdd118f2e
This commit is contained in:
parent
b7b9fa3ba5
commit
418c341e32
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.watcher.condition;
|
||||
|
||||
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.condition.compare.array.ArrayCompareCondition;
|
||||
import org.elasticsearch.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.watcher.condition.script.ScriptCondition;
|
||||
|
@ -39,6 +40,10 @@ public final class ConditionBuilders {
|
|||
return ScriptCondition.builder(script);
|
||||
}
|
||||
|
||||
public static CompareCondition.Builder compareCondition(String path, CompareCondition.Op op, Object value) {
|
||||
return CompareCondition.builder(path, op, value);
|
||||
}
|
||||
|
||||
public static ArrayCompareCondition.Builder arrayCompareCondition(String arrayPath, String path, ArrayCompareCondition.Op op, Object value, ArrayCompareCondition.Quantifier quantifier) {
|
||||
return ArrayCompareCondition.builder(arrayPath, path, op, value, quantifier);
|
||||
}
|
||||
|
|
|
@ -220,6 +220,10 @@ public class CompareCondition implements Condition {
|
|||
}
|
||||
}
|
||||
|
||||
public static Builder builder(String path, Op op, Object value) {
|
||||
return new Builder(path, op, value);
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<CompareCondition> {
|
||||
|
||||
private String path;
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
package org.elasticsearch.watcher.actions;
|
||||
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.history.WatchRecord;
|
||||
|
@ -24,7 +24,7 @@ import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.matchAllRequest;
|
||||
import static org.elasticsearch.watcher.transform.TransformBuilders.searchTransform;
|
||||
|
@ -35,7 +35,6 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
/**
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||
private IndexResponse indexTestDoc() {
|
||||
createIndex("actions", "events");
|
||||
|
@ -63,7 +62,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(matchAllRequest().indices("events")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.transform(searchTransform(matchAllRequest().indices("events")))
|
||||
.addAction("_id", indexAction("actions", "action"))
|
||||
.defaultThrottlePeriod(TimeValue.timeValueSeconds(30)))
|
||||
|
@ -137,7 +136,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("1s")))
|
||||
.input(searchInput(matchAllRequest().indices("events")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.transform(searchTransform(matchAllRequest().indices("events")))
|
||||
.addAction("_id", indexAction("actions", "action")))
|
||||
.get();
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging;
|
|||
import org.elasticsearch.watcher.actions.email.service.EmailTemplate;
|
||||
import org.elasticsearch.watcher.actions.email.service.support.EmailServer;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
|
||||
import org.junit.After;
|
||||
|
@ -27,7 +28,7 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
|||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
|
||||
import static org.elasticsearch.watcher.actions.ActionBuilders.emailAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.newInputSearchRequest;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -36,7 +37,6 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
|
||||
@TestLogging("subethamail:TRACE,watcher:TRACE")
|
||||
@ESIntegTestCase.ClusterScope(scope = SUITE, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 1)
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class EmailActionIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||
static final String USERNAME = "_user";
|
||||
static final String PASSWORD = "_passwd";
|
||||
|
@ -84,7 +84,7 @@ public class EmailActionIntegrationTests extends AbstractWatcherIntegrationTestC
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.addAction("_email", emailAction(EmailTemplate.builder().from("_from").to("_to")
|
||||
.subject("{{ctx.payload.hits.hits.0._source.field}}")).setAuthentication(USERNAME, PASSWORD.toCharArray())))
|
||||
.get();
|
||||
|
|
|
@ -59,7 +59,6 @@ import static org.mockito.Mockito.*;
|
|||
|
||||
/**
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class WebhookActionTests extends ESTestCase {
|
||||
static final String TEST_HOST = "test.com";
|
||||
static final int TEST_PORT = 8089;
|
||||
|
@ -214,7 +213,7 @@ public class WebhookActionTests extends ESTestCase {
|
|||
actionParser.parseExecutable("_watch", randomAsciiOfLength(5), parser);
|
||||
fail("expected a WebhookActionException since we only provided either a host or a port but not both");
|
||||
} catch (ElasticsearchParseException e) {
|
||||
assertThat(e.getMessage(), containsString("could not parse http request template. missing required ["));
|
||||
assertThat(e.getMessage(), containsString("failed parsing http request template"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,9 @@ import org.elasticsearch.watcher.actions.ActionStatus;
|
|||
import org.elasticsearch.watcher.actions.logging.LoggingAction;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.history.WatchRecord;
|
||||
import org.elasticsearch.watcher.input.simple.SimpleInput;
|
||||
import org.elasticsearch.watcher.support.Script;
|
||||
import org.elasticsearch.watcher.support.clock.SystemClock;
|
||||
import org.elasticsearch.watcher.support.xcontent.ObjectPath;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -66,7 +64,7 @@ import static org.hamcrest.Matchers.not;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
|
||||
public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
||||
@Override
|
||||
protected boolean enableShield() {
|
||||
|
@ -304,11 +302,12 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
assertThat(ObjectPath.<String>eval("state", executeWatchResult), equalTo(ExecutionState.THROTTLED.toString()));
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public void testWatchExecutionDuration() throws Exception {
|
||||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(new ScriptCondition((new Script.Builder.Inline("sleep 100; return true")).build()))
|
||||
// .condition(new ScriptCondition((new Script.Builder.Inline("sleep 100; return true")).build()))
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
Watch watch = watchParser().parse("_id", false, watchBuilder.buildAsBytes(XContentType.JSON));
|
||||
|
@ -317,11 +316,12 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
assertThat(record.result().executionDurationMs(), greaterThanOrEqualTo(100L));
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public void testForceDeletionOfLongRunningWatch() throws Exception {
|
||||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(new ScriptCondition((new Script.Builder.Inline("sleep 10000; return true")).build()))
|
||||
// .condition(new ScriptCondition((new Script.Builder.Inline("sleep 10000; return true")).build()))
|
||||
.defaultThrottlePeriod(new TimeValue(1, TimeUnit.HOURS))
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
|
||||
/**
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class TriggeredWatchTests extends AbstractWatcherIntegrationTestCase {
|
||||
public void testParser() throws Exception {
|
||||
Watch watch = WatcherTestUtils.createTestWatch("fired_test", scriptService(), watcherHttpClient(), noopEmailService(), logger);
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
|
||||
|
@ -30,14 +31,13 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.xContentSource;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
|
@ -60,7 +60,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.path("/index/_search")
|
||||
.body(jsonBuilder().startObject().field("size", 1).endObject())
|
||||
.auth(shieldEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l))
|
||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
||||
.get();
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.input(httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||
.path("/_cluster/stats")
|
||||
.auth(shieldEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
||||
.condition(scriptCondition("ctx.payload.nodes.count.total >= 1"))
|
||||
.condition(compareCondition("ctx.payload.nodes.count.total", CompareCondition.Op.GTE, 1l))
|
||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
||||
.get();
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(10, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(httpInput(requestBuilder).extractKeys("hits.total"))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l)))
|
||||
.get();
|
||||
|
||||
// in this watcher the condition will fail, because max_score isn't extracted, only total:
|
||||
|
@ -122,7 +122,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(10, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(httpInput(requestBuilder).extractKeys("hits.total"))
|
||||
.condition(scriptCondition("ctx.payload.hits.max_score >= 0")))
|
||||
.condition(compareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
|
|
@ -414,27 +414,38 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
|
|||
}
|
||||
|
||||
protected void assertWatchWithNoActionNeeded(final String watchName, final long expectedWatchActionsWithNoActionNeeded) throws Exception {
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The watch_history index gets created in the background when the first watch is triggered, so we to check first is this index is created and shards are started
|
||||
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
||||
String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndices(state, IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*");
|
||||
assertThat(watchHistoryIndices, not(emptyArray()));
|
||||
for (String index : watchHistoryIndices) {
|
||||
IndexRoutingTable routingTable = state.getRoutingTable().index(index);
|
||||
assertThat(routingTable, notNullValue());
|
||||
assertThat(routingTable.allPrimaryShardsActive(), is(true));
|
||||
final AtomicReference<SearchResponse> lastResponse = new AtomicReference<>();
|
||||
try {
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The watch_history index gets created in the background when the first watch is triggered, so we to check first is this index is created and shards are started
|
||||
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
||||
String[] watchHistoryIndices = indexNameExpressionResolver().concreteIndices(state, IndicesOptions.lenientExpandOpen(), HistoryStore.INDEX_PREFIX + "*");
|
||||
assertThat(watchHistoryIndices, not(emptyArray()));
|
||||
for (String index : watchHistoryIndices) {
|
||||
IndexRoutingTable routingTable = state.getRoutingTable().index(index);
|
||||
assertThat(routingTable, notNullValue());
|
||||
assertThat(routingTable.allPrimaryShardsActive(), is(true));
|
||||
}
|
||||
refresh();
|
||||
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*")
|
||||
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|
||||
.setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTION_NOT_NEEDED.id())))
|
||||
.get();
|
||||
lastResponse.set(searchResponse);
|
||||
assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded));
|
||||
}
|
||||
|
||||
refresh();
|
||||
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX + "*")
|
||||
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|
||||
.setQuery(boolQuery().must(matchQuery("watch_id", watchName)).must(matchQuery("state", ExecutionState.EXECUTION_NOT_NEEDED.id())))
|
||||
.get();
|
||||
assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedWatchActionsWithNoActionNeeded));
|
||||
});
|
||||
} catch (AssertionError error) {
|
||||
SearchResponse searchResponse = lastResponse.get();
|
||||
logger.info("Found [{}] records for watch [{}]", searchResponse.getHits().totalHits(), watchName);
|
||||
int counter = 1;
|
||||
for (SearchHit hit : searchResponse.getHits().getHits()) {
|
||||
logger.info("hit [{}]=\n {}", counter++, XContentHelper.convertToJson(hit.getSourceRef(), true, true));
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertWatchWithMinimumActionsCount(final String watchName, final ExecutionState recordState, final long recordCount) throws Exception {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.watcher.actions.email.ExecutableEmailAction;
|
|||
import org.elasticsearch.watcher.actions.email.service.*;
|
||||
import org.elasticsearch.watcher.actions.webhook.ExecutableWebhookAction;
|
||||
import org.elasticsearch.watcher.actions.webhook.WebhookAction;
|
||||
import org.elasticsearch.watcher.condition.always.ExecutableAlwaysCondition;
|
||||
import org.elasticsearch.watcher.condition.script.ExecutableScriptCondition;
|
||||
import org.elasticsearch.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
|
@ -105,7 +106,8 @@ public final class WatcherTestUtils {
|
|||
}
|
||||
|
||||
public static SearchRequest newInputSearchRequest(String... indices) {
|
||||
SearchRequest request = new SearchRequest(indices);
|
||||
SearchRequest request = new SearchRequest();
|
||||
request.indices(indices);
|
||||
request.indicesOptions(WatcherUtils.DEFAULT_INDICES_OPTIONS);
|
||||
request.searchType(ExecutableSearchInput.DEFAULT_SEARCH_TYPE);
|
||||
return request;
|
||||
|
@ -215,7 +217,7 @@ public final class WatcherTestUtils {
|
|||
watchName,
|
||||
new ScheduleTrigger(new CronSchedule("0/5 * * * * ? *")),
|
||||
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple(inputData)), logger),
|
||||
new ExecutableScriptCondition(new ScriptCondition(Script.inline("return true").build()), logger, scriptService),
|
||||
new ExecutableAlwaysCondition(logger),
|
||||
new ExecutableSearchTransform(new SearchTransform(transformRequest, null, null), logger, client, null),
|
||||
new TimeValue(0),
|
||||
new ExecutableActions(actions),
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.test.integration;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
|
@ -14,13 +13,15 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.util.Callback;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.Template;
|
||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.ConditionBuilders;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.support.WatcherUtils;
|
||||
import org.elasticsearch.watcher.support.clock.SystemClock;
|
||||
import org.elasticsearch.watcher.support.xcontent.XContentSource;
|
||||
|
@ -35,11 +36,7 @@ import org.elasticsearch.watcher.trigger.schedule.support.WeekTimes;
|
|||
import org.elasticsearch.watcher.watch.WatchStore;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
|
@ -47,26 +44,24 @@ import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
|
|||
import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.newInputSearchRequest;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.xContentSource;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.daily;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.hourly;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.monthly;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.weekly;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
*/
|
||||
@TestLogging("watcher.trigger.schedule:TRACE")
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
||||
|
||||
@Override
|
||||
protected boolean enableShield() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testIndexWatch() throws Exception {
|
||||
WatcherClient watcherClient = watcherClient();
|
||||
createIndex("idx");
|
||||
|
@ -78,7 +73,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l))
|
||||
.addAction("_logger", loggingAction("\n\n************\n" +
|
||||
"total hits: {{ctx.payload.hits.total}}\n" +
|
||||
"************\n")
|
||||
|
@ -104,7 +99,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
@ -135,7 +130,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l)))
|
||||
.get();
|
||||
assertThat(indexResponse.isCreated(), is(true));
|
||||
|
||||
|
@ -204,7 +199,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.addAction("_id", indexAction("idx", "action"));
|
||||
|
||||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source.condition(scriptCondition("ctx.payload.hits.total == 1")))
|
||||
.setSource(source.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
@ -215,7 +210,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
assertWatchWithMinimumPerformedActionsCount("_name", 0, false);
|
||||
|
||||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source.condition(scriptCondition("ctx.payload.hits.total == 0")))
|
||||
.setSource(source.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
@ -228,7 +223,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source
|
||||
.trigger(schedule(Schedules.cron("0/1 * * * * ? 2020")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 0")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
@ -330,14 +325,14 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest).extractKeys("hits.total"))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l)))
|
||||
.get();
|
||||
// in this watcher the condition will fail, because max_score isn't extracted, only total:
|
||||
watcherClient.preparePutWatch("_name2")
|
||||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest).extractKeys("hits.total"))
|
||||
.condition(scriptCondition("ctx.payload.hits.max_score >= 0")))
|
||||
.condition(compareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0l)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
@ -444,7 +439,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(request))
|
||||
.condition(ConditionBuilders.scriptCondition("return ctx.payload.hits.total >= 3")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GTE, 3l)))
|
||||
.get();
|
||||
|
||||
logger.info("created watch [{}] at [{}]", watchName, SystemClock.INSTANCE.nowUTC());
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging;
|
|||
import org.elasticsearch.watcher.WatcherState;
|
||||
import org.elasticsearch.watcher.condition.Condition;
|
||||
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.watcher.execution.TriggeredWatch;
|
||||
import org.elasticsearch.watcher.execution.TriggeredWatchStore;
|
||||
|
@ -38,7 +39,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC
|
|||
import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.newInputSearchRequest;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -50,7 +51,6 @@ import static org.joda.time.DateTimeZone.UTC;
|
|||
/**
|
||||
*/
|
||||
@TestLogging("watcher:TRACE")
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
||||
@Override
|
||||
protected boolean timeWarped() {
|
||||
|
@ -221,7 +221,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0 0/5 * * * ? 2050")))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l))
|
||||
.buildAsBytes(XContentType.JSON)
|
||||
)
|
||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.watcher.WatcherState;
|
|||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilders;
|
||||
import org.elasticsearch.watcher.condition.ConditionBuilders;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.execution.ExecutionService;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.test.WatcherTestUtils;
|
||||
|
@ -41,6 +42,7 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
|||
import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -53,7 +55,6 @@ import static org.hamcrest.core.Is.is;
|
|||
@TestLogging("discovery:TRACE,watcher:TRACE")
|
||||
@ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 0)
|
||||
@SuppressLocalMode
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
||||
private ClusterDiscoveryConfiguration.UnicastZen config;
|
||||
|
||||
|
@ -92,7 +93,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSource = watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(ConditionBuilders.scriptCondition("ctx.payload.hits.total == 1"));
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l));
|
||||
|
||||
// we first need to make sure the license is enabled, otherwise all APIs will be blocked
|
||||
ensureLicenseEnabled();
|
||||
|
@ -201,7 +202,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSource = watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(ConditionBuilders.scriptCondition("ctx.payload.hits.total == 1"));
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l));
|
||||
watcherClient().preparePutWatch(watchName).setSource(watchSource).get();
|
||||
}
|
||||
ensureGreen();
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.test.integration;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.actions.logging.LoggingAction;
|
||||
import org.elasticsearch.watcher.actions.logging.LoggingLevel;
|
||||
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
|
@ -32,7 +32,7 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -43,7 +43,6 @@ import static org.joda.time.DateTimeZone.UTC;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase {
|
||||
public void testWatchMetadata() throws Exception {
|
||||
Map<String, Object> metadata = new HashMap<>();
|
||||
|
@ -59,7 +58,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(WatcherTestUtils.newInputSearchRequest("my-index").source(searchSource().query(matchAllQuery()))))
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l))
|
||||
.metadata(metadata))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.watcher.transport.action.ack;
|
||||
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
|
@ -15,6 +14,7 @@ import org.elasticsearch.action.index.IndexResponse;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.actions.ActionStatus;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.history.WatchRecord;
|
||||
|
@ -34,7 +34,7 @@ import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.matchAllRequest;
|
||||
import static org.elasticsearch.watcher.transform.TransformBuilders.searchTransform;
|
||||
|
@ -48,7 +48,6 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||
|
||||
/**
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
||||
private IndexResponse indexTestDoc() {
|
||||
createIndex("actions", "events");
|
||||
|
@ -71,7 +70,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(matchAllRequest().indices("events")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.transform(searchTransform(matchAllRequest().indices("events")))
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.addAction("_a2", indexAction("actions", "action2"))
|
||||
|
@ -143,7 +142,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(matchAllRequest().indices("events")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.transform(searchTransform(matchAllRequest().indices("events")))
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.addAction("_a2", indexAction("actions", "action2"))
|
||||
|
@ -222,7 +221,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(matchAllRequest().indices("events")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0l))
|
||||
.transform(searchTransform(matchAllRequest().indices("events")))
|
||||
.addAction("_id", indexAction("actions", "action")))
|
||||
.get();
|
||||
|
@ -292,7 +291,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient.prepareAckWatch("_id").setActionIds("id with whitespaces").get();
|
||||
fail("Expected ActionRequestValidationException");
|
||||
} catch (ActionRequestValidationException e) {
|
||||
assertThat(e.getMessage(), containsString("Watch id cannot have white spaces"));
|
||||
assertThat(e.getMessage(), containsString("Action id cannot have white spaces"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.action.stats;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
|
@ -13,7 +12,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging;
|
|||
import org.elasticsearch.watcher.WatcherBuild;
|
||||
import org.elasticsearch.watcher.WatcherState;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.condition.ConditionBuilders;
|
||||
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.test.WatcherTestUtils;
|
||||
import org.elasticsearch.watcher.transport.actions.delete.DeleteWatchResponse;
|
||||
|
@ -26,6 +25,7 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
||||
import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -38,7 +38,6 @@ import static org.hamcrest.core.IsEqual.equalTo;
|
|||
*/
|
||||
@ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false)
|
||||
@TestLogging("watcher:TRACE")
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/724")
|
||||
public class WatcherStatsTests extends AbstractWatcherIntegrationTestCase {
|
||||
public void testStartedStats() throws Exception {
|
||||
WatcherStatsRequest watcherStatsRequest = watcherClient().prepareWatcherStats().request();
|
||||
|
@ -64,7 +63,7 @@ public class WatcherStatsTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("* * * * * ? *")))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(ConditionBuilders.scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1l))
|
||||
)
|
||||
.get();
|
||||
|
||||
|
|
Loading…
Reference in New Issue