Skip to content

Commit

Permalink
Avoid using TimeWarp in TransformIntegrationTests. (elastic#39277)
Browse files Browse the repository at this point in the history
This commit makes `TransformIntegrationTests` into a standard integration test, as
opposed to using `TimeWarp`, which registers the mock component
`ScheduleEngineTriggerMock` to trigger watches.

The simplification may help with flakiness we've observed `TimeWarp, as in elastic#37882.
  • Loading branch information
jtibshirani authored and weizijun committed Feb 22, 2019
1 parent d85cd47 commit 223245e
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition;
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.test.WatcherMockScriptPlugin;
Expand Down Expand Up @@ -121,7 +120,6 @@ public void testScriptTransform() throws Exception {
.setSource(watchBuilder()
.trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.transform(scriptTransform(script))
.addAction("_id", indexAction("output1", "type")))
.get();
Expand All @@ -131,13 +129,12 @@ public void testScriptTransform() throws Exception {
.setSource(watchBuilder()
.trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("_id", scriptTransform(script), indexAction("output2", "type")))
.get();
assertThat(putWatchResponse.isCreated(), is(true));

timeWarp().trigger("_id1");
timeWarp().trigger("_id2");
executeWatch("_id1");
executeWatch("_id2");
refresh();

assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
Expand Down Expand Up @@ -184,8 +181,8 @@ public void testSearchTransform() throws Exception {
).get();
assertThat(putWatchResponse.isCreated(), is(true));

timeWarp().trigger("_id1");
timeWarp().trigger("_id2");
executeWatch("_id1");
executeWatch("_id2");
refresh();

assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
Expand All @@ -212,7 +209,6 @@ public void testChainTransform() throws Exception {
.setSource(watchBuilder()
.trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.transform(chainTransform(scriptTransform(script1), scriptTransform(script2)))
.addAction("_id", indexAction("output1", "type")))
.get();
Expand All @@ -222,14 +218,13 @@ public void testChainTransform() throws Exception {
.setSource(watchBuilder()
.trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("_id", chainTransform(scriptTransform(script1), scriptTransform(script2)),
indexAction("output2", "type")))
.get();
assertThat(putWatchResponse.isCreated(), is(true));

timeWarp().trigger("_id1");
timeWarp().trigger("_id2");
executeWatch("_id1");
executeWatch("_id2");
refresh();

assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
Expand All @@ -248,4 +243,10 @@ public void testChainTransform() throws Exception {
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30"));
}

private void executeWatch(String watchId) {
watcherClient().prepareExecuteWatch(watchId)
.setRecordExecution(true)
.get();
}
}

0 comments on commit 223245e

Please sign in to comment.