Avoid using TimeWarp in TransformIntegrationTests.
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
@@ -15,7 +15,6 @@ import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse;
import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
-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;
@@ -120,7 +119,6 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.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();
@@ -130,13 +128,12 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.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);
@@ -183,8 +180,8 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
).get();
assertThat(putWatchResponse.isCreated(), is(true));
- timeWarp().trigger("_id1");
- timeWarp().trigger("_id2");
+ executeWatch("_id1");
+ executeWatch("_id2");
refresh();
assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
@@ -211,7 +208,6 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.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();
@@ -221,14 +217,13 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.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);
@@ -247,4 +242,10 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
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();
+ }
}
