Avoid using TimeWarp in TransformIntegrationTests. (#39277)

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 #37882.
This commit is contained in:
Julie Tibshirani 2019-02-21 17:57:46 -08:00
parent 697911c31d
commit 29243f7001
1 changed files with 12 additions and 11 deletions

View File

@ -16,7 +16,6 @@ import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.junit.annotations.TestLogging; 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.support.search.WatcherSearchTemplateRequest;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.test.WatcherMockScriptPlugin; import org.elasticsearch.xpack.watcher.test.WatcherMockScriptPlugin;
@ -121,7 +120,6 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.setSource(watchBuilder() .setSource(watchBuilder()
.trigger(schedule(interval("5s"))) .trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10))) .input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.transform(scriptTransform(script)) .transform(scriptTransform(script))
.addAction("_id", indexAction("output1", "type"))) .addAction("_id", indexAction("output1", "type")))
.get(); .get();
@ -131,13 +129,12 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.setSource(watchBuilder() .setSource(watchBuilder()
.trigger(schedule(interval("5s"))) .trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10))) .input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("_id", scriptTransform(script), indexAction("output2", "type"))) .addAction("_id", scriptTransform(script), indexAction("output2", "type")))
.get(); .get();
assertThat(putWatchResponse.isCreated(), is(true)); assertThat(putWatchResponse.isCreated(), is(true));
timeWarp().trigger("_id1"); executeWatch("_id1");
timeWarp().trigger("_id2"); executeWatch("_id2");
refresh(); refresh();
assertWatchWithMinimumPerformedActionsCount("_id1", 1, false); assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
@ -184,8 +181,8 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
).get(); ).get();
assertThat(putWatchResponse.isCreated(), is(true)); assertThat(putWatchResponse.isCreated(), is(true));
timeWarp().trigger("_id1"); executeWatch("_id1");
timeWarp().trigger("_id2"); executeWatch("_id2");
refresh(); refresh();
assertWatchWithMinimumPerformedActionsCount("_id1", 1, false); assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
@ -212,7 +209,6 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.setSource(watchBuilder() .setSource(watchBuilder()
.trigger(schedule(interval("5s"))) .trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10))) .input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.transform(chainTransform(scriptTransform(script1), scriptTransform(script2))) .transform(chainTransform(scriptTransform(script1), scriptTransform(script2)))
.addAction("_id", indexAction("output1", "type"))) .addAction("_id", indexAction("output1", "type")))
.get(); .get();
@ -222,14 +218,13 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.setSource(watchBuilder() .setSource(watchBuilder()
.trigger(schedule(interval("5s"))) .trigger(schedule(interval("5s")))
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10))) .input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
.condition(InternalAlwaysCondition.INSTANCE)
.addAction("_id", chainTransform(scriptTransform(script1), scriptTransform(script2)), .addAction("_id", chainTransform(scriptTransform(script1), scriptTransform(script2)),
indexAction("output2", "type"))) indexAction("output2", "type")))
.get(); .get();
assertThat(putWatchResponse.isCreated(), is(true)); assertThat(putWatchResponse.isCreated(), is(true));
timeWarp().trigger("_id1"); executeWatch("_id1");
timeWarp().trigger("_id2"); executeWatch("_id2");
refresh(); refresh();
assertWatchWithMinimumPerformedActionsCount("_id1", 1, false); assertWatchWithMinimumPerformedActionsCount("_id1", 1, false);
@ -248,4 +243,10 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30")); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30"));
} }
private void executeWatch(String watchId) {
watcherClient().prepareExecuteWatch(watchId)
.setRecordExecution(true)
.get();
}
} }