From bc37d2de85134c1739b6f6e0ad1ea34110be6e32 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 26 Sep 2018 17:49:53 -0700 Subject: [PATCH 1/2] Tests: Add support for custom contexts to mock scripts This commit adds the ability to plug in compilation of custom contexts in mock script engine. This is needed for testing plugins which add custom contexts like watcher. --- .../ingest/common/ScriptProcessorTests.java | 11 ++++---- .../action/update/UpdateRequestTests.java | 2 +- .../ingest/ConditionalProcessorTests.java | 21 +++++++++------- .../script/ScriptServiceTests.java | 4 +-- .../metrics/InternalScriptedMetricTests.java | 5 ++-- .../ScriptedMetricAggregatorTests.java | 4 +-- .../search/sort/AbstractSortTestCase.java | 2 +- .../ingest/TestTemplateService.java | 3 +-- .../script/MockScriptEngine.java | 16 ++++++++++-- .../script/MockScriptPlugin.java | 7 +++++- .../org/elasticsearch/test/ESTestCase.java | 2 +- .../xpack/upgrade/IndexUpgradeTasksIT.java | 2 +- .../condition/ScriptConditionTests.java | 2 +- .../input/transform/TransformInputTests.java | 3 ++- .../ExecutionVarsIntegrationTests.java | 25 +++++++++++++++++++ .../integration/SearchTransformTests.java | 2 +- 16 files changed, 77 insertions(+), 34 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java index 72bc337e9c9f7..10fcf5fe602ad 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorTests.java @@ -19,10 +19,6 @@ package org.elasticsearch.ingest.common; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - import org.elasticsearch.common.settings.Settings; import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.RandomDocumentPicks; @@ -33,6 +29,10 @@ import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.core.Is.is; @@ -52,7 +52,8 @@ Script.DEFAULT_SCRIPT_LANG, new MockScriptEngine( ctx.put("bytes_total", randomBytesTotal); return null; } - ) + ), + Collections.emptyMap() ) ), new HashMap<>(ScriptModule.CORE_CONTEXTS) diff --git a/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java index 8e6db7d776191..ff7697745da76 100644 --- a/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java @@ -132,7 +132,7 @@ public void setUp() throws Exception { return null; }); scripts.put("return", vars -> null); - final MockScriptEngine engine = new MockScriptEngine("mock", scripts); + final MockScriptEngine engine = new MockScriptEngine("mock", scripts, Collections.emptyMap()); Map engines = Collections.singletonMap(engine.getType(), engine); ScriptService scriptService = new ScriptService(baseSettings, engines, ScriptModule.CORE_CONTEXTS); final Settings settings = settings(Version.CURRENT).build(); diff --git a/server/src/test/java/org/elasticsearch/ingest/ConditionalProcessorTests.java b/server/src/test/java/org/elasticsearch/ingest/ConditionalProcessorTests.java index 12b4078ddf8bb..c7d4dfa4e68cd 100644 --- a/server/src/test/java/org/elasticsearch/ingest/ConditionalProcessorTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/ConditionalProcessorTests.java @@ -19,13 +19,6 @@ package org.elasticsearch.ingest; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.Script; @@ -34,6 +27,14 @@ import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; @@ -52,7 +53,8 @@ public void testChecksCondition() throws Exception { Script.DEFAULT_SCRIPT_LANG, Collections.singletonMap( scriptName, ctx -> trueValue.equals(ctx.get(conditionalField)) - ) + ), + Collections.emptyMap() ) ), new HashMap<>(ScriptModule.CORE_CONTEXTS) @@ -120,7 +122,8 @@ private static void assertMutatingCtxThrows(Consumer> mutati } return false; } - ) + ), + Collections.emptyMap() ) ), new HashMap<>(ScriptModule.CORE_CONTEXTS) diff --git a/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index ea8b6a9223412..fcb868c0e0e84 100644 --- a/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/server/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -66,12 +66,12 @@ public void setup() throws IOException { scripts.put(i + "+" + i, p -> null); // only care about compilation, not execution } scripts.put("script", p -> null); - scriptEngine = new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, scripts); + scriptEngine = new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, scripts, Collections.emptyMap()); //prevent duplicates using map contexts = new HashMap<>(ScriptModule.CORE_CONTEXTS); engines = new HashMap<>(); engines.put(scriptEngine.getType(), scriptEngine); - engines.put("test", new MockScriptEngine("test", scripts)); + engines.put("test", new MockScriptEngine("test", scripts, Collections.emptyMap())); logger.info("--> setup script service"); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalScriptedMetricTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalScriptedMetricTests.java index 89f42355f204a..d1918c170ed37 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalScriptedMetricTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalScriptedMetricTests.java @@ -30,8 +30,6 @@ import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.Aggregation.CommonFields; import org.elasticsearch.search.aggregations.ParsedAggregation; -import org.elasticsearch.search.aggregations.metrics.InternalScriptedMetric; -import org.elasticsearch.search.aggregations.metrics.ParsedScriptedMetric; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.InternalAggregationTestCase; @@ -118,7 +116,8 @@ protected ScriptService mockScriptService() { // mock script always retuns the size of the input aggs list as result @SuppressWarnings("unchecked") MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, - Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> ((List) script.get("states")).size())); + Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> ((List) script.get("states")).size()), + Collections.emptyMap()); Map engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine); return new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS); } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricAggregatorTests.java index 56b8938b6e54b..34ef4b9b93c98 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricAggregatorTests.java @@ -35,8 +35,6 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregatorTestCase; -import org.elasticsearch.search.aggregations.metrics.ScriptedMetric; -import org.elasticsearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder; import org.junit.BeforeClass; import java.io.IOException; @@ -345,7 +343,7 @@ public void testSelfReferencingAggStateAfterCombine() throws IOException { */ @Override protected QueryShardContext queryShardContextMock(MapperService mapperService) { - MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS); + MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS, Collections.emptyMap()); Map engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine); ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS); return new QueryShardContext(0, mapperService.getIndexSettings(), null, null, mapperService, null, scriptService, diff --git a/server/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/server/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index 2285af3ec46c0..e301e8c11c3ad 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/server/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -84,7 +84,7 @@ public static void init() { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .build(); Map, Object>> scripts = Collections.singletonMap(MOCK_SCRIPT_NAME, p -> null); - ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts); + ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts, Collections.emptyMap()); scriptService = new ScriptService(baseSettings, Collections.singletonMap(engine.getType(), engine), ScriptModule.CORE_CONTEXTS); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); diff --git a/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java b/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java index 4777d7c4ef24a..5bbf39d8fdc17 100644 --- a/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java +++ b/test/framework/src/main/java/org/elasticsearch/ingest/TestTemplateService.java @@ -43,8 +43,7 @@ public static ScriptService instance(boolean compilationException) { } private TestTemplateService(boolean compilationException) { - super(Settings.EMPTY, Collections.singletonMap(DEFAULT_TEMPLATE_LANG, - new MockScriptEngine(MockScriptEngine.NAME, Collections.emptyMap())), Collections.emptyMap()); + super(Settings.EMPTY, Collections.singletonMap(DEFAULT_TEMPLATE_LANG, new MockScriptEngine()), Collections.emptyMap()); this.compilationException = compilationException; } diff --git a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java index 1b609e8171195..e81c9f95ba2f6 100644 --- a/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java +++ b/test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java @@ -53,18 +53,26 @@ */ public class MockScriptEngine implements ScriptEngine { + /** A non-typed compiler for a single custom context */ + public interface ContextCompiler { + Object compile(Function, Object> script, Map params); + } + public static final String NAME = "mockscript"; private final String type; private final Map, Object>> scripts; + private final Map, ContextCompiler> contexts; - public MockScriptEngine(String type, Map, Object>> scripts) { + public MockScriptEngine(String type, Map, Object>> scripts, + Map, ContextCompiler> contexts) { this.type = type; this.scripts = Collections.unmodifiableMap(scripts); + this.contexts = Collections.unmodifiableMap(contexts); } public MockScriptEngine() { - this(NAME, Collections.emptyMap()); + this(NAME, Collections.emptyMap(), Collections.emptyMap()); } @Override @@ -198,6 +206,10 @@ public String execute() { ScriptedMetricAggContexts.ReduceScript.Factory factory = mockCompiled::createMetricAggReduceScript; return context.factoryClazz.cast(factory); } + ContextCompiler compiler = contexts.get(context); + if (compiler != null) { + return context.factoryClazz.cast(compiler.compile(script, params)); + } throw new IllegalArgumentException("mock script engine does not know how to handle context [" + context.name + "]"); } diff --git a/test/framework/src/main/java/org/elasticsearch/script/MockScriptPlugin.java b/test/framework/src/main/java/org/elasticsearch/script/MockScriptPlugin.java index cd951a3b53f5c..34aca79ec4725 100644 --- a/test/framework/src/main/java/org/elasticsearch/script/MockScriptPlugin.java +++ b/test/framework/src/main/java/org/elasticsearch/script/MockScriptPlugin.java @@ -24,6 +24,7 @@ import org.elasticsearch.plugins.ScriptPlugin; import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.function.Function; @@ -36,11 +37,15 @@ public abstract class MockScriptPlugin extends Plugin implements ScriptPlugin { @Override public ScriptEngine getScriptEngine(Settings settings, Collection> contexts) { - return new MockScriptEngine(pluginScriptLang(), pluginScripts()); + return new MockScriptEngine(pluginScriptLang(), pluginScripts(), pluginContextCompilers()); } protected abstract Map, Object>> pluginScripts(); + protected Map, MockScriptEngine.ContextCompiler> pluginContextCompilers() { + return Collections.emptyMap(); + } + public String pluginScriptLang() { return NAME; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index ffa7c601184b3..d5cf798682aef 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -1384,7 +1384,7 @@ public static ScriptModule newTestScriptModule() { return new ScriptModule(Settings.EMPTY, singletonList(new ScriptPlugin() { @Override public ScriptEngine getScriptEngine(Settings settings, Collection> contexts) { - return new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1")); + return new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"), Collections.emptyMap()); } })); } diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java index 7605af041e67c..1cc6ce8e54777 100644 --- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java +++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java @@ -88,7 +88,7 @@ public static class MockUpgradePlugin extends Plugin implements ScriptPlugin, Ac @Override public ScriptEngine getScriptEngine(Settings settings, Collection> contexts) { - return new MockScriptEngine(pluginScriptLang(), pluginScripts()); + return new MockScriptEngine(pluginScriptLang(), pluginScripts(), Collections.emptyMap()); } public String pluginScriptLang() { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java index bef38a27b6be2..9fd0ace3b321b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java @@ -83,7 +83,7 @@ public void init() throws IOException { return total > threshold; }); - ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts); + ScriptEngine engine = new MockScriptEngine(MockScriptEngine.NAME, scripts, Collections.emptyMap()); scriptService = new ScriptService(Settings.EMPTY, Collections.singletonMap(engine.getType(), engine), Collections.singletonMap(Watcher.SCRIPT_EXECUTABLE_CONTEXT.name, Watcher.SCRIPT_EXECUTABLE_CONTEXT)); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/transform/TransformInputTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/transform/TransformInputTests.java index aee5a5e07f09e..ce39046bfaf83 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/transform/TransformInputTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/transform/TransformInputTests.java @@ -47,7 +47,8 @@ public class TransformInputTests extends ESTestCase { @Before public void setupScriptService() { Map engines = new HashMap<>(); - engines.put(MockScriptEngine.NAME, new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", s -> "2"))); + engines.put(MockScriptEngine.NAME, + new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", s -> "2"), Collections.emptyMap())); Map> contexts = new HashMap<>(); contexts.put(Watcher.SCRIPT_TEMPLATE_CONTEXT.name, Watcher.SCRIPT_TEMPLATE_CONTEXT); contexts.put(Watcher.SCRIPT_SEARCH_CONTEXT.name, Watcher.SCRIPT_SEARCH_CONTEXT); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index 0b3c0fc28ec05..b3c96fed39d63 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -9,13 +9,17 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; +import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.MockScriptPlugin; +import org.elasticsearch.script.ScriptContext; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.watcher.condition.ScriptCondition; +import org.elasticsearch.xpack.watcher.condition.WatcherConditionScript; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; +import org.elasticsearch.xpack.watcher.transform.script.WatcherTransformScript; import org.hamcrest.Matcher; import java.util.HashMap; @@ -105,6 +109,27 @@ protected Map, Object>> pluginScripts() { return scripts; } + + protected Map, MockScriptEngine.ContextCompiler> pluginContextCompilers() { + HashMap, MockScriptEngine.ContextCompiler> compilers = new HashMap<>(); + compilers.put(WatcherConditionScript.CONTEXT, (script, options) -> + (WatcherConditionScript.Factory) (params, watcherContext) -> + new WatcherConditionScript(params, watcherContext) { + @Override + public boolean execute() { + return (boolean) script.apply(getParams()); + } + }); + compilers.put(WatcherTransformScript.CONTEXT, (script, options) -> + (WatcherTransformScript.Factory) (params, watcherContext, payload) -> + new WatcherTransformScript(params, watcherContext, payload) { + @Override + public Object execute() { + return script.apply(getParams()); + } + }); + return compilers; + } } public void testVars() throws Exception { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java index 10c61677a4c42..72bc71cdb08c2 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java @@ -70,7 +70,7 @@ public void testParser() throws Exception { XContentParser parser = createParser(builder); parser.nextToken(); - final MockScriptEngine engine = new MockScriptEngine("mock", Collections.emptyMap()); + final MockScriptEngine engine = new MockScriptEngine("mock", Collections.emptyMap(), Collections.emptyMap()); Map engines = Collections.singletonMap(engine.getType(), engine); ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS); From ebe9b49e4942be9939bc8460e1fc18ea6a02adca Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 27 Sep 2018 08:43:19 -0700 Subject: [PATCH 2/2] remove test use from different PR --- .../ExecutionVarsIntegrationTests.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index b3c96fed39d63..0b3c0fc28ec05 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -9,17 +9,13 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; -import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.MockScriptPlugin; -import org.elasticsearch.script.ScriptContext; import org.elasticsearch.xpack.core.watcher.client.WatcherClient; import org.elasticsearch.xpack.core.watcher.support.xcontent.ObjectPath; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.xpack.watcher.condition.ScriptCondition; -import org.elasticsearch.xpack.watcher.condition.WatcherConditionScript; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; -import org.elasticsearch.xpack.watcher.transform.script.WatcherTransformScript; import org.hamcrest.Matcher; import java.util.HashMap; @@ -109,27 +105,6 @@ protected Map, Object>> pluginScripts() { return scripts; } - - protected Map, MockScriptEngine.ContextCompiler> pluginContextCompilers() { - HashMap, MockScriptEngine.ContextCompiler> compilers = new HashMap<>(); - compilers.put(WatcherConditionScript.CONTEXT, (script, options) -> - (WatcherConditionScript.Factory) (params, watcherContext) -> - new WatcherConditionScript(params, watcherContext) { - @Override - public boolean execute() { - return (boolean) script.apply(getParams()); - } - }); - compilers.put(WatcherTransformScript.CONTEXT, (script, options) -> - (WatcherTransformScript.Factory) (params, watcherContext, payload) -> - new WatcherTransformScript(params, watcherContext, payload) { - @Override - public Object execute() { - return script.apply(getParams()); - } - }); - return compilers; - } } public void testVars() throws Exception {