[TEST] adapt to changes upstream, expression has been moved out
Queries that can include scripts make now use of the mock script engine
This commit is contained in:
parent
34de79370f
commit
a50a0da183
|
@ -69,7 +69,8 @@ import org.elasticsearch.indices.IndicesModule;
|
|||
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
|
||||
import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.script.*;
|
||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.TestSearchContext;
|
||||
|
@ -85,13 +86,11 @@ import java.io.IOException;
|
|||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>> extends ESTestCase {
|
||||
|
||||
|
@ -166,7 +165,38 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
bindQueryParsersExtension();
|
||||
}
|
||||
},
|
||||
new ScriptModule(settings),
|
||||
new ScriptModule(settings) {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Settings settings = Settings.builder()
|
||||
.put("path.home", createTempDir())
|
||||
// no file watching, so we don't need a ResourceWatcherService
|
||||
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
|
||||
.build();
|
||||
MockScriptEngine mockScriptEngine = new MockScriptEngine();
|
||||
Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
|
||||
multibinder.addBinding().toInstance(mockScriptEngine);
|
||||
try {
|
||||
Class.forName("com.github.mustachejava.Mustache");
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new IllegalStateException("error while loading mustache", e);
|
||||
}
|
||||
MustacheScriptEngineService mustacheScriptEngineService = new MustacheScriptEngineService(settings);
|
||||
Set<ScriptEngineService> engines = new HashSet<>();
|
||||
engines.add(mockScriptEngine);
|
||||
engines.add(mustacheScriptEngineService);
|
||||
List<ScriptContext.Plugin> customContexts = new ArrayList<>();
|
||||
bind(ScriptContextRegistry.class).toInstance(new ScriptContextRegistry(customContexts));
|
||||
try {
|
||||
ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, new ScriptContextRegistry(customContexts));
|
||||
bind(ScriptService.class).toInstance(scriptService);
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("error while binding ScriptService", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
new IndexSettingsModule(index, indexSettings),
|
||||
new IndexCacheModule(indexSettings),
|
||||
new AnalysisModule(indexSettings, new IndicesAnalysisService(indexSettings)),
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.script.expression.ExpressionScriptEngineService;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
@ -35,16 +35,9 @@ public class ScriptQueryBuilderTests extends AbstractQueryTestCase<ScriptQueryBu
|
|||
|
||||
@Override
|
||||
protected ScriptQueryBuilder doCreateTestQueryBuilder() {
|
||||
String script;
|
||||
Map<String, Object> params = null;
|
||||
if (randomBoolean()) {
|
||||
script = "5 * 2 > param";
|
||||
params = new HashMap<>();
|
||||
params.put("param", 1);
|
||||
} else {
|
||||
script = "5 * 2 > 2";
|
||||
}
|
||||
return new ScriptQueryBuilder(new Script(script, ScriptType.INLINE, ExpressionScriptEngineService.NAME, params));
|
||||
String script = "5";
|
||||
Map<String, Object> params = Collections.emptyMap();
|
||||
return new ScriptQueryBuilder(new Script(script, ScriptType.INLINE, MockScriptEngine.NAME, params));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,14 +35,14 @@ import org.elasticsearch.index.query.functionscore.lin.LinearDecayFunctionBuilde
|
|||
import org.elasticsearch.index.query.functionscore.random.RandomScoreFunctionBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.weight.WeightBuilder;
|
||||
import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.expression.ExpressionScriptEngineService;
|
||||
import org.elasticsearch.search.MultiValueMode;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
@ -140,16 +140,9 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
functionBuilder = fieldValueFactorFunctionBuilder;
|
||||
break;
|
||||
case 2:
|
||||
String script;
|
||||
Map<String, Object> params = null;
|
||||
if (randomBoolean()) {
|
||||
script = "5 * 2 > param";
|
||||
params = new HashMap<>();
|
||||
params.put("param", 1);
|
||||
} else {
|
||||
script = "5 * 2 > 2";
|
||||
}
|
||||
functionBuilder = new ScriptScoreFunctionBuilder(new Script(script, ScriptService.ScriptType.INLINE, ExpressionScriptEngineService.NAME, params));
|
||||
String script = "5";
|
||||
Map<String, Object> params = Collections.emptyMap();
|
||||
functionBuilder = new ScriptScoreFunctionBuilder(new Script(script, ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, params));
|
||||
break;
|
||||
case 3:
|
||||
RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilder();
|
||||
|
@ -420,7 +413,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
String functionScoreQuery = "{\n" +
|
||||
" \"function_score\": {\n" +
|
||||
" \"script_score\": {\n" +
|
||||
" \"script\": \"_index['text']['foo'].tf()\"\n" +
|
||||
" \"script\": \"5\"\n" +
|
||||
" },\n" +
|
||||
" \"weight\": 2\n" +
|
||||
" }\n" +
|
||||
|
|
Loading…
Reference in New Issue