diff options
author | Tanguy Leroux <tlrx.dev@gmail.com> | 2017-05-10 13:40:39 +0200 |
---|---|---|
committer | Tanguy Leroux <tlrx.dev@gmail.com> | 2017-05-10 13:40:39 +0200 |
commit | bf718a686fa9ba51a8292178740c15670d0f0ec5 (patch) | |
tree | 13056b1cf9dbaf25f87ad94e66231d4d60b41081 /core | |
parent | 7c97296d774d397a0c311cb70485ea985b34c49d (diff) | |
parent | 3e4406f044676d50aab0e7135d2a289a929ea84b (diff) |
Merge remote-tracking branch 'origin/master' into feature/client_aggs_parsing
# Conflicts:
# core/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTermsTestCase.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalMaxTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/cardinality/InternalCardinalityTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/geobounds/InternalGeoBoundsTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/min/InternalMinTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/InternalPercentilesTestCase.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/hdr/InternalHDRPercentilesRanksTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/InternalTDigestPercentilesRanksTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSumTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/InternalPercentilesBucketTests.java
# core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java
# test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java
Diffstat (limited to 'core')
53 files changed, 517 insertions, 790 deletions
diff --git a/core/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java b/core/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java index a7d59fcfb4..37834b93a1 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java @@ -57,7 +57,7 @@ public abstract class StringFieldType extends TermBasedFieldType { } @Override - public final Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, + public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { failIfNotIndexed(); return new FuzzyQuery(new Term(name(), indexedValueForSearch(value)), @@ -65,7 +65,7 @@ public abstract class StringFieldType extends TermBasedFieldType { } @Override - public final Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) { + public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) { failIfNotIndexed(); PrefixQuery query = new PrefixQuery(new Term(name(), indexedValueForSearch(value))); if (method != null) { @@ -75,7 +75,7 @@ public abstract class StringFieldType extends TermBasedFieldType { } @Override - public final Query regexpQuery(String value, int flags, int maxDeterminizedStates, + public Query regexpQuery(String value, int flags, int maxDeterminizedStates, MultiTermQuery.RewriteMethod method, QueryShardContext context) { failIfNotIndexed(); RegexpQuery query = new RegexpQuery(new Term(name(), indexedValueForSearch(value)), flags, maxDeterminizedStates); diff --git a/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java b/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java index c1e2a43c95..546fbdd24f 100644 --- a/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java +++ b/core/src/main/java/org/elasticsearch/plugins/ScriptPlugin.java @@ -21,7 +21,7 @@ package org.elasticsearch.plugins; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import java.util.Collections; import java.util.List; @@ -32,9 +32,9 @@ import java.util.List; public interface ScriptPlugin { /** - * Returns a {@link ScriptEngineService} instance or <code>null</code> if this plugin doesn't add a new script engine + * Returns a {@link ScriptEngine} instance or <code>null</code> if this plugin doesn't add a new script engine */ - default ScriptEngineService getScriptEngineService(Settings settings) { + default ScriptEngine getScriptEngine(Settings settings) { return null; } diff --git a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java index 69c8b92ba1..7bd2f62e15 100644 --- a/core/src/main/java/org/elasticsearch/script/NativeScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/NativeScriptEngine.java @@ -33,13 +33,13 @@ import static java.util.Collections.unmodifiableMap; /** * A native script engine service. */ -public class NativeScriptEngineService extends AbstractComponent implements ScriptEngineService { +public class NativeScriptEngine extends AbstractComponent implements ScriptEngine { public static final String NAME = "native"; private final Map<String, NativeScriptFactory> scripts; - public NativeScriptEngineService(Settings settings, Map<String, NativeScriptFactory> scripts) { + public NativeScriptEngine(Settings settings, Map<String, NativeScriptFactory> scripts) { super(settings); this.scripts = unmodifiableMap(scripts); } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java index 1760dbaa3a..89ded96256 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngine.java @@ -25,10 +25,19 @@ import org.elasticsearch.search.lookup.SearchLookup; import java.io.Closeable; import java.util.Map; -public interface ScriptEngineService extends Closeable { +/** + * A script language implementation. + */ +public interface ScriptEngine extends Closeable { + /** + * The language name used in the script APIs to refer to this scripting backend. + */ String getType(); + /** + * The extension for file scripts in this language. + */ String getExtension(); /** diff --git a/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java b/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java index f65d694aa3..4881d45f6c 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptEngineRegistry.java @@ -21,23 +21,21 @@ package org.elasticsearch.script; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; -import org.elasticsearch.common.Strings; public class ScriptEngineRegistry { - private final Map<Class<? extends ScriptEngineService>, String> registeredScriptEngineServices; - private final Map<String, ScriptEngineService> registeredLanguages; + private final Map<Class<? extends ScriptEngine>, String> registeredScriptEngineServices; + private final Map<String, ScriptEngine> registeredLanguages; private final Map<String, Boolean> defaultInlineScriptEnableds; - public ScriptEngineRegistry(Iterable<ScriptEngineService> registrations) { + public ScriptEngineRegistry(Iterable<ScriptEngine> registrations) { Objects.requireNonNull(registrations); - Map<Class<? extends ScriptEngineService>, String> registeredScriptEngineServices = new HashMap<>(); - Map<String, ScriptEngineService> registeredLanguages = new HashMap<>(); + Map<Class<? extends ScriptEngine>, String> registeredScriptEngineServices = new HashMap<>(); + Map<String, ScriptEngine> registeredLanguages = new HashMap<>(); Map<String, Boolean> inlineScriptEnableds = new HashMap<>(); - for (ScriptEngineService service : registrations) { + for (ScriptEngine service : registrations) { String oldLanguage = registeredScriptEngineServices.putIfAbsent(service.getClass(), service.getType()); if (oldLanguage != null) { @@ -45,11 +43,11 @@ public class ScriptEngineRegistry { "] already registered for language [" + oldLanguage + "]"); } String language = service.getType(); - ScriptEngineService scriptEngineService = + ScriptEngine scriptEngine = registeredLanguages.putIfAbsent(language, service); - if (scriptEngineService != null) { + if (scriptEngine != null) { throw new IllegalArgumentException("scripting language [" + language + "] already registered for script engine service [" + - scriptEngineService.getClass().getCanonicalName() + "]"); + scriptEngine.getClass().getCanonicalName() + "]"); } inlineScriptEnableds.put(language, service.isInlineScriptEnabled()); } @@ -59,16 +57,16 @@ public class ScriptEngineRegistry { this.defaultInlineScriptEnableds = Collections.unmodifiableMap(inlineScriptEnableds); } - Iterable<Class<? extends ScriptEngineService>> getRegisteredScriptEngineServices() { + Iterable<Class<? extends ScriptEngine>> getRegisteredScriptEngineServices() { return registeredScriptEngineServices.keySet(); } - String getLanguage(Class<? extends ScriptEngineService> scriptEngineService) { + String getLanguage(Class<? extends ScriptEngine> scriptEngineService) { Objects.requireNonNull(scriptEngineService); return registeredScriptEngineServices.get(scriptEngineService); } - public Map<String, ScriptEngineService> getRegisteredLanguages() { + public Map<String, ScriptEngine> getRegisteredLanguages() { return registeredLanguages; } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModes.java b/core/src/main/java/org/elasticsearch/script/ScriptModes.java index 15393948d6..ae12deaec9 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModes.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModes.java @@ -57,7 +57,7 @@ public class ScriptModes { */ public boolean getScriptEnabled(String lang, ScriptType scriptType, ScriptContext scriptContext) { //native scripts are always enabled as they are static by definition - if (NativeScriptEngineService.NAME.equals(lang)) { + if (NativeScriptEngine.NAME.equals(lang)) { return true; } Boolean scriptMode = scriptEnabled.get(getKey(lang, scriptType, scriptContext)); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java index 30f84bc696..ff03c25265 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -27,8 +27,6 @@ import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.watcher.ResourceWatcherService; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -50,23 +48,23 @@ public class ScriptModule { ResourceWatcherService resourceWatcherService, List<ScriptPlugin> scriptPlugins) { Map<String, NativeScriptFactory> factoryMap = scriptPlugins.stream().flatMap(x -> x.getNativeScripts().stream()) .collect(Collectors.toMap(NativeScriptFactory::getName, Function.identity())); - NativeScriptEngineService nativeScriptEngineService = new NativeScriptEngineService(settings, factoryMap); - List<ScriptEngineService> scriptEngineServices = scriptPlugins.stream().map(x -> x.getScriptEngineService(settings)) + NativeScriptEngine nativeScriptEngineService = new NativeScriptEngine(settings, factoryMap); + List<ScriptEngine> scriptEngines = scriptPlugins.stream().map(x -> x.getScriptEngine(settings)) .filter(Objects::nonNull).collect(Collectors.toList()); - scriptEngineServices.add(nativeScriptEngineService); + scriptEngines.add(nativeScriptEngineService); List<ScriptContext.Plugin> plugins = scriptPlugins.stream().map(x -> x.getCustomScriptContexts()).filter(Objects::nonNull) .collect(Collectors.toList()); - return new ScriptModule(settings, environment, resourceWatcherService, scriptEngineServices, plugins); + return new ScriptModule(settings, environment, resourceWatcherService, scriptEngines, plugins); } /** - * Build {@linkplain ScriptEngineService} and {@linkplain ScriptContext.Plugin}. + * Build {@linkplain ScriptEngine} and {@linkplain ScriptContext.Plugin}. */ public ScriptModule(Settings settings, Environment environment, - ResourceWatcherService resourceWatcherService, List<ScriptEngineService> scriptEngineServices, + ResourceWatcherService resourceWatcherService, List<ScriptEngine> scriptEngines, List<ScriptContext.Plugin> customScriptContexts) { ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngineServices); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngines); scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); try { scriptService = new ScriptService(settings, environment, resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index 7a65fee327..b52e135be5 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -92,9 +92,9 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust public static final Setting<Integer> SCRIPT_MAX_COMPILATIONS_PER_MINUTE = Setting.intSetting("script.max_compilations_per_minute", 15, 0, Property.Dynamic, Property.NodeScope); - private final Collection<ScriptEngineService> scriptEngines; - private final Map<String, ScriptEngineService> scriptEnginesByLang; - private final Map<String, ScriptEngineService> scriptEnginesByExt; + private final Collection<ScriptEngine> scriptEngines; + private final Map<String, ScriptEngine> scriptEnginesByLang; + private final Map<String, ScriptEngine> scriptEnginesByExt; private final ConcurrentMap<CacheKey, CompiledScript> staticCache = ConcurrentCollections.newConcurrentMap(); @@ -142,9 +142,9 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire); this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build(); - Map<String, ScriptEngineService> enginesByLangBuilder = new HashMap<>(); - Map<String, ScriptEngineService> enginesByExtBuilder = new HashMap<>(); - for (ScriptEngineService scriptEngine : scriptEngines) { + Map<String, ScriptEngine> enginesByLangBuilder = new HashMap<>(); + Map<String, ScriptEngine> enginesByExtBuilder = new HashMap<>(); + for (ScriptEngine scriptEngine : scriptEngines) { String language = scriptEngineRegistry.getLanguage(scriptEngine.getClass()); enginesByLangBuilder.put(language, scriptEngine); enginesByExtBuilder.put(scriptEngine.getExtension(), scriptEngine); @@ -183,20 +183,20 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust IOUtils.close(scriptEngines); } - private ScriptEngineService getScriptEngineServiceForLang(String lang) { - ScriptEngineService scriptEngineService = scriptEnginesByLang.get(lang); - if (scriptEngineService == null) { + private ScriptEngine getScriptEngineServiceForLang(String lang) { + ScriptEngine scriptEngine = scriptEnginesByLang.get(lang); + if (scriptEngine == null) { throw new IllegalArgumentException("script_lang not supported [" + lang + "]"); } - return scriptEngineService; + return scriptEngine; } - private ScriptEngineService getScriptEngineServiceForFileExt(String fileExtension) { - ScriptEngineService scriptEngineService = scriptEnginesByExt.get(fileExtension); - if (scriptEngineService == null) { + private ScriptEngine getScriptEngineServiceForFileExt(String fileExtension) { + ScriptEngine scriptEngine = scriptEnginesByExt.get(fileExtension); + if (scriptEngine == null) { throw new IllegalArgumentException("script file extension not supported [" + fileExtension + "]"); } - return scriptEngineService; + return scriptEngine; } void setMaxCompilationsPerMinute(Integer newMaxPerMinute) { @@ -258,7 +258,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust " operation [" + scriptContext.getKey() + "] and lang [" + lang + "] are not supported"); } - ScriptEngineService scriptEngineService = getScriptEngineServiceForLang(lang); + ScriptEngine scriptEngine = getScriptEngineServiceForLang(lang); if (canExecuteScript(lang, type, scriptContext) == false) { throw new IllegalStateException("scripts of type [" + script.getType() + "]," + @@ -304,7 +304,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust } // Check whether too many compilations have happened checkCompilationLimit(); - compiledScript = new CompiledScript(type, id, lang, scriptEngineService.compile(id, idOrCode, options)); + compiledScript = new CompiledScript(type, id, lang, scriptEngine.compile(id, idOrCode, options)); } catch (ScriptException good) { // TODO: remove this try-catch completely, when all script engines have good exceptions! throw good; // its already good @@ -404,10 +404,10 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust } try { - ScriptEngineService scriptEngineService = getScriptEngineServiceForLang(source.getLang()); + ScriptEngine scriptEngine = getScriptEngineServiceForLang(source.getLang()); if (isAnyScriptContextEnabled(source.getLang(), ScriptType.STORED)) { - Object compiled = scriptEngineService.compile(request.id(), source.getCode(), Collections.emptyMap()); + Object compiled = scriptEngine.compile(request.id(), source.getCode(), Collections.emptyMap()); if (compiled == null) { throw new IllegalArgumentException("failed to parse/compile stored script [" + request.id() + "]" + @@ -528,7 +528,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust /** * A small listener for the script cache that calls each - * {@code ScriptEngineService}'s {@code scriptRemoved} method when the + * {@code ScriptEngine}'s {@code scriptRemoved} method when the * script has been removed from the cache */ private class ScriptCacheRemovalListener implements RemovalListener<CacheKey, CompiledScript> { @@ -571,7 +571,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust logger.trace("Loading script file : [{}]", file); } - ScriptEngineService engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); + ScriptEngine engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); if (engineService == null) { logger.warn("No script engine found for [{}]", scriptNameExt.v2()); } else { @@ -629,7 +629,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust public void onFileDeleted(Path file) { Tuple<String, String> scriptNameExt = getScriptNameExt(file); if (scriptNameExt != null) { - ScriptEngineService engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); + ScriptEngine engineService = getScriptEngineServiceForFileExt(scriptNameExt.v2()); assert engineService != null; logger.info("removing script file [{}]", file.toAbsolutePath()); staticCache.remove(new CacheKey(engineService.getType(), scriptNameExt.v1(), null)); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java index e4387aa52d..cc928a8b59 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java @@ -72,8 +72,8 @@ public class ScriptSettings { ScriptContextRegistry scriptContextRegistry) { final List<Setting<Boolean>> scriptModeSettings = new ArrayList<>(); - for (final Class<? extends ScriptEngineService> scriptEngineService : scriptEngineRegistry.getRegisteredScriptEngineServices()) { - if (scriptEngineService == NativeScriptEngineService.class) { + for (final Class<? extends ScriptEngine> scriptEngineService : scriptEngineRegistry.getRegisteredScriptEngineServices()) { + if (scriptEngineService == NativeScriptEngine.class) { // native scripts are always enabled, and their settings can not be changed continue; } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptType.java b/core/src/main/java/org/elasticsearch/script/ScriptType.java index 35698e36b4..e8265b644d 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptType.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptType.java @@ -37,7 +37,7 @@ public enum ScriptType implements Writeable { * INLINE scripts are specified in numerous queries and compiled on-the-fly. * They will be cached based on the lang and code of the script. * They are turned off by default because most languages are insecure - * (Groovy and others), but can be overridden by the specific {@link ScriptEngineService} + * (Groovy and others), but can be overridden by the specific {@link ScriptEngine} * if the language is naturally secure (Painless, Mustache, and Expressions). */ INLINE ( 0 , new ParseField("inline") , false ), @@ -46,7 +46,7 @@ public enum ScriptType implements Writeable { * STORED scripts are saved as part of the {@link org.elasticsearch.cluster.ClusterState} * based on user requests. They will be cached when they are first used in a query. * They are turned off by default because most languages are insecure - * (Groovy and others), but can be overridden by the specific {@link ScriptEngineService} + * (Groovy and others), but can be overridden by the specific {@link ScriptEngine} * if the language is naturally secure (Painless, Mustache, and Expressions). */ STORED ( 1 , new ParseField("stored", "id") , false ), @@ -123,7 +123,7 @@ public enum ScriptType implements Writeable { /** * @return Whether or not a {@link ScriptType} can be run by default. Note - * this can be potentially overridden by any {@link ScriptEngineService}. + * this can be potentially overridden by any {@link ScriptEngine}. */ public boolean isDefaultEnabled() { return defaultEnabled; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java index 3d0cf1b5a8..f5bb0e25c6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; public class InternalRange<B extends InternalRange.Bucket, R extends InternalRange<B, R>> extends InternalMultiBucketAggregation<R, B> implements Range { @@ -172,6 +173,27 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan @Override public void writeTo(StreamOutput out) throws IOException { } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null || getClass() != other.getClass()) { + return false; + } + Bucket that = (Bucket) other; + return Objects.equals(from, that.from) + && Objects.equals(to, that.to) + && Objects.equals(docCount, that.docCount) + && Objects.equals(aggregations, that.aggregations) + && Objects.equals(key, that.key); + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), from, to, docCount, aggregations, key); + } } public static class Factory<B extends Bucket, R extends InternalRange<B, R>> { @@ -245,8 +267,8 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan out.writeVInt(ranges.size()); for (B bucket : ranges) { out.writeOptionalString(((Bucket) bucket).key); - out.writeDouble(((Bucket) bucket).from); - out.writeDouble(((Bucket) bucket).to); + out.writeDouble(bucket.from); + out.writeDouble(bucket.to); out.writeVLong(((Bucket) bucket).docCount); bucket.aggregations.writeTo(out); } @@ -317,4 +339,16 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan return builder; } + @Override + protected int doHashCode() { + return Objects.hash(ranges, format, keyed); + } + + @Override + protected boolean doEquals(Object obj) { + InternalRange<?,?> that = (InternalRange<?,?>) obj; + return Objects.equals(ranges, that.ranges) + && Objects.equals(format, that.format) + && Objects.equals(keyed, that.keyed); + } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java b/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java deleted file mode 100644 index 5d86602c4c..0000000000 --- a/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeTestCase.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.index.mapper; - -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.elasticsearch.Version; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.analysis.AnalyzerScope; -import org.elasticsearch.index.analysis.NamedAnalyzer; -import org.elasticsearch.index.similarity.BM25SimilarityProvider; -import org.elasticsearch.test.ESTestCase; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** Base test case for subclasses of MappedFieldType */ -public abstract class FieldTypeTestCase extends ESTestCase { - - private static final Settings INDEX_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); - - /** Abstraction for mutating a property of a MappedFieldType */ - public abstract static class Modifier { - /** The name of the property that is being modified. Used in test failure messages. */ - public final String property; - /** true if this modifier only makes types incompatible in strict mode, false otherwise */ - public final boolean strictOnly; - - public Modifier(String property, boolean strictOnly) { - this.property = property; - this.strictOnly = strictOnly; - } - - /** Modifies the property */ - public abstract void modify(MappedFieldType ft); - /** - * Optional method to implement that allows the field type that will be compared to be modified, - * so that it does not have the default value for the property being modified. - */ - public void normalizeOther(MappedFieldType other) {} - } - - private final List<Modifier> modifiers = new ArrayList<>(Arrays.asList( - new Modifier("boost", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setBoost(1.1f); - } - }, - new Modifier("doc_values", false) { - @Override - public void modify(MappedFieldType ft) { - ft.setHasDocValues(ft.hasDocValues() == false); - } - }, - new Modifier("analyzer", false) { - @Override - public void modify(MappedFieldType ft) { - ft.setIndexAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("analyzer", false) { - @Override - public void modify(MappedFieldType ft) { - ft.setIndexAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - @Override - public void normalizeOther(MappedFieldType other) { - other.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("search_analyzer", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setSearchAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("search_analyzer", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setSearchAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - @Override - public void normalizeOther(MappedFieldType other) { - other.setSearchAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("search_quote_analyzer", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setSearchQuoteAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("search_quote_analyzer", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setSearchQuoteAnalyzer(new NamedAnalyzer("bar", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - @Override - public void normalizeOther(MappedFieldType other) { - other.setSearchQuoteAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.INDEX, new StandardAnalyzer())); - } - }, - new Modifier("similarity", false) { - @Override - public void modify(MappedFieldType ft) { - ft.setSimilarity(new BM25SimilarityProvider("foo", Settings.EMPTY, INDEX_SETTINGS)); - } - }, - new Modifier("similarity", false) { - @Override - public void modify(MappedFieldType ft) { - ft.setSimilarity(new BM25SimilarityProvider("foo", Settings.EMPTY, INDEX_SETTINGS)); - } - @Override - public void normalizeOther(MappedFieldType other) { - other.setSimilarity(new BM25SimilarityProvider("bar", Settings.EMPTY, INDEX_SETTINGS)); - } - }, - new Modifier("eager_global_ordinals", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setEagerGlobalOrdinals(ft.eagerGlobalOrdinals() == false); - } - }, - new Modifier("null_value", true) { - @Override - public void modify(MappedFieldType ft) { - ft.setNullValue(dummyNullValue); - } - } - )); - - /** - * Add a mutation that will be tested for all expected semantics of equality and compatibility. - * These should be added in an @Before method. - */ - protected void addModifier(Modifier modifier) { - modifiers.add(modifier); - } - - private Object dummyNullValue = "dummyvalue"; - - /** Sets the null value used by the modifier for null value testing. This should be set in an @Before method. */ - protected void setDummyNullValue(Object value) { - dummyNullValue = value; - } - - /** Create a default constructed fieldtype */ - protected abstract MappedFieldType createDefaultFieldType(); - - MappedFieldType createNamedDefaultFieldType() { - MappedFieldType fieldType = createDefaultFieldType(); - fieldType.setName("foo"); - return fieldType; - } - - // TODO: remove this once toString is no longer final on FieldType... - protected void assertFieldTypeEquals(String property, MappedFieldType ft1, MappedFieldType ft2) { - if (ft1.equals(ft2) == false) { - fail("Expected equality, testing property " + property + "\nexpected: " + toString(ft1) + "; \nactual: " + toString(ft2) + "\n"); - } - } - - protected void assertFieldTypeNotEquals(String property, MappedFieldType ft1, MappedFieldType ft2) { - if (ft1.equals(ft2)) { - fail("Expected inequality, testing property " + property + "\nfirst: " + toString(ft1) + "; \nsecond: " + toString(ft2) + "\n"); - } - } - - protected void assertCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict) { - List<String> conflicts = new ArrayList<>(); - ft1.checkCompatibility(ft2, conflicts, strict); - assertTrue("Found conflicts for " + msg + ": " + conflicts, conflicts.isEmpty()); - } - - protected void assertNotCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict, String... messages) { - assert messages.length != 0; - List<String> conflicts = new ArrayList<>(); - ft1.checkCompatibility(ft2, conflicts, strict); - for (String message : messages) { - boolean found = false; - for (String conflict : conflicts) { - if (conflict.contains(message)) { - found = true; - } - } - assertTrue("Missing conflict for " + msg + ": [" + message + "] in conflicts " + conflicts, found); - } - } - - protected String toString(MappedFieldType ft) { - return "MappedFieldType{" + - "name=" + ft.name() + - ", boost=" + ft.boost() + - ", docValues=" + ft.hasDocValues() + - ", indexAnalyzer=" + ft.indexAnalyzer() + - ", searchAnalyzer=" + ft.searchAnalyzer() + - ", searchQuoteAnalyzer=" + ft.searchQuoteAnalyzer() + - ", similarity=" + ft.similarity() + - ", eagerGlobalOrdinals=" + ft.eagerGlobalOrdinals() + - ", nullValue=" + ft.nullValue() + - ", nullValueAsString='" + ft.nullValueAsString() + "'" + - "} " + super.toString(); - } - - public void testClone() { - MappedFieldType fieldType = createNamedDefaultFieldType(); - MappedFieldType clone = fieldType.clone(); - assertNotSame(clone, fieldType); - assertEquals(clone.getClass(), fieldType.getClass()); - assertEquals(clone, fieldType); - assertEquals(clone, clone.clone()); // transitivity - - for (Modifier modifier : modifiers) { - fieldType = createNamedDefaultFieldType(); - modifier.modify(fieldType); - clone = fieldType.clone(); - assertNotSame(clone, fieldType); - assertFieldTypeEquals(modifier.property, clone, fieldType); - } - } - - public void testEquals() { - MappedFieldType ft1 = createNamedDefaultFieldType(); - MappedFieldType ft2 = createNamedDefaultFieldType(); - assertEquals(ft1, ft1); // reflexive - assertEquals(ft1, ft2); // symmetric - assertEquals(ft2, ft1); - assertEquals(ft1.hashCode(), ft2.hashCode()); - - for (Modifier modifier : modifiers) { - ft1 = createNamedDefaultFieldType(); - ft2 = createNamedDefaultFieldType(); - modifier.modify(ft2); - assertFieldTypeNotEquals(modifier.property, ft1, ft2); - assertNotEquals("hash code for modified property " + modifier.property, ft1.hashCode(), ft2.hashCode()); - // modify the same property and they are equal again - modifier.modify(ft1); - assertFieldTypeEquals(modifier.property, ft1, ft2); - assertEquals("hash code for modified property " + modifier.property, ft1.hashCode(), ft2.hashCode()); - } - } - - public void testFreeze() { - for (Modifier modifier : modifiers) { - MappedFieldType fieldType = createNamedDefaultFieldType(); - fieldType.freeze(); - try { - modifier.modify(fieldType); - fail("expected already frozen exception for property " + modifier.property); - } catch (IllegalStateException e) { - assertTrue(e.getMessage().contains("already frozen")); - } - } - } - - public void testCheckTypeName() { - final MappedFieldType fieldType = createNamedDefaultFieldType(); - List<String> conflicts = new ArrayList<>(); - fieldType.checkCompatibility(fieldType, conflicts, random().nextBoolean()); // no exception - assertTrue(conflicts.toString(), conflicts.isEmpty()); - - MappedFieldType bogus = new TermBasedFieldType() { - @Override - public MappedFieldType clone() {return null;} - @Override - public String typeName() { return fieldType.typeName();} - }; - try { - fieldType.checkCompatibility(bogus, conflicts, random().nextBoolean()); - fail("expected bad types exception"); - } catch (IllegalStateException e) { - assertTrue(e.getMessage().contains("Type names equal")); - } - assertTrue(conflicts.toString(), conflicts.isEmpty()); - - MappedFieldType other = new TermBasedFieldType() { - @Override - public MappedFieldType clone() {return null;} - @Override - public String typeName() { return "othertype";} - }; - try { - fieldType.checkCompatibility(other, conflicts, random().nextBoolean()); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage(), e.getMessage().contains("cannot be changed from type")); - } - assertTrue(conflicts.toString(), conflicts.isEmpty()); - } - - public void testCheckCompatibility() { - MappedFieldType ft1 = createNamedDefaultFieldType(); - MappedFieldType ft2 = createNamedDefaultFieldType(); - assertCompatible("default", ft1, ft2, true); - assertCompatible("default", ft1, ft2, false); - assertCompatible("default", ft2, ft1, true); - assertCompatible("default", ft2, ft1, false); - - for (Modifier modifier : modifiers) { - ft1 = createNamedDefaultFieldType(); - ft2 = createNamedDefaultFieldType(); - modifier.normalizeOther(ft1); - modifier.modify(ft2); - if (modifier.strictOnly) { - String[] conflicts = { - "mapper [foo] is used by multiple types", - "update [" + modifier.property + "]" - }; - assertCompatible(modifier.property, ft1, ft2, false); - assertNotCompatible(modifier.property, ft1, ft2, true, conflicts); - assertCompatible(modifier.property, ft2, ft1, false); // always symmetric when not strict - assertNotCompatible(modifier.property, ft2, ft1, true, conflicts); - } else { - // not compatible whether strict or not - String conflict = "different [" + modifier.property + "]"; - assertNotCompatible(modifier.property, ft1, ft2, true, conflict); - assertNotCompatible(modifier.property, ft1, ft2, false, conflict); - assertNotCompatible(modifier.property, ft2, ft1, true, conflict); - assertNotCompatible(modifier.property, ft2, ft1, false, conflict); - } - } - } -} diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 0dfda8f7a1..7f56f3de4b 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -47,11 +47,11 @@ public class NativeScriptTests extends ESTestCase { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); ScriptModule scriptModule = new ScriptModule(settings, new Environment(settings), null, - singletonList(new NativeScriptEngineService(settings, singletonMap("my", new MyNativeScriptFactory()))), emptyList()); + singletonList(new NativeScriptEngine(settings, singletonMap("my", new MyNativeScriptFactory()))), emptyList()); List<Setting<?>> scriptSettings = scriptModule.getSettings(); scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED); - Script script = new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "my", Collections.emptyMap()); + Script script = new Script(ScriptType.INLINE, NativeScriptEngine.NAME, "my", Collections.emptyMap()); CompiledScript compiledScript = scriptModule.getScriptService().compile(script, ScriptContext.Standard.SEARCH); ExecutableScript executable = scriptModule.getScriptService().executable(compiledScript, script.getParams()); assertThat(executable.run().toString(), equalTo("test")); @@ -71,7 +71,7 @@ public class NativeScriptTests extends ESTestCase { ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null); Map<String, NativeScriptFactory> nativeScriptFactoryMap = new HashMap<>(); nativeScriptFactoryMap.put("my", new MyNativeScriptFactory()); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(new NativeScriptEngineService(settings, + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(new NativeScriptEngine(settings, nativeScriptFactoryMap))); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList<>()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); @@ -79,7 +79,7 @@ public class NativeScriptTests extends ESTestCase { scriptContextRegistry, scriptSettings); for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) { - assertThat(scriptService.compile(new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "my", Collections.emptyMap()), + assertThat(scriptService.compile(new Script(ScriptType.INLINE, NativeScriptEngine.NAME, "my", Collections.emptyMap()), scriptContext), notNullValue()); } } diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index 2289e040f5..a2db206858 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -43,7 +43,7 @@ public class ScriptModesTests extends ESTestCase { ScriptSettings scriptSettings; ScriptContextRegistry scriptContextRegistry; private ScriptContext[] scriptContexts; - private Map<String, ScriptEngineService> scriptEngines; + private Map<String, ScriptEngine> scriptEngines; private ScriptModes scriptModes; private Set<String> checkedSettings; private boolean assertAllSettingsWereChecked; @@ -65,8 +65,8 @@ public class ScriptModesTests extends ESTestCase { scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]); scriptEngines = buildScriptEnginesByLangMap(newHashSet( //add the native engine just to make sure it gets filtered out - new NativeScriptEngineService(Settings.EMPTY, Collections.<String, NativeScriptFactory>emptyMap()), - new CustomScriptEngineService())); + new NativeScriptEngine(Settings.EMPTY, Collections.<String, NativeScriptFactory>emptyMap()), + new CustomScriptEngine())); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngines.values()); scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); checkedSettings = new HashSet<>(); @@ -77,7 +77,7 @@ public class ScriptModesTests extends ESTestCase { @After public void assertNativeScriptsAreAlwaysAllowed() { if (assertScriptModesNonNull) { - assertThat(scriptModes.getScriptEnabled(NativeScriptEngineService.NAME, randomFrom(ScriptType.values()), randomFrom(scriptContexts)), equalTo(true)); + assertThat(scriptModes.getScriptEnabled(NativeScriptEngine.NAME, randomFrom(ScriptType.values()), randomFrom(scriptContexts)), equalTo(true)); } } @@ -216,16 +216,16 @@ public class ScriptModesTests extends ESTestCase { return copy.values().toArray(new ScriptContext[copy.size()]); } - static Map<String, ScriptEngineService> buildScriptEnginesByLangMap(Set<ScriptEngineService> scriptEngines) { - Map<String, ScriptEngineService> builder = new HashMap<>(); - for (ScriptEngineService scriptEngine : scriptEngines) { + static Map<String, ScriptEngine> buildScriptEnginesByLangMap(Set<ScriptEngine> scriptEngines) { + Map<String, ScriptEngine> builder = new HashMap<>(); + for (ScriptEngine scriptEngine : scriptEngines) { String type = scriptEngine.getType(); builder.put(type, scriptEngine); } return unmodifiableMap(builder); } - private static class CustomScriptEngineService implements ScriptEngineService { + private static class CustomScriptEngine implements ScriptEngine { public static final String NAME = "custom"; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 026751f644..6928d56548 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -55,9 +55,9 @@ import static org.hamcrest.Matchers.sameInstance; public class ScriptServiceTests extends ESTestCase { private ResourceWatcherService resourceWatcherService; - private ScriptEngineService scriptEngineService; - private ScriptEngineService dangerousScriptEngineService; - private Map<String, ScriptEngineService> scriptEnginesByLangMap; + private ScriptEngine scriptEngine; + private ScriptEngine dangerousScriptEngine; + private Map<String, ScriptEngine> scriptEnginesByLangMap; private ScriptEngineRegistry scriptEngineRegistry; private ScriptContextRegistry scriptContextRegistry; private ScriptSettings scriptSettings; @@ -83,11 +83,11 @@ public class ScriptServiceTests extends ESTestCase { .put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 10000) .build(); resourceWatcherService = new ResourceWatcherService(baseSettings, null); - scriptEngineService = new TestEngineService(); - dangerousScriptEngineService = new TestDangerousEngineService(); - TestEngineService defaultScriptServiceEngine = new TestEngineService(Script.DEFAULT_SCRIPT_LANG) {}; + scriptEngine = new TestEngine(); + dangerousScriptEngine = new TestDangerousEngine(); + TestEngine defaultScriptServiceEngine = new TestEngine(Script.DEFAULT_SCRIPT_LANG) {}; scriptEnginesByLangMap = ScriptModesTests.buildScriptEnginesByLangMap( - new HashSet<>(Arrays.asList(scriptEngineService, defaultScriptServiceEngine))); + new HashSet<>(Arrays.asList(scriptEngine, defaultScriptServiceEngine))); //randomly register custom script contexts int randomInt = randomIntBetween(0, 3); //prevent duplicates using map @@ -104,7 +104,7 @@ public class ScriptServiceTests extends ESTestCase { String context = plugin + "_" + operation; contexts.put(context, new ScriptContext.Plugin(plugin, operation)); } - scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(scriptEngineService, dangerousScriptEngineService, + scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(scriptEngine, dangerousScriptEngine, defaultScriptServiceEngine)); scriptContextRegistry = new ScriptContextRegistry(contexts.values()); scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); @@ -259,7 +259,7 @@ public class ScriptServiceTests extends ESTestCase { do { ScriptType scriptType = randomFrom(ScriptType.values()); ScriptContext scriptContext = randomFrom(this.scriptContexts); - settingKey = scriptEngineService.getType() + "." + scriptType + "." + scriptContext.getKey(); + settingKey = scriptEngine.getType() + "." + scriptType + "." + scriptContext.getKey(); } while (engineSettings.containsKey(settingKey)); engineSettings.put(settingKey, randomBoolean()); } @@ -301,7 +301,7 @@ public class ScriptServiceTests extends ESTestCase { String script = scriptType == ScriptType.FILE ? "file_script" : "script"; for (ScriptContext scriptContext : this.scriptContexts) { //fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings - Boolean scriptEnabled = engineSettings.get(dangerousScriptEngineService.getType() + "." + scriptType + "." + scriptContext.getKey()); + Boolean scriptEnabled = engineSettings.get(dangerousScriptEngine.getType() + "." + scriptType + "." + scriptContext.getKey()); if (scriptEnabled == null) { scriptEnabled = scriptContextSettings.get(scriptContext); } @@ -312,7 +312,7 @@ public class ScriptServiceTests extends ESTestCase { scriptEnabled = DEFAULT_SCRIPT_ENABLED.get(scriptType); } - String lang = dangerousScriptEngineService.getType(); + String lang = dangerousScriptEngine.getType(); if (scriptEnabled) { assertCompileAccepted(lang, script, scriptType, scriptContext); } else { @@ -332,7 +332,7 @@ public class ScriptServiceTests extends ESTestCase { unknownContext = randomAlphaOfLength(randomIntBetween(1, 30)); } while(scriptContextRegistry.isSupportedContext(new ScriptContext.Plugin(pluginName, unknownContext))); - String type = scriptEngineService.getType(); + String type = scriptEngine.getType(); try { scriptService.compile(new Script(randomFrom(ScriptType.values()), type, "test", Collections.emptyMap()), new ScriptContext.Plugin(pluginName, unknownContext)); @@ -482,17 +482,17 @@ public class ScriptServiceTests extends ESTestCase { ); } - public static class TestEngineService implements ScriptEngineService { + public static class TestEngine implements ScriptEngine { public static final String NAME = "test"; private final String name; - public TestEngineService() { + public TestEngine() { this(NAME); } - public TestEngineService(String name) { + public TestEngine(String name) { this.name = name; } @@ -532,7 +532,7 @@ public class ScriptServiceTests extends ESTestCase { } } - public static class TestDangerousEngineService implements ScriptEngineService { + public static class TestDangerousEngine implements ScriptEngine { public static final String NAME = "dtest"; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java index abda0376a2..6eea1fa801 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java @@ -29,14 +29,13 @@ import java.util.Collections; import java.util.Iterator; import java.util.Map; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; public class ScriptSettingsTests extends ESTestCase { public void testSettingsAreProperlyPropogated() { ScriptEngineRegistry scriptEngineRegistry = - new ScriptEngineRegistry(Collections.singletonList(new CustomScriptEngineService())); + new ScriptEngineRegistry(Collections.singletonList(new CustomScriptEngine())); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); boolean enabled = randomBoolean(); @@ -50,7 +49,7 @@ public class ScriptSettingsTests extends ESTestCase { } } - private static class CustomScriptEngineService implements ScriptEngineService { + private static class CustomScriptEngine implements ScriptEngine { public static final String NAME = "custom"; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java deleted file mode 100644 index a766dcbf5c..0000000000 --- a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.aggregations; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.MockBigArrays; -import org.elasticsearch.common.xcontent.ContextParser; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentParserUtils; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; -import org.elasticsearch.rest.action.search.RestSearchAction; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.SearchModule; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; -import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram; -import org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram; -import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms; -import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; -import org.elasticsearch.search.aggregations.bucket.terms.ParsedDoubleTerms; -import org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms; -import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms; -import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.avg.ParsedAvg; -import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.cardinality.ParsedCardinality; -import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.geobounds.ParsedGeoBounds; -import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.geocentroid.ParsedGeoCentroid; -import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.max.ParsedMax; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.min.ParsedMin; -import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks; -import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentiles; -import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.ParsedHDRPercentileRanks; -import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.ParsedHDRPercentiles; -import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks; -import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles; -import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.ParsedTDigestPercentileRanks; -import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.ParsedTDigestPercentiles; -import org.elasticsearch.search.aggregations.metrics.stats.ParsedStats; -import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.stats.extended.ParsedExtendedStats; -import org.elasticsearch.search.aggregations.metrics.sum.ParsedSum; -import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.valuecount.ParsedValueCount; -import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder; -import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; -import org.elasticsearch.search.aggregations.pipeline.ParsedSimpleValue; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.ParsedBucketMetricValue; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.ParsedPercentilesBucket; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.ParsedStatsBucket; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregationBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ParsedExtendedStatsBucket; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder; -import org.elasticsearch.search.aggregations.pipeline.derivative.ParsedDerivative; -import org.elasticsearch.test.AbstractWireSerializingTestCase; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonMap; -import static org.elasticsearch.common.xcontent.XContentHelper.toXContent; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; - -public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractWireSerializingTestCase<T> { - - private final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry( - new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables()); - - private final NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(getNamedXContents()); - - static List<NamedXContentRegistry.Entry> getNamedXContents() { - Map<String, ContextParser<Object, ? extends Aggregation>> namedXContents = new HashMap<>(); - namedXContents.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c)); - namedXContents.put(InternalHDRPercentiles.NAME, (p, c) -> ParsedHDRPercentiles.fromXContent(p, (String) c)); - namedXContents.put(InternalHDRPercentileRanks.NAME, (p, c) -> ParsedHDRPercentileRanks.fromXContent(p, (String) c)); - namedXContents.put(InternalTDigestPercentiles.NAME, (p, c) -> ParsedTDigestPercentiles.fromXContent(p, (String) c)); - namedXContents.put(InternalTDigestPercentileRanks.NAME, (p, c) -> ParsedTDigestPercentileRanks.fromXContent(p, (String) c)); - namedXContents.put(PercentilesBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedPercentilesBucket.fromXContent(p, (String) c)); - namedXContents.put(MinAggregationBuilder.NAME, (p, c) -> ParsedMin.fromXContent(p, (String) c)); - namedXContents.put(MaxAggregationBuilder.NAME, (p, c) -> ParsedMax.fromXContent(p, (String) c)); - namedXContents.put(SumAggregationBuilder.NAME, (p, c) -> ParsedSum.fromXContent(p, (String) c)); - namedXContents.put(AvgAggregationBuilder.NAME, (p, c) -> ParsedAvg.fromXContent(p, (String) c)); - namedXContents.put(ValueCountAggregationBuilder.NAME, (p, c) -> ParsedValueCount.fromXContent(p, (String) c)); - namedXContents.put(InternalSimpleValue.NAME, (p, c) -> ParsedSimpleValue.fromXContent(p, (String) c)); - namedXContents.put(DerivativePipelineAggregationBuilder.NAME, (p, c) -> ParsedDerivative.fromXContent(p, (String) c)); - namedXContents.put(InternalBucketMetricValue.NAME, (p, c) -> ParsedBucketMetricValue.fromXContent(p, (String) c)); - namedXContents.put(StatsAggregationBuilder.NAME, (p, c) -> ParsedStats.fromXContent(p, (String) c)); - namedXContents.put(StatsBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedStatsBucket.fromXContent(p, (String) c)); - namedXContents.put(ExtendedStatsAggregationBuilder.NAME, (p, c) -> ParsedExtendedStats.fromXContent(p, (String) c)); - namedXContents.put(ExtendedStatsBucketPipelineAggregationBuilder.NAME, - (p, c) -> ParsedExtendedStatsBucket.fromXContent(p, (String) c)); - namedXContents.put(GeoBoundsAggregationBuilder.NAME, (p, c) -> ParsedGeoBounds.fromXContent(p, (String) c)); - namedXContents.put(GeoCentroidAggregationBuilder.NAME, (p, c) -> ParsedGeoCentroid.fromXContent(p, (String) c)); - namedXContents.put(HistogramAggregationBuilder.NAME, (p, c) -> ParsedHistogram.fromXContent(p, (String) c)); - namedXContents.put(DateHistogramAggregationBuilder.NAME, (p, c) -> ParsedDateHistogram.fromXContent(p, (String) c)); - namedXContents.put(StringTerms.NAME, (p, c) -> ParsedStringTerms.fromXContent(p, (String) c)); - namedXContents.put(LongTerms.NAME, (p, c) -> ParsedLongTerms.fromXContent(p, (String) c)); - namedXContents.put(DoubleTerms.NAME, (p, c) -> ParsedDoubleTerms.fromXContent(p, (String) c)); - - return namedXContents.entrySet().stream() - .map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())) - .collect(Collectors.toList()); - } - - protected abstract T createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData); - - /** Return an instance on an unmapped field. */ - protected T createUnmappedInstance(String name, - List<PipelineAggregator> pipelineAggregators, - Map<String, Object> metaData) { - // For most impls, we use the same instance in the unmapped case and in the mapped case - return createTestInstance(name, pipelineAggregators, metaData); - } - - public void testReduceRandom() { - String name = randomAlphaOfLength(5); - List<T> inputs = new ArrayList<>(); - List<InternalAggregation> toReduce = new ArrayList<>(); - int toReduceSize = between(1, 200); - for (int i = 0; i < toReduceSize; i++) { - T t = randomBoolean() ? createUnmappedInstance(name) : createTestInstance(name); - inputs.add(t); - toReduce.add(t); - } - ScriptService mockScriptService = mockScriptService(); - MockBigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); - if (randomBoolean() && toReduce.size() > 1) { - // sometimes do an incremental reduce - Collections.shuffle(toReduce, random()); - int r = randomIntBetween(1, toReduceSize); - List<InternalAggregation> internalAggregations = toReduce.subList(0, r); - InternalAggregation.ReduceContext context = - new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false); - @SuppressWarnings("unchecked") - T reduced = (T) inputs.get(0).reduce(internalAggregations, context); - toReduce = new ArrayList<>(toReduce.subList(r, toReduceSize)); - toReduce.add(reduced); - } - InternalAggregation.ReduceContext context = - new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true); - @SuppressWarnings("unchecked") - T reduced = (T) inputs.get(0).reduce(toReduce, context); - assertReduced(reduced, inputs); - } - - /** - * overwrite in tests that need it - */ - protected ScriptService mockScriptService() { - return null; - } - - protected abstract void assertReduced(T reduced, List<T> inputs); - - @Override - protected final T createTestInstance() { - return createTestInstance(randomAlphaOfLength(5)); - } - - private T createTestInstance(String name) { - List<PipelineAggregator> pipelineAggregators = new ArrayList<>(); - // TODO populate pipelineAggregators - Map<String, Object> metaData = null; - if (randomBoolean()) { - metaData = new HashMap<>(); - int metaDataCount = between(0, 10); - while (metaData.size() < metaDataCount) { - metaData.put(randomAlphaOfLength(5), randomAlphaOfLength(5)); - } - } - return createTestInstance(name, pipelineAggregators, metaData); - } - - /** Return an instance on an unmapped field. */ - protected final T createUnmappedInstance(String name) { - List<PipelineAggregator> pipelineAggregators = new ArrayList<>(); - // TODO populate pipelineAggregators - Map<String, Object> metaData = new HashMap<>(); - int metaDataCount = randomBoolean() ? 0 : between(1, 10); - while (metaData.size() < metaDataCount) { - metaData.put(randomAlphaOfLength(5), randomAlphaOfLength(5)); - } - return createUnmappedInstance(name, pipelineAggregators, metaData); - } - - @Override - protected NamedWriteableRegistry getNamedWriteableRegistry() { - return namedWriteableRegistry; - } - - @Override - protected NamedXContentRegistry xContentRegistry() { - return namedXContentRegistry; - } - - public final void testFromXContent() throws IOException { - final T aggregation = createTestInstance(); - - //norelease Remove this assumption when all aggregations can be parsed back. - assumeTrue("This test does not support the aggregation type yet", - getNamedXContents().stream().filter(entry -> entry.name.match(aggregation.getType())).count() > 0); - - final Aggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean()); - assertFromXContent(aggregation, (ParsedAggregation) parsedAggregation); - } - - //norelease TODO make abstract - protected void assertFromXContent(T aggregation, ParsedAggregation parsedAggregation) { - } - - @SuppressWarnings("unchecked") - protected <P extends ParsedAggregation> P parseAndAssert(final InternalAggregation aggregation, - final boolean shuffled) throws IOException { - - final ToXContent.Params params = new ToXContent.MapParams(singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true")); - final XContentType xContentType = randomFrom(XContentType.values()); - final boolean humanReadable = randomBoolean(); - - final BytesReference originalBytes; - if (shuffled) { - originalBytes = toShuffledXContent(aggregation, xContentType, params, humanReadable); - } else { - originalBytes = toXContent(aggregation, xContentType, params, humanReadable); - } - - Aggregation parsedAggregation; - try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) { - assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); - assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); - - parsedAggregation = XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class); - - assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken()); - assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); - assertNull(parser.nextToken()); - - assertEquals(aggregation.getName(), parsedAggregation.getName()); - assertEquals(aggregation.getMetaData(), parsedAggregation.getMetaData()); - - assertTrue(parsedAggregation instanceof ParsedAggregation); - assertEquals(aggregation.getType(), ((ParsedAggregation) parsedAggregation).getType()); - } - - BytesReference parsedBytes = toXContent(parsedAggregation, xContentType, params, humanReadable); - assertToXContentEquivalent(originalBytes, parsedBytes, xContentType); - - return (P) parsedAggregation; - } - - /** - * @return a random {@link DocValueFormat} that can be used in aggregations which - * compute numbers. - */ - protected static DocValueFormat randomNumericDocValueFormat() { - final List<Supplier<DocValueFormat>> formats = new ArrayList<>(3); - formats.add(() -> DocValueFormat.RAW); - formats.add(() -> new DocValueFormat.Decimal(randomFrom("###.##", "###,###.##"))); - return randomFrom(formats).get(); - } -} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregationTestCase.java index a31b28e7fd..f84a364ab1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/InternalSingleBucketAggregationTestCase.java @@ -20,11 +20,11 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.InternalAggregation; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.metrics.max.InternalMax; import org.elasticsearch.search.aggregations.metrics.min.InternalMin; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.ArrayList; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGridTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGridTests.java index ace22b244a..a27b47946f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGridTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGridTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.search.aggregations.bucket.geogrid; import org.apache.lucene.index.IndexWriter; import org.elasticsearch.common.geo.GeoHashUtils; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.ArrayList; import java.util.HashMap; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogramTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogramTests.java index 0b71d138a5..50cb453049 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogramTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogramTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalMultiBucketAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import org.joda.time.DateTime; import java.util.ArrayList; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogramTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogramTests.java index 4f0fea87d6..b4ecf828e7 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogramTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogramTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalMultiBucketAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.ArrayList; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRangeTests.java index 2f8d4f9e65..6d83b74c82 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRangeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRangeTests.java @@ -22,9 +22,9 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import org.junit.Before; import java.util.ArrayList; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTestCase.java new file mode 100644 index 0000000000..1edaea2f8e --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTestCase.java @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range; + +import org.elasticsearch.search.aggregations.InternalAggregation; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; +import org.junit.Before; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public abstract class InternalRangeTestCase<T extends InternalAggregation & Range> extends InternalAggregationTestCase<T> { + + private boolean keyed; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + keyed = randomBoolean(); + } + + @Override + protected T createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) { + return createTestInstance(name, pipelineAggregators, metaData, keyed); + } + + protected abstract T createTestInstance(String name, + List<PipelineAggregator> pipelineAggregators, + Map<String, Object> metaData, + boolean keyed); + @Override + protected void assertReduced(T reduced, List<T> inputs) { + final Map<String, Long> expectedCounts = new TreeMap<>(); + for (T input : inputs) { + for (Range.Bucket bucket : input.getBuckets()) { + expectedCounts.compute(bucket.getKeyAsString(), + (key, oldValue) -> (oldValue == null ? 0 : oldValue) + bucket.getDocCount()); + + } + } + final Map<String, Long> actualCounts = new TreeMap<>(); + for (Range.Bucket bucket : reduced.getBuckets()) { + actualCounts.compute(bucket.getKeyAsString(), + (key, oldValue) -> (oldValue == null ? 0 : oldValue) + bucket.getDocCount()); + } + assertEquals(expectedCounts, actualCounts); + } +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java new file mode 100644 index 0000000000..9264028d07 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/InternalRangeTests.java @@ -0,0 +1,82 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range; + +import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregations; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class InternalRangeTests extends InternalRangeTestCase<InternalRange> { + + private DocValueFormat format; + private List<Tuple<Double, Double>> ranges; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + format = randomNumericDocValueFormat(); + + final int interval = randomFrom(1, 5, 10, 25, 50, 100); + final int numRanges = 1;//randomIntBetween(1, 10); + + List<Tuple<Double, Double>> listOfRanges = new ArrayList<>(numRanges); + for (int i = 0; i < numRanges; i++) { + double from = i * interval; + double to = from + interval; + listOfRanges.add(Tuple.tuple(from, to)); + } + if (randomBoolean()) { + // Add some overlapping ranges + double max = (double) numRanges * interval; + listOfRanges.add(Tuple.tuple(0.0, max)); + listOfRanges.add(Tuple.tuple(0.0, max / 2)); + listOfRanges.add(Tuple.tuple(max / 3, max / 3 * 2)); + } + ranges = Collections.unmodifiableList(listOfRanges); + } + + @Override + protected InternalRange createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData, + boolean keyed) { + final List<InternalRange.Bucket> buckets = new ArrayList<>(); + for (int i = 0; i < ranges.size(); ++i) { + Tuple<Double, Double> range = ranges.get(i); + int docCount = randomIntBetween(0, 1000); + double from = range.v1(); + double to = range.v2(); + buckets.add( new InternalRange.Bucket("range_" + i, from, to, docCount, InternalAggregations.EMPTY, keyed, format)); + } + return new InternalRange<>(name, buckets, format, keyed, pipelineAggregators, Collections.emptyMap()); + } + + @Override + protected Writeable.Reader<InternalRange> instanceReader() { + return InternalRange::new; + } +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/date/InternalDateRangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/date/InternalDateRangeTests.java new file mode 100644 index 0000000000..bbfcdf7463 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/date/InternalDateRangeTests.java @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range.date; + +import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregations; +import org.elasticsearch.search.aggregations.bucket.range.InternalRangeTestCase; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public class InternalDateRangeTests extends InternalRangeTestCase<InternalDateRange> { + + private DocValueFormat format; + private List<Tuple<Double, Double>> dateRanges; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + format = randomNumericDocValueFormat(); + + Function<DateTime, DateTime> interval = randomFrom(dateTime -> dateTime.plusSeconds(1), dateTime -> dateTime.plusMinutes(1), + dateTime -> dateTime.plusHours(1), dateTime -> dateTime.plusDays(1), dateTime -> dateTime.plusMonths(1), dateTime -> + dateTime.plusYears(1)); + + final int numRanges = randomIntBetween(1, 10); + final List<Tuple<Double, Double>> listOfRanges = new ArrayList<>(numRanges); + + DateTime date = new DateTime(DateTimeZone.UTC); + double start = date.getMillis(); + double end = 0; + for (int i = 0; i < numRanges; i++) { + double from = date.getMillis(); + date = interval.apply(date); + double to = date.getMillis(); + listOfRanges.add(Tuple.tuple(from, to)); + if (to > end) { + end = to; + } + } + if (randomBoolean()) { + final int randomOverlaps = randomIntBetween(1, 5); + for (int i = 0; i < randomOverlaps; i++) { + listOfRanges.add(Tuple.tuple(start, randomDoubleBetween(start, end, false))); + } + } + dateRanges = Collections.unmodifiableList(listOfRanges); + } + + @Override + protected InternalDateRange createTestInstance(String name, + List<PipelineAggregator> pipelineAggregators, + Map<String, Object> metaData, + boolean keyed) { + final List<InternalDateRange.Bucket> buckets = new ArrayList<>(); + for (int i = 0; i < dateRanges.size(); ++i) { + Tuple<Double, Double> range = dateRanges.get(i); + int docCount = randomIntBetween(0, 1000); + double from = range.v1(); + double to = range.v2(); + buckets.add( new InternalDateRange.Bucket("range_" + i, from, to, docCount, InternalAggregations.EMPTY, keyed, format)); + } + return new InternalDateRange(name, buckets, format, keyed, pipelineAggregators, metaData); + } + + @Override + protected Writeable.Reader<InternalDateRange> instanceReader() { + return InternalDateRange::new; + } +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/InternalGeoDistanceTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/InternalGeoDistanceTests.java new file mode 100644 index 0000000000..9dd2a7a67c --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/InternalGeoDistanceTests.java @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range.geodistance; + +import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.search.aggregations.InternalAggregations; +import org.elasticsearch.search.aggregations.bucket.range.InternalRangeTestCase; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class InternalGeoDistanceTests extends InternalRangeTestCase<InternalGeoDistance> { + + private List<Tuple<Double, Double>> geoDistanceRanges; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + final int interval = randomFrom(1, 5, 10, 25, 50, 100); + final int numRanges = randomIntBetween(1, 10); + + List<Tuple<Double, Double>> listOfRanges = new ArrayList<>(numRanges); + for (int i = 0; i < numRanges; i++) { + double from = i * interval; + double to = from + interval; + listOfRanges.add(Tuple.tuple(from, to)); + } + if (randomBoolean()) { + // Add some overlapping ranges + double max = (double) numRanges * interval; + listOfRanges.add(Tuple.tuple(0.0, max)); + listOfRanges.add(Tuple.tuple(0.0, max / 2)); + listOfRanges.add(Tuple.tuple(max / 3, max / 3 * 2)); + } + geoDistanceRanges = Collections.unmodifiableList(listOfRanges); + } + @Override + protected Writeable.Reader<InternalGeoDistance> instanceReader() { + return InternalGeoDistance::new; + } + + @Override + protected InternalGeoDistance createTestInstance(String name, + List<PipelineAggregator> pipelineAggregators, + Map<String, Object> metaData, + boolean keyed) { + final List<InternalGeoDistance.Bucket> buckets = new ArrayList<>(); + for (int i = 0; i < geoDistanceRanges.size(); ++i) { + Tuple<Double, Double> range = geoDistanceRanges.get(i); + int docCount = randomIntBetween(0, 1000); + double from = range.v1(); + double to = range.v2(); + buckets.add(new InternalGeoDistance.Bucket("range_" + i, from, to, docCount, InternalAggregations.EMPTY, keyed)); + } + return new InternalGeoDistance(name, buckets, keyed, pipelineAggregators, metaData); + } +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/InternalSignificantTermsTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/InternalSignificantTermsTestCase.java index dde1562e1a..f1c54c4b50 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/InternalSignificantTermsTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/InternalSignificantTermsTestCase.java @@ -19,8 +19,8 @@ package org.elasticsearch.search.aggregations.bucket.significant; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.Arrays; import java.util.HashMap; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTermsTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTermsTestCase.java index cfd7a82da1..b8c44d5c9b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTermsTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/terms/InternalTermsTestCase.java @@ -23,6 +23,7 @@ import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalMultiBucketAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.junit.Before; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.HashMap; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index b7739d6c81..c952f43eb3 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -397,7 +397,7 @@ public class AvgIT extends AbstractNumericTestCase { */ public static class ExtractFieldScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new ExtractFieldScriptEngine(); } } @@ -405,7 +405,7 @@ public class AvgIT extends AbstractNumericTestCase { /** * This mock script returns the field that is specified by name in the script body */ - public static class ExtractFieldScriptEngine implements ScriptEngineService { + public static class ExtractFieldScriptEngine implements ScriptEngine { public static final String NAME = "extract_field"; @@ -502,7 +502,7 @@ public class AvgIT extends AbstractNumericTestCase { */ public static class FieldValueScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new FieldValueScriptEngine(); } } @@ -510,7 +510,7 @@ public class AvgIT extends AbstractNumericTestCase { /** * This mock script returns the field value and adds one month to the returned date */ - public static class FieldValueScriptEngine implements ScriptEngineService { + public static class FieldValueScriptEngine implements ScriptEngine { public static final String NAME = "field_value"; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java index 6459f5a5ae..8e90b88176 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java @@ -21,12 +21,12 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats.Bounds; import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats; import org.elasticsearch.search.aggregations.metrics.stats.extended.ParsedExtendedStats; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import org.junit.Before; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalMaxTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalMaxTests.java index 1d3a8b45a1..e2114fbebb 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalMaxTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalMaxTests.java @@ -21,11 +21,11 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.max.InternalMax; import org.elasticsearch.search.aggregations.metrics.max.ParsedMax; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java index 6bfcfdd1ee..45bc4a8a9b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java @@ -20,11 +20,11 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.stats.InternalStats; import org.elasticsearch.search.aggregations.metrics.stats.ParsedStats; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java index 16d345c7b8..227ffc7251 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -396,7 +396,7 @@ public class SumIT extends AbstractNumericTestCase { */ public static class ExtractFieldScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new ExtractFieldScriptEngine(); } } @@ -405,7 +405,7 @@ public class SumIT extends AbstractNumericTestCase { * This mock script returns the field that is specified by name in the * script body */ - public static class ExtractFieldScriptEngine implements ScriptEngineService { + public static class ExtractFieldScriptEngine implements ScriptEngine { public static final String NAME = "extract_field"; @@ -508,7 +508,7 @@ public class SumIT extends AbstractNumericTestCase { */ public static class FieldValueScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new FieldValueScriptEngine(); } } @@ -517,7 +517,7 @@ public class SumIT extends AbstractNumericTestCase { * This mock script returns the field value and adds one to the returned * value */ - public static class FieldValueScriptEngine implements ScriptEngineService { + public static class FieldValueScriptEngine implements ScriptEngine { public static final String NAME = "field_value"; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index 784635bb1d..2cfb344310 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -251,7 +251,7 @@ public class ValueCountIT extends ESIntegTestCase { */ public static class FieldValueScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new FieldValueScriptEngine(); } } @@ -259,7 +259,7 @@ public class ValueCountIT extends ESIntegTestCase { /** * This mock script returns the field value. If the parameter map contains a parameter "s", the corresponding is used as field name. */ - public static class FieldValueScriptEngine implements ScriptEngineService { + public static class FieldValueScriptEngine implements ScriptEngine { public static final String NAME = "field_value"; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java index 965f06e9e6..4e05b1bd68 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/avg/InternalAvgTests.java @@ -22,8 +22,8 @@ package org.elasticsearch.search.aggregations.metrics.avg; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.InternalAggregationTestCase; -import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/cardinality/InternalCardinalityTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/cardinality/InternalCardinalityTests.java index 60f0179d9a..1b46e0cdaf 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/cardinality/InternalCardinalityTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/cardinality/InternalCardinalityTests.java @@ -24,9 +24,10 @@ import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.MockBigArrays; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; +import org.elasticsearch.test.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import org.junit.After; import java.util.ArrayList; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geobounds/InternalGeoBoundsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geobounds/InternalGeoBoundsTests.java index 611178d1bf..133b948219 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geobounds/InternalGeoBoundsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geobounds/InternalGeoBoundsTests.java @@ -20,9 +20,9 @@ package org.elasticsearch.search.aggregations.metrics.geobounds; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.Collections; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java index 52474c4ae3..4e48649b07 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.search.aggregations.metrics.geocentroid; import org.apache.lucene.geo.GeoEncodingUtils; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import org.elasticsearch.test.geo.RandomGeoGenerator; import java.util.Collections; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/min/InternalMinTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/min/InternalMinTests.java index 6230c80132..f1cfa0a63b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/min/InternalMinTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/min/InternalMinTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.search.aggregations.metrics.min; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/InternalPercentilesTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/InternalPercentilesTestCase.java index be105f2af8..8e06926ea0 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/InternalPercentilesTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/InternalPercentilesTestCase.java @@ -21,6 +21,9 @@ package org.elasticsearch.search.aggregations.metrics.percentiles; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.ParsedAggregation; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; +import org.junit.Before; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/hdr/InternalHDRPercentilesRanksTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/hdr/InternalHDRPercentilesRanksTests.java index d9379edefe..728ddf6afa 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/hdr/InternalHDRPercentilesRanksTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/hdr/InternalHDRPercentilesRanksTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.metrics.percentiles.InternalPercentilesRanksTestCase; import org.elasticsearch.search.aggregations.metrics.percentiles.ParsedPercentiles; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.Arrays; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/InternalTDigestPercentilesRanksTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/InternalTDigestPercentilesRanksTests.java index f8698fda2c..189091433a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/InternalTDigestPercentilesRanksTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/InternalTDigestPercentilesRanksTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.search.aggregations.metrics.percentiles.tdigest; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.metrics.percentiles.InternalPercentilesRanksTestCase; import org.elasticsearch.search.aggregations.metrics.percentiles.ParsedPercentiles; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.Arrays; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java index 9d8ff94c47..75975d5a39 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java @@ -30,8 +30,8 @@ import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.ScriptType; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.io.IOException; import java.util.Collections; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSumTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSumTests.java index 6fb61257a9..1e5b8057cb 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSumTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/sum/InternalSumTests.java @@ -20,9 +20,9 @@ package org.elasticsearch.search.aggregations.metrics.sum; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java index 22479eb434..db68e8537d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java @@ -30,11 +30,11 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.text.Text; -import org.elasticsearch.search.SearchHitField; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHits; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java index 17df4b89dc..e7483cad91 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java @@ -20,9 +20,9 @@ package org.elasticsearch.search.aggregations.metrics.valuecount; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.List; import java.util.Map; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java index ffd5fd1bf8..a996bde059 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; +import org.elasticsearch.test.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import java.util.Collections; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/InternalPercentilesBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/InternalPercentilesBucketTests.java index 3f29caae84..ed4fc00776 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/InternalPercentilesBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/InternalPercentilesBucketTests.java @@ -21,10 +21,10 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.metrics.percentiles.Percentile; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.io.IOException; import java.util.Collections; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java index 229c98b4ad..58115a7fbb 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.search.aggregations.pipeline.derivative; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.aggregations.InternalAggregationTestCase; import org.elasticsearch.search.aggregations.ParsedAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.test.InternalAggregationTestCase; import java.util.Collections; import java.util.List; diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index 6f1087561c..32676d06a2 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -56,7 +56,7 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContextRegistry; import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptServiceTests.TestEngineService; +import org.elasticsearch.script.ScriptServiceTests.TestEngine; import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.DocValueFormat; @@ -91,7 +91,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST .build(); Environment environment = new Environment(baseSettings); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList()); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngineService())); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngine())); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); scriptService = new ScriptService(baseSettings, environment, new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) { diff --git a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java index 92fb2cd277..82b1dc3656 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.suggest; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.search.ReduceSearchPhaseException; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -34,7 +33,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder; @@ -1112,12 +1111,12 @@ public class SuggestSearchIT extends ESIntegTestCase { public static class DummyTemplatePlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new DummyTemplateScriptEngine(); } } - public static class DummyTemplateScriptEngine implements ScriptEngineService { + public static class DummyTemplateScriptEngine implements ScriptEngine { // The collate query setter is hard coded to use mustache, so lets lie in this test about the script plugin, // which makes the collate code thinks mustache is evaluating the query. diff --git a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java index 2d28f75ff9..463d9e0d29 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.AbstractExecutableScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.NativeScriptEngineService; +import org.elasticsearch.script.NativeScriptEngine; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; @@ -57,7 +57,7 @@ public class UpdateByNativeScriptIT extends ESIntegTestCase { Map<String, Object> params = new HashMap<>(); params.put("foo", "SETVALUE"); client().prepareUpdate("test", "type", "1") - .setScript(new Script(ScriptType.INLINE, NativeScriptEngineService.NAME, "custom", params)).get(); + .setScript(new Script(ScriptType.INLINE, NativeScriptEngine.NAME, "custom", params)).get(); Map<String, Object> data = client().prepareGet("test", "type", "1").get().getSource(); assertThat(data, hasKey("foo")); diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index 10d235d3a8..d274399387 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -34,17 +34,14 @@ import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.MergePolicyConfig; -import org.elasticsearch.index.VersionType; import org.elasticsearch.index.engine.DocumentMissingException; -import org.elasticsearch.index.engine.VersionConflictEngineException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptEngineService; +import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.SearchLookup; @@ -76,12 +73,12 @@ public class UpdateIT extends ESIntegTestCase { public static class PutFieldValuesScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new PutFieldValuesScriptEngine(); } } - public static class PutFieldValuesScriptEngine implements ScriptEngineService { + public static class PutFieldValuesScriptEngine implements ScriptEngine { public static final String NAME = "put_values"; @@ -149,12 +146,12 @@ public class UpdateIT extends ESIntegTestCase { public static class FieldIncrementScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new FieldIncrementScriptEngine(); } } - public static class FieldIncrementScriptEngine implements ScriptEngineService { + public static class FieldIncrementScriptEngine implements ScriptEngine { public static final String NAME = "field_inc"; @@ -215,12 +212,12 @@ public class UpdateIT extends ESIntegTestCase { public static class ScriptedUpsertScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new ScriptedUpsertScriptEngine(); } } - public static class ScriptedUpsertScriptEngine implements ScriptEngineService { + public static class ScriptedUpsertScriptEngine implements ScriptEngine { public static final String NAME = "scripted_upsert"; @@ -282,12 +279,12 @@ public class UpdateIT extends ESIntegTestCase { public static class ExtractContextInSourceScriptPlugin extends Plugin implements ScriptPlugin { @Override - public ScriptEngineService getScriptEngineService(Settings settings) { + public ScriptEngine getScriptEngine(Settings settings) { return new ExtractContextInSourceScriptEngine(); } } - public static class ExtractContextInSourceScriptEngine implements ScriptEngineService { + public static class ExtractContextInSourceScriptEngine implements ScriptEngine { public static final String NAME = "extract_ctx"; |