Fix mock painless to use mock compiled script for generating

search/executable scripts

Original commit: elastic/x-pack-elasticsearch@362432664b
This commit is contained in:
Ryan Ernst 2017-05-26 00:33:38 -07:00
parent d9816fac58
commit 4ecd1e5d50
1 changed files with 4 additions and 3 deletions

View File

@ -43,11 +43,12 @@ public class MockPainlessScriptEngine extends MockScriptEngine {
}
@Override
public <T> T compile(String name, String script, ScriptContext<T> context, Map<String, String> params) {
public <T> T compile(String name, String script, ScriptContext<T> context, Map<String, String> options) {
MockCompiledScript compiledScript = new MockCompiledScript(name, options, script, p -> script);
if (context.instanceClazz.equals(ExecutableScript.class)) {
return context.factoryClazz.cast((ExecutableScript.Factory) vars -> new MockExecutableScript(vars, p -> script));
return context.factoryClazz.cast((ExecutableScript.Factory) compiledScript::createExecutableScript);
} else if (context.instanceClazz.equals(SearchScript.class)) {
return context.factoryClazz.cast((SearchScript.Factory) (vars, lookup) -> new MockSearchScript(lookup, vars, p -> script));
return context.factoryClazz.cast((SearchScript.Factory) compiledScript::createSearchScript);
}
throw new IllegalArgumentException("mock painless does not know how to handle context [" + context.name + "]");
}