Search in sources :

Example 6 with ScriptSettings

use of org.elasticsearch.script.ScriptSettings in project elasticsearch by elastic.

the class ScriptedMetricAggregatorTests method queryShardContextMock.

/**
     * We cannot use Mockito for mocking QueryShardContext in this case because
     * script-related methods (e.g. QueryShardContext#getLazyExecutableScript)
     * is final and cannot be mocked
     */
@Override
protected QueryShardContext queryShardContextMock(final MappedFieldType[] fieldTypes, IndexSettings idxSettings, CircuitBreakerService circuitBreakerService) {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").build();
    MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS);
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    ScriptService scriptService;
    try {
        scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    } catch (IOException e) {
        throw new ElasticsearchException(e);
    }
    return new QueryShardContext(0, idxSettings, null, null, null, null, scriptService, xContentRegistry(), null, null, System::currentTimeMillis);
}
Also used : ScriptService(org.elasticsearch.script.ScriptService) ScriptSettings(org.elasticsearch.script.ScriptSettings) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) MockScriptEngine(org.elasticsearch.script.MockScriptEngine) Environment(org.elasticsearch.env.Environment) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ScriptSettings(org.elasticsearch.script.ScriptSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry)

Aggregations

Environment (org.elasticsearch.env.Environment)6 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)6 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)6 ScriptService (org.elasticsearch.script.ScriptService)6 ScriptSettings (org.elasticsearch.script.ScriptSettings)6 Settings (org.elasticsearch.common.settings.Settings)5 MockScriptEngine (org.elasticsearch.script.MockScriptEngine)3 Script (org.elasticsearch.script.Script)3 ResourceWatcherService (org.elasticsearch.watcher.ResourceWatcherService)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 IndexSettings (org.elasticsearch.index.IndexSettings)2 Collections (java.util.Collections)1 List (java.util.List)1 Function (java.util.function.Function)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1