summaryrefslogtreecommitdiff
path: root/core/src/test
diff options
context:
space:
mode:
authorTanguy Leroux <tlrx.dev@gmail.com>2017-05-19 13:13:00 +0200
committerTanguy Leroux <tlrx.dev@gmail.com>2017-05-19 13:13:00 +0200
commit83aa00b3f665099b0f5dadf5a2fcd97219cdbde5 (patch)
tree04253d353603d3caa4098c09d870409564a7d4d1 /core/src/test
parent4c34ea8fc84ccd27af98b81f51408fcb53077a20 (diff)
parent55af1f7a2b503d7997b476c34f952bd9fce6eeb5 (diff)
Merge remote-tracking branch 'origin/master' into feature/client_aggs_parsing
Diffstat (limited to 'core/src/test')
-rw-r--r--core/src/test/java/org/elasticsearch/VersionTests.java11
-rw-r--r--core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java7
-rw-r--r--core/src/test/java/org/elasticsearch/discovery/zen/PublishClusterStateActionTests.java143
-rw-r--r--core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java92
-rw-r--r--core/src/test/java/org/elasticsearch/index/IndexModuleTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptContextTests.java31
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptModesTests.java254
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java131
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java98
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java56
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java5
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java5
13 files changed, 210 insertions, 631 deletions
diff --git a/core/src/test/java/org/elasticsearch/VersionTests.java b/core/src/test/java/org/elasticsearch/VersionTests.java
index 96a0c9aa81..27782511de 100644
--- a/core/src/test/java/org/elasticsearch/VersionTests.java
+++ b/core/src/test/java/org/elasticsearch/VersionTests.java
@@ -293,7 +293,6 @@ public class VersionTests extends ESTestCase {
if (maxBranchVersion == null) {
maxBranchVersions.put(branchName, v);
} else if (v.after(maxBranchVersion)) {
-
assertFalse("Version " + maxBranchVersion + " cannot be a snapshot because version " + v + " exists", VersionUtils.isSnapshot(maxBranchVersion));
maxBranchVersions.put(branchName, v);
}
@@ -329,6 +328,16 @@ public class VersionTests extends ESTestCase {
assertTrue(isCompatible(Version.V_5_5_0_UNRELEASED, Version.V_6_0_0_alpha2_UNRELEASED));
assertFalse(isCompatible(Version.fromId(2000099), Version.V_6_0_0_alpha2_UNRELEASED));
assertFalse(isCompatible(Version.fromId(2000099), Version.V_5_0_0));
+ assertTrue(isCompatible(Version.fromString("6.0.0"), Version.fromString("7.0.0")));
+ if (Version.CURRENT.isRelease()) {
+ assertTrue(isCompatible(Version.CURRENT, Version.fromString("7.0.0")));
+ } else {
+ assertFalse(isCompatible(Version.CURRENT, Version.fromString("7.0.0")));
+ }
+ assertFalse("only compatible with the latest minor",
+ isCompatible(VersionUtils.getPreviousMinorVersion(), Version.fromString("7.0.0")));
+ assertFalse(isCompatible(Version.V_5_0_0, Version.fromString("6.0.0")));
+ assertFalse(isCompatible(Version.V_5_0_0, Version.fromString("7.0.0")));
}
diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
index e03f3ec45f..a3bb96a72f 100644
--- a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
@@ -45,7 +45,6 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptService;
-import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.RandomObjects;
@@ -64,7 +63,6 @@ import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
-import static org.elasticsearch.common.xcontent.XContentHelper.update;
import static org.elasticsearch.script.MockScriptEngine.mockInlineScript;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
import static org.hamcrest.Matchers.arrayContaining;
@@ -145,15 +143,12 @@ public class UpdateRequestTests extends ESTestCase {
final ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(singletonList(engine));
- final ScriptSettings scriptSettings =
- new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
final ResourceWatcherService watcherService =
new ResourceWatcherService(baseSettings, null);
ScriptService scriptService = new ScriptService(
baseSettings,
scriptEngineRegistry,
- scriptContextRegistry,
- scriptSettings);
+ scriptContextRegistry);
final Settings settings = settings(Version.CURRENT).build();
updateHelper = new UpdateHelper(settings, scriptService);
diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/PublishClusterStateActionTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/PublishClusterStateActionTests.java
index 863bf80085..2e29347204 100644
--- a/core/src/test/java/org/elasticsearch/discovery/zen/PublishClusterStateActionTests.java
+++ b/core/src/test/java/org/elasticsearch/discovery/zen/PublishClusterStateActionTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.discovery.zen;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
+import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.ClusterName;
@@ -64,20 +65,17 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Supplier;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@@ -90,11 +88,12 @@ public class PublishClusterStateActionTests extends ESTestCase {
protected ThreadPool threadPool;
protected Map<String, MockNode> nodes = new HashMap<>();
- public static class MockNode implements PublishClusterStateAction.NewPendingClusterStateListener {
+ public static class MockNode implements PublishClusterStateAction.IncomingClusterStateListener {
public final DiscoveryNode discoveryNode;
public final MockTransportService service;
public MockPublishAction action;
public final ClusterStateListener listener;
+ private final PendingClusterStatesQueue pendingStatesQueue;
public volatile ClusterState clusterState;
@@ -108,6 +107,7 @@ public class PublishClusterStateActionTests extends ESTestCase {
this.logger = logger;
this.clusterState = ClusterState.builder(CLUSTER_NAME).nodes(DiscoveryNodes.builder()
.add(discoveryNode).localNodeId(discoveryNode.getId()).build()).build();
+ this.pendingStatesQueue = new PendingClusterStatesQueue(logger, 25);
}
public MockNode setAsMaster() {
@@ -128,18 +128,37 @@ public class PublishClusterStateActionTests extends ESTestCase {
}
@Override
- public void onNewClusterState(String reason) {
- ClusterState newClusterState = action.pendingStatesQueue().getNextClusterStateToProcess();
- logger.debug("[{}] received version [{}], uuid [{}]",
- discoveryNode.getName(), newClusterState.version(), newClusterState.stateUUID());
- if (listener != null) {
- ClusterChangedEvent event = new ClusterChangedEvent("", newClusterState, clusterState);
- listener.clusterChanged(event);
- }
- if (clusterState.nodes().getMasterNode() == null || newClusterState.supersedes(clusterState)) {
- clusterState = newClusterState;
+ public void onIncomingClusterState(ClusterState incomingState) {
+ ZenDiscovery.validateIncomingState(logger, incomingState, clusterState);
+ pendingStatesQueue.addPending(incomingState);
+ }
+
+ public void onClusterStateCommitted(String stateUUID, ActionListener<Void> processedListener) {
+ final ClusterState state = pendingStatesQueue.markAsCommitted(stateUUID,
+ new PendingClusterStatesQueue.StateProcessedListener() {
+ @Override
+ public void onNewClusterStateProcessed() {
+ processedListener.onResponse(null);
+ }
+
+ @Override
+ public void onNewClusterStateFailed(Exception e) {
+ processedListener.onFailure(e);
+ }
+ });
+ if (state != null) {
+ ClusterState newClusterState = pendingStatesQueue.getNextClusterStateToProcess();
+ logger.debug("[{}] received version [{}], uuid [{}]",
+ discoveryNode.getName(), newClusterState.version(), newClusterState.stateUUID());
+ if (listener != null) {
+ ClusterChangedEvent event = new ClusterChangedEvent("", newClusterState, clusterState);
+ listener.clusterChanged(event);
+ }
+ if (clusterState.nodes().getMasterNode() == null || newClusterState.supersedes(clusterState)) {
+ clusterState = newClusterState;
+ }
+ pendingStatesQueue.markAsProcessed(newClusterState);
}
- action.pendingStatesQueue().markAsProcessed(newClusterState);
}
public DiscoveryNodes nodes() {
@@ -168,7 +187,7 @@ public class PublishClusterStateActionTests extends ESTestCase {
MockTransportService service = buildTransportService(settings, threadPool);
DiscoveryNode discoveryNode = service.getLocalDiscoNode();
MockNode node = new MockNode(discoveryNode, service, listener, logger);
- node.action = buildPublishClusterStateAction(settings, service, () -> node.clusterState, node);
+ node.action = buildPublishClusterStateAction(settings, service, node);
final CountDownLatch latch = new CountDownLatch(nodes.size() * 2);
TransportConnectionListener waitForConnection = new TransportConnectionListener() {
@Override
@@ -241,8 +260,7 @@ public class PublishClusterStateActionTests extends ESTestCase {
private static MockPublishAction buildPublishClusterStateAction(
Settings settings,
MockTransportService transportService,
- Supplier<ClusterState> clusterStateSupplier,
- PublishClusterStateAction.NewPendingClusterStateListener listener
+ PublishClusterStateAction.IncomingClusterStateListener listener
) {
DiscoverySettings discoverySettings =
new DiscoverySettings(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
@@ -251,10 +269,8 @@ public class PublishClusterStateActionTests extends ESTestCase {
settings,
transportService,
namedWriteableRegistry,
- clusterStateSupplier,
listener,
- discoverySettings,
- CLUSTER_NAME);
+ discoverySettings);
}
public void testSimpleClusterStatePublishing() throws Exception {
@@ -607,86 +623,6 @@ public class PublishClusterStateActionTests extends ESTestCase {
}
}
- public void testIncomingClusterStateValidation() throws Exception {
- MockNode node = createMockNode("node");
-
- logger.info("--> testing acceptances of any master when having no master");
- ClusterState state = ClusterState.builder(node.clusterState)
- .nodes(DiscoveryNodes.builder(node.nodes()).masterNodeId(randomAlphaOfLength(10))).incrementVersion().build();
- node.action.validateIncomingState(state, null);
-
- // now set a master node
- node.clusterState = ClusterState.builder(node.clusterState)
- .nodes(DiscoveryNodes.builder(node.nodes()).masterNodeId("master")).build();
- logger.info("--> testing rejection of another master");
- try {
- node.action.validateIncomingState(state, node.clusterState);
- fail("node accepted state from another master");
- } catch (IllegalStateException OK) {
- assertThat(OK.toString(), containsString("cluster state from a different master than the current one, rejecting"));
- }
-
- logger.info("--> test state from the current master is accepted");
- node.action.validateIncomingState(ClusterState.builder(node.clusterState)
- .nodes(DiscoveryNodes.builder(node.nodes()).masterNodeId("master")).incrementVersion().build(), node.clusterState);
-
-
- logger.info("--> testing rejection of another cluster name");
- try {
- node.action.validateIncomingState(ClusterState.builder(new ClusterName(randomAlphaOfLength(10)))
- .nodes(node.nodes()).build(), node.clusterState);
- fail("node accepted state with another cluster name");
- } catch (IllegalStateException OK) {
- assertThat(OK.toString(), containsString("received state from a node that is not part of the cluster"));
- }
-
- logger.info("--> testing rejection of a cluster state with wrong local node");
- try {
- state = ClusterState.builder(node.clusterState)
- .nodes(DiscoveryNodes.builder(node.nodes()).localNodeId("_non_existing_").build())
- .incrementVersion().build();
- node.action.validateIncomingState(state, node.clusterState);
- fail("node accepted state with non-existence local node");
- } catch (IllegalStateException OK) {
- assertThat(OK.toString(), containsString("received state with a local node that does not match the current local node"));
- }
-
- try {
- MockNode otherNode = createMockNode("otherNode");
- state = ClusterState.builder(node.clusterState).nodes(
- DiscoveryNodes.builder(node.nodes()).add(otherNode.discoveryNode).localNodeId(otherNode.discoveryNode.getId()).build()
- ).incrementVersion().build();
- node.action.validateIncomingState(state, node.clusterState);
- fail("node accepted state with existent but wrong local node");
- } catch (IllegalStateException OK) {
- assertThat(OK.toString(), containsString("received state with a local node that does not match the current local node"));
- }
-
- logger.info("--> testing acceptance of an old cluster state");
- final ClusterState incomingState = node.clusterState;
- node.clusterState = ClusterState.builder(node.clusterState).incrementVersion().build();
- final IllegalStateException e =
- expectThrows(IllegalStateException.class, () -> node.action.validateIncomingState(incomingState, node.clusterState));
- final String message = String.format(
- Locale.ROOT,
- "rejecting cluster state version [%d] uuid [%s] received from [%s]",
- incomingState.version(),
- incomingState.stateUUID(),
- incomingState.nodes().getMasterNodeId()
- );
- assertThat(e, hasToString("java.lang.IllegalStateException: " + message));
-
- // an older version from a *new* master is also OK!
- ClusterState previousState = ClusterState.builder(node.clusterState).incrementVersion().build();
- state = ClusterState.builder(node.clusterState)
- .nodes(DiscoveryNodes.builder(node.clusterState.nodes()).masterNodeId("_new_master_").build())
- .build();
- // remove the master of the node (but still have a previous cluster state with it)!
- node.resetMasterId();
-
- node.action.validateIncomingState(state, previousState);
- }
-
public void testOutOfOrderCommitMessages() throws Throwable {
MockNode node = createMockNode("node").setAsMaster();
final CapturingTransportChannel channel = new CapturingTransportChannel();
@@ -874,9 +810,8 @@ public class PublishClusterStateActionTests extends ESTestCase {
AtomicBoolean errorOnCommit = new AtomicBoolean();
public MockPublishAction(Settings settings, TransportService transportService, NamedWriteableRegistry namedWriteableRegistry,
- Supplier<ClusterState> clusterStateSupplier, NewPendingClusterStateListener listener,
- DiscoverySettings discoverySettings, ClusterName clusterName) {
- super(settings, transportService, namedWriteableRegistry, clusterStateSupplier, listener, discoverySettings, clusterName);
+ IncomingClusterStateListener listener, DiscoverySettings discoverySettings) {
+ super(settings, transportService, namedWriteableRegistry, listener, discoverySettings);
}
@Override
diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java
index 65856add56..cb88213cfe 100644
--- a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java
+++ b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java
@@ -67,6 +67,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -88,6 +89,7 @@ import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasToString;
public class ZenDiscoveryUnitTests extends ESTestCase {
@@ -405,4 +407,94 @@ public class ZenDiscoveryUnitTests extends ESTestCase {
}
}
}
+
+ public void testIncomingClusterStateValidation() throws Exception {
+ ClusterName clusterName = new ClusterName("abc");
+
+ DiscoveryNodes.Builder currentNodes = DiscoveryNodes.builder().add(
+ new DiscoveryNode("a", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)).localNodeId("a");
+
+ ClusterState previousState = ClusterState.builder(clusterName).nodes(currentNodes).build();
+
+ logger.info("--> testing acceptances of any master when having no master");
+ ClusterState state = ClusterState.builder(previousState)
+ .nodes(DiscoveryNodes.builder(previousState.nodes()).masterNodeId(randomAlphaOfLength(10))).incrementVersion().build();
+ ZenDiscovery.validateIncomingState(logger, state, previousState);
+
+ // now set a master node
+ previousState = state;
+ state = ClusterState.builder(previousState)
+ .nodes(DiscoveryNodes.builder(previousState.nodes()).masterNodeId("master")).build();
+ logger.info("--> testing rejection of another master");
+ try {
+ ZenDiscovery.validateIncomingState(logger, state, previousState);
+ fail("node accepted state from another master");
+ } catch (IllegalStateException OK) {
+ assertThat(OK.toString(), containsString("cluster state from a different master than the current one, rejecting"));
+ }
+
+ logger.info("--> test state from the current master is accepted");
+ previousState = state;
+ ZenDiscovery.validateIncomingState(logger, ClusterState.builder(previousState)
+ .nodes(DiscoveryNodes.builder(previousState.nodes()).masterNodeId("master")).incrementVersion().build(), previousState);
+
+
+ logger.info("--> testing rejection of another cluster name");
+ try {
+ ZenDiscovery.validateIncomingState(logger, ClusterState.builder(new ClusterName(randomAlphaOfLength(10)))
+ .nodes(previousState.nodes()).build(), previousState);
+ fail("node accepted state with another cluster name");
+ } catch (IllegalStateException OK) {
+ assertThat(OK.toString(), containsString("received state from a node that is not part of the cluster"));
+ }
+
+ logger.info("--> testing rejection of a cluster state with wrong local node");
+ try {
+ state = ClusterState.builder(previousState)
+ .nodes(DiscoveryNodes.builder(previousState.nodes()).localNodeId("_non_existing_").build())
+ .incrementVersion().build();
+ ZenDiscovery.validateIncomingState(logger, state, previousState);
+ fail("node accepted state with non-existence local node");
+ } catch (IllegalStateException OK) {
+ assertThat(OK.toString(), containsString("received state with a local node that does not match the current local node"));
+ }
+
+ try {
+ DiscoveryNode otherNode = new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
+ state = ClusterState.builder(previousState).nodes(
+ DiscoveryNodes.builder(previousState.nodes()).add(otherNode)
+ .localNodeId(otherNode.getId()).build()
+ ).incrementVersion().build();
+ ZenDiscovery.validateIncomingState(logger, state, previousState);
+ fail("node accepted state with existent but wrong local node");
+ } catch (IllegalStateException OK) {
+ assertThat(OK.toString(), containsString("received state with a local node that does not match the current local node"));
+ }
+
+ logger.info("--> testing acceptance of an old cluster state");
+ final ClusterState incomingState = previousState;
+ previousState = ClusterState.builder(previousState).incrementVersion().build();
+ final ClusterState finalPreviousState = previousState;
+ final IllegalStateException e =
+ expectThrows(IllegalStateException.class, () -> ZenDiscovery.validateIncomingState(logger, incomingState, finalPreviousState));
+ final String message = String.format(
+ Locale.ROOT,
+ "rejecting cluster state version [%d] uuid [%s] received from [%s]",
+ incomingState.version(),
+ incomingState.stateUUID(),
+ incomingState.nodes().getMasterNodeId()
+ );
+ assertThat(e, hasToString("java.lang.IllegalStateException: " + message));
+
+ ClusterState higherVersionState = ClusterState.builder(previousState).incrementVersion().build();
+ // remove the master of the node (but still have a previous cluster state with it)!
+ higherVersionState = ClusterState.builder(higherVersionState)
+ .nodes(DiscoveryNodes.builder(higherVersionState.nodes()).masterNodeId(null)).build();
+ // an older version from a *new* master is also OK!
+ state = ClusterState.builder(previousState)
+ .nodes(DiscoveryNodes.builder(previousState.nodes()).masterNodeId("_new_master_").build())
+ .build();
+
+ ZenDiscovery.validateIncomingState(logger, state, higherVersionState);
+ }
}
diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java
index 7dd97f8554..b1a9bc7501 100644
--- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java
+++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java
@@ -70,7 +70,6 @@ import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptService;
-import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ClusterServiceUtils;
import org.elasticsearch.test.ESTestCase;
@@ -130,8 +129,7 @@ public class IndexModuleTests extends ESTestCase {
bigArrays = new BigArrays(settings, circuitBreakerService);
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList());
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
- ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
- scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
+ scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
clusterService = ClusterServiceUtils.createClusterService(threadPool);
nodeEnvironment = new NodeEnvironment(settings, environment);
mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java
index 182a6c1af5..6fc77eeb9b 100644
--- a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java
+++ b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java
@@ -23,7 +23,6 @@ import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.MetaData;
-import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
@@ -32,21 +31,14 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static org.hamcrest.Matchers.containsString;
-
public class ScriptContextTests extends ESTestCase {
private static final String PLUGIN_NAME = "testplugin";
- private static final String SCRIPT_PLUGIN_CUSTOM_SETTING = "script." + PLUGIN_NAME + "_custom_globally_disabled_op";
- private static final String SCRIPT_ENGINE_CUSTOM_SETTING = "script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op";
-
- private ScriptSettings scriptSettings;
ScriptService makeScriptService() throws Exception {
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
- .put(SCRIPT_PLUGIN_CUSTOM_SETTING, "false")
- .put(SCRIPT_ENGINE_CUSTOM_SETTING, "false")
+ .put("script.contexts_allowed", "search, aggs, testplugin_custom_op")
.build();
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"));
@@ -56,8 +48,7 @@ public class ScriptContextTests extends ESTestCase {
new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"),
new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
- scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
- ScriptService scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
+ ScriptService scriptService = new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry);
ClusterState empty = ClusterState.builder(new ClusterName("_name")).build();
ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE);
@@ -69,8 +60,6 @@ public class ScriptContextTests extends ESTestCase {
return scriptService;
}
-
-
public void testCustomGlobalScriptContextSettings() throws Exception {
ScriptService scriptService = makeScriptService();
for (ScriptType scriptType : ScriptType.values()) {
@@ -78,12 +67,10 @@ public class ScriptContextTests extends ESTestCase {
Script script = new Script(scriptType, MockScriptEngine.NAME, "1", Collections.emptyMap());
scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
fail("script compilation should have been rejected");
- } catch (IllegalStateException e) {
- assertThat(e.getMessage(), containsString("scripts of type [" + scriptType + "], operation [" + PLUGIN_NAME + "_custom_globally_disabled_op] and lang [" + MockScriptEngine.NAME + "] are disabled"));
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("cannot execute scripts using [" + PLUGIN_NAME + "_custom_globally_disabled_op] context"));
}
}
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING));
}
public void testCustomScriptContextSettings() throws Exception {
@@ -92,16 +79,14 @@ public class ScriptContextTests extends ESTestCase {
try {
scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"));
fail("script compilation should have been rejected");
- } catch (IllegalStateException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("scripts of type [inline], operation [" + PLUGIN_NAME + "_custom_exp_disabled_op] and lang [" + MockScriptEngine.NAME + "] are disabled"));
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("cannot execute scripts using [" + PLUGIN_NAME + "_custom_exp_disabled_op] context"));
}
// still works for other script contexts
assertNotNull(scriptService.compile(script, ScriptContext.Standard.AGGS));
assertNotNull(scriptService.compile(script, ScriptContext.Standard.SEARCH));
assertNotNull(scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_op")));
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING));
}
public void testUnknownPluginScriptContext() throws Exception {
@@ -115,8 +100,6 @@ public class ScriptContextTests extends ESTestCase {
assertTrue(e.getMessage(), e.getMessage().contains("script context [" + PLUGIN_NAME + "_unknown] not supported"));
}
}
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING));
}
public void testUnknownCustomScriptContext() throws Exception {
@@ -136,7 +119,5 @@ public class ScriptContextTests extends ESTestCase {
assertTrue(e.getMessage(), e.getMessage().contains("script context [test] not supported"));
}
}
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, SCRIPT_PLUGIN_CUSTOM_SETTING, SCRIPT_ENGINE_CUSTOM_SETTING));
}
}
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java
deleted file mode 100644
index 653ac47485..0000000000
--- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java
+++ /dev/null
@@ -1,254 +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.script;
-
-import org.elasticsearch.common.Nullable;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.search.lookup.SearchLookup;
-import org.elasticsearch.test.ESTestCase;
-import org.junit.After;
-import org.junit.Before;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static java.util.Collections.unmodifiableMap;
-import static org.elasticsearch.common.util.set.Sets.newHashSet;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.Matchers.containsString;
-
-// TODO: this needs to be a base test class, and all scripting engines extend it
-public class ScriptModesTests extends ESTestCase {
- ScriptSettings scriptSettings;
- ScriptContextRegistry scriptContextRegistry;
- private ScriptContext[] scriptContexts;
- private Map<String, ScriptEngine> scriptEngines;
- private ScriptModes scriptModes;
- private Set<String> checkedSettings;
- private boolean assertAllSettingsWereChecked;
- private boolean assertScriptModesNonNull;
-
- @Before
- public void setupScriptEngines() {
- //randomly register custom script contexts
- int randomInt = randomIntBetween(0, 3);
- //prevent duplicates using map
- Map<String, ScriptContext.Plugin> contexts = new HashMap<>();
- for (int i = 0; i < randomInt; i++) {
- String plugin = randomAlphaOfLength(randomIntBetween(1, 10));
- String operation = randomAlphaOfLength(randomIntBetween(1, 30));
- String context = plugin + "-" + operation;
- contexts.put(context, new ScriptContext.Plugin(plugin, operation));
- }
- scriptContextRegistry = new ScriptContextRegistry(contexts.values());
- scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
- scriptEngines = buildScriptEnginesByLangMap(newHashSet(new CustomScriptEngine()));
- ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngines.values());
- scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
- checkedSettings = new HashSet<>();
- assertAllSettingsWereChecked = true;
- assertScriptModesNonNull = true;
- }
-
- @After
- public void assertAllSettingsWereChecked() {
- if (assertScriptModesNonNull) {
- assertThat(scriptModes, notNullValue());
- int numberOfSettings = ScriptType.values().length * scriptContextRegistry.scriptContexts().size();
- numberOfSettings += 2; // for top-level inline/store settings
- assertThat(scriptModes.scriptEnabled.size(), equalTo(numberOfSettings));
- if (assertAllSettingsWereChecked) {
- assertThat(checkedSettings.size(), equalTo(numberOfSettings));
- }
- }
- }
-
- public void testDefaultSettings() {
- this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, Settings.EMPTY);
- assertScriptModesAllOps(false, ScriptType.STORED, ScriptType.INLINE);
- }
-
- public void testMissingSetting() {
- assertAllSettingsWereChecked = false;
- this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, Settings.EMPTY);
- try {
- scriptModes.getScriptEnabled("non_existing", randomFrom(ScriptType.values()), randomFrom(scriptContexts));
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString("not found for lang [non_existing]"));
- }
- }
-
- public void testScriptTypeGenericSettings() {
- int randomInt = randomIntBetween(1, ScriptType.values().length - 1);
- Set<ScriptType> randomScriptTypesSet = new HashSet<>();
- boolean[] randomScriptModes = new boolean[randomInt];
- for (int i = 0; i < randomInt; i++) {
- boolean added = false;
- while (added == false) {
- added = randomScriptTypesSet.add(randomFrom(ScriptType.values()));
- }
- randomScriptModes[i] = randomBoolean();
- }
- ScriptType[] randomScriptTypes = randomScriptTypesSet.toArray(new ScriptType[randomScriptTypesSet.size()]);
- List<String> deprecated = new ArrayList<>();
- Settings.Builder builder = Settings.builder();
- for (int i = 0; i < randomInt; i++) {
- builder.put("script" + "." + randomScriptTypes[i].getName(), randomScriptModes[i]);
- deprecated.add("script" + "." + randomScriptTypes[i].getName());
- }
- this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, builder.build());
-
- for (int i = 0; i < randomInt; i++) {
- assertScriptModesAllOps(randomScriptModes[i], randomScriptTypes[i]);
- }
- if (randomScriptTypesSet.contains(ScriptType.STORED) == false) {
- assertScriptModesAllOps(false, ScriptType.STORED);
- }
- if (randomScriptTypesSet.contains(ScriptType.INLINE) == false) {
- assertScriptModesAllOps(false, ScriptType.INLINE);
- }
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {})));
- }
-
- public void testScriptContextGenericSettings() {
- int randomInt = randomIntBetween(1, scriptContexts.length - 1);
- Set<ScriptContext> randomScriptContextsSet = new HashSet<>();
- boolean[] randomScriptModes = new boolean[randomInt];
- for (int i = 0; i < randomInt; i++) {
- boolean added = false;
- while (added == false) {
- added = randomScriptContextsSet.add(randomFrom(scriptContexts));
- }
- randomScriptModes[i] = randomBoolean();
- }
- ScriptContext[] randomScriptContexts = randomScriptContextsSet.toArray(new ScriptContext[randomScriptContextsSet.size()]);
- List<String> deprecated = new ArrayList<>();
- Settings.Builder builder = Settings.builder();
- for (int i = 0; i < randomInt; i++) {
- builder.put("script" + "." + randomScriptContexts[i].getKey(), randomScriptModes[i]);
- deprecated.add("script" + "." + randomScriptContexts[i].getKey());
- }
- this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, builder.build());
-
- for (int i = 0; i < randomInt; i++) {
- assertScriptModesAllTypes(randomScriptModes[i], randomScriptContexts[i]);
- }
-
- ScriptContext[] complementOf = complementOf(randomScriptContexts);
- assertScriptModes(false, new ScriptType[]{ScriptType.STORED, ScriptType.INLINE}, complementOf);
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {})));
- }
-
- public void testConflictingScriptTypeAndOpGenericSettings() {
- ScriptContext scriptContext = randomFrom(scriptContexts);
- Settings.Builder builder = Settings.builder()
- .put("script." + scriptContext.getKey(), "false")
- .put("script.stored", "true")
- .put("script.inline", "true");
- //operations generic settings have precedence over script type generic settings
- this.scriptModes = new ScriptModes(scriptContextRegistry, scriptSettings, builder.build());
- assertScriptModesAllTypes(false, scriptContext);
- ScriptContext[] complementOf = complementOf(scriptContext);
- assertScriptModes(true, new ScriptType[]{ScriptType.STORED}, complementOf);
- assertScriptModes(true, new ScriptType[]{ScriptType.INLINE}, complementOf);
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(
- scriptSettings, "script." + scriptContext.getKey(), "script.stored", "script.inline"));
- }
-
- private void assertScriptModesAllOps(boolean expectedScriptEnabled, ScriptType... scriptTypes) {
- assertScriptModes(expectedScriptEnabled, scriptTypes, scriptContexts);
- }
-
- private void assertScriptModesAllTypes(boolean expectedScriptEnabled, ScriptContext... scriptContexts) {
- assertScriptModes(expectedScriptEnabled, ScriptType.values(), scriptContexts);
- }
-
- private void assertScriptModes(boolean expectedScriptEnabled, ScriptType[] scriptTypes, ScriptContext... scriptContexts) {
- assert scriptTypes.length > 0;
- assert scriptContexts.length > 0;
- for (ScriptType scriptType : scriptTypes) {
- checkedSettings.add("script.engine.custom." + scriptType);
- for (ScriptContext scriptContext : scriptContexts) {
- assertThat("custom." + scriptType + "." + scriptContext.getKey() + " doesn't have the expected value",
- scriptModes.getScriptEnabled("custom", scriptType, scriptContext), equalTo(expectedScriptEnabled));
- checkedSettings.add("custom." + scriptType + "." + scriptContext);
- }
- }
- }
-
- private ScriptContext[] complementOf(ScriptContext... scriptContexts) {
- Map<String, ScriptContext> copy = new HashMap<>();
- for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
- copy.put(scriptContext.getKey(), scriptContext);
- }
- for (ScriptContext scriptContext : scriptContexts) {
- copy.remove(scriptContext.getKey());
- }
- return copy.values().toArray(new ScriptContext[copy.size()]);
- }
-
- 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 CustomScriptEngine implements ScriptEngine {
-
- public static final String NAME = "custom";
-
- @Override
- public String getType() {
- return NAME;
- }
-
- @Override
- public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
- return null;
- }
-
- @Override
- public ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars) {
- return null;
- }
-
- @Override
- public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
- return null;
- }
-
- @Override
- public void close() {
- }
- }
-}
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
index 9b52ff81ef..671fdaf502 100644
--- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
@@ -57,7 +57,6 @@ public class ScriptServiceTests extends ESTestCase {
private Map<String, ScriptEngine> scriptEnginesByLangMap;
private ScriptEngineRegistry scriptEngineRegistry;
private ScriptContextRegistry scriptContextRegistry;
- private ScriptSettings scriptSettings;
private ScriptContext[] scriptContexts;
private ScriptService scriptService;
private Settings baseSettings;
@@ -80,8 +79,6 @@ public class ScriptServiceTests extends ESTestCase {
scriptEngine = new TestEngine();
dangerousScriptEngine = new TestDangerousEngine();
TestEngine defaultScriptServiceEngine = new TestEngine(Script.DEFAULT_SCRIPT_LANG) {};
- scriptEnginesByLangMap = ScriptModesTests.buildScriptEnginesByLangMap(
- new HashSet<>(Arrays.asList(scriptEngine, defaultScriptServiceEngine)));
//randomly register custom script contexts
int randomInt = randomIntBetween(0, 3);
//prevent duplicates using map
@@ -101,15 +98,13 @@ public class ScriptServiceTests extends ESTestCase {
scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(scriptEngine, dangerousScriptEngine,
defaultScriptServiceEngine));
scriptContextRegistry = new ScriptContextRegistry(contexts.values());
- scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
logger.info("--> setup script service");
}
private void buildScriptService(Settings additionalSettings) throws IOException {
Settings finalSettings = Settings.builder().put(baseSettings).put(additionalSettings).build();
- // TODO:
- scriptService = new ScriptService(finalSettings, scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
+ scriptService = new ScriptService(finalSettings, scriptEngineRegistry, scriptContextRegistry) {
@Override
StoredScriptSource getScriptFromClusterState(String id, String lang) {
//mock the script that gets retrieved from an index
@@ -179,33 +174,25 @@ public class ScriptServiceTests extends ESTestCase {
public void testAllowSomeScriptTypeSettings() throws IOException {
Settings.Builder builder = Settings.builder();
builder.put("script.types_allowed", "inline");
- builder.put("script.engine.painless.stored", false);
buildScriptService(builder.build());
assertCompileAccepted("painless", "script", ScriptType.INLINE, ScriptContext.Standard.SEARCH);
assertCompileRejected("painless", "script", ScriptType.STORED, ScriptContext.Standard.SEARCH);
-
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.engine.painless.stored"));
}
public void testAllowSomeScriptContextSettings() throws IOException {
Settings.Builder builder = Settings.builder();
builder.put("script.contexts_allowed", "search, aggs");
- builder.put("script.update", false);
buildScriptService(builder.build());
assertCompileAccepted("painless", "script", ScriptType.INLINE, ScriptContext.Standard.SEARCH);
assertCompileAccepted("painless", "script", ScriptType.INLINE, ScriptContext.Standard.AGGS);
assertCompileRejected("painless", "script", ScriptType.INLINE, ScriptContext.Standard.UPDATE);
-
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.update"));
}
public void testAllowNoScriptTypeSettings() throws IOException {
Settings.Builder builder = Settings.builder();
- builder.put("script.types_allowed", "");
+ builder.put("script.types_allowed", "none");
buildScriptService(builder.build());
assertCompileRejected("painless", "script", ScriptType.INLINE, ScriptContext.Standard.SEARCH);
@@ -214,7 +201,7 @@ public class ScriptServiceTests extends ESTestCase {
public void testAllowNoScriptContextSettings() throws IOException {
Settings.Builder builder = Settings.builder();
- builder.put("script.contexts_allowed", "");
+ builder.put("script.contexts_allowed", "none");
buildScriptService(builder.build());
assertCompileRejected("painless", "script", ScriptType.INLINE, ScriptContext.Standard.SEARCH);
@@ -223,109 +210,6 @@ public class ScriptServiceTests extends ESTestCase {
assertCompileRejected("painless", "script", ScriptType.INLINE, ScriptContext.Standard.INGEST);
}
- public void testDefaultBehaviourFineGrainedSettings() throws IOException {
- Settings.Builder builder = Settings.builder();
- buildScriptService(builder.build());
-
- for (ScriptContext scriptContext : scriptContexts) {
- assertCompileRejected("dtest", "script", ScriptType.INLINE, scriptContext);
- assertCompileRejected("dtest", "script", ScriptType.STORED, scriptContext);
- }
- }
-
- public void testFineGrainedSettings() throws IOException {
- //collect the fine-grained settings to set for this run
- int numScriptSettings = randomIntBetween(0, ScriptType.values().length);
- Map<ScriptType, Boolean> scriptSourceSettings = new HashMap<>();
- for (int i = 0; i < numScriptSettings; i++) {
- ScriptType scriptType;
- do {
- scriptType = randomFrom(ScriptType.values());
- } while (scriptSourceSettings.containsKey(scriptType));
- scriptSourceSettings.put(scriptType, randomBoolean());
- }
- int numScriptContextSettings = randomIntBetween(0, this.scriptContextRegistry.scriptContexts().size());
- Map<ScriptContext, Boolean> scriptContextSettings = new HashMap<>();
- for (int i = 0; i < numScriptContextSettings; i++) {
- ScriptContext scriptContext;
- do {
- scriptContext = randomFrom(this.scriptContexts);
- } while (scriptContextSettings.containsKey(scriptContext));
- scriptContextSettings.put(scriptContext, randomBoolean());
- }
- int numEngineSettings = randomIntBetween(0, ScriptType.values().length * scriptContexts.length);
- Map<String, Boolean> engineSettings = new HashMap<>();
- for (int i = 0; i < numEngineSettings; i++) {
- String settingKey;
- do {
- ScriptType scriptType = randomFrom(ScriptType.values());
- ScriptContext scriptContext = randomFrom(this.scriptContexts);
- settingKey = scriptEngine.getType() + "." + scriptType + "." + scriptContext.getKey();
- } while (engineSettings.containsKey(settingKey));
- engineSettings.put(settingKey, randomBoolean());
- }
- List<String> deprecated = new ArrayList<>();
- //set the selected fine-grained settings
- Settings.Builder builder = Settings.builder();
- for (Map.Entry<ScriptType, Boolean> entry : scriptSourceSettings.entrySet()) {
- if (entry.getValue()) {
- builder.put("script" + "." + entry.getKey().getName(), "true");
- } else {
- builder.put("script" + "." + entry.getKey().getName(), "false");
- }
- deprecated.add("script" + "." + entry.getKey().getName());
- }
- for (Map.Entry<ScriptContext, Boolean> entry : scriptContextSettings.entrySet()) {
- if (entry.getValue()) {
- builder.put("script" + "." + entry.getKey().getKey(), "true");
- } else {
- builder.put("script" + "." + entry.getKey().getKey(), "false");
- }
- deprecated.add("script" + "." + entry.getKey().getKey());
- }
- for (Map.Entry<String, Boolean> entry : engineSettings.entrySet()) {
- int delimiter = entry.getKey().indexOf('.');
- String part1 = entry.getKey().substring(0, delimiter);
- String part2 = entry.getKey().substring(delimiter + 1);
-
- String lang = randomFrom(scriptEnginesByLangMap.get(part1).getType());
- if (entry.getValue()) {
- builder.put("script.engine" + "." + lang + "." + part2, "true");
- } else {
- builder.put("script.engine" + "." + lang + "." + part2, "false");
- }
- deprecated.add("script.engine" + "." + lang + "." + part2);
- }
-
- buildScriptService(builder.build());
-
- for (ScriptType scriptType : ScriptType.values()) {
- String 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(dangerousScriptEngine.getType() + "." + scriptType + "." + scriptContext.getKey());
- if (scriptEnabled == null) {
- scriptEnabled = scriptContextSettings.get(scriptContext);
- }
- if (scriptEnabled == null) {
- scriptEnabled = scriptSourceSettings.get(scriptType);
- }
- if (scriptEnabled == null) {
- scriptEnabled = DEFAULT_SCRIPT_ENABLED.get(scriptType);
- }
-
- String lang = dangerousScriptEngine.getType();
- if (scriptEnabled) {
- assertCompileAccepted(lang, script, scriptType, scriptContext);
- } else {
- assertCompileRejected(lang, script, scriptType, scriptContext);
- }
- }
- }
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, deprecated.toArray(new String[] {})));
- }
-
public void testCompileNonRegisteredContext() throws IOException {
buildScriptService(Settings.EMPTY);
String pluginName;
@@ -378,14 +262,11 @@ public class ScriptServiceTests extends ESTestCase {
public void testCompilationStatsOnCacheHit() throws IOException {
Settings.Builder builder = Settings.builder();
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), 1);
- builder.put("script.inline", "true");
buildScriptService(builder.build());
Script script = new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap());
scriptService.compile(script, randomFrom(scriptContexts));
scriptService.compile(script, randomFrom(scriptContexts));
assertEquals(1L, scriptService.stats().getCompilations());
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.inline"));
}
public void testIndexedScriptCountedInCompilationStats() throws IOException {
@@ -397,25 +278,19 @@ public class ScriptServiceTests extends ESTestCase {
public void testCacheEvictionCountedInCacheEvictionsStats() throws IOException {
Settings.Builder builder = Settings.builder();
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), 1);
- builder.put("script.inline", "true");
buildScriptService(builder.build());
scriptService.compile(new Script(ScriptType.INLINE, "test", "1+1", Collections.emptyMap()), randomFrom(scriptContexts));
scriptService.compile(new Script(ScriptType.INLINE, "test", "2+2", Collections.emptyMap()), randomFrom(scriptContexts));
assertEquals(2L, scriptService.stats().getCompilations());
assertEquals(1L, scriptService.stats().getCacheEvictions());
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.inline"));
}
public void testDefaultLanguage() throws IOException {
Settings.Builder builder = Settings.builder();
- builder.put("script.inline", "true");
buildScriptService(builder.build());
CompiledScript script = scriptService.compile(
new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "1 + 1", Collections.emptyMap()), randomFrom(scriptContexts));
assertEquals(script.lang(), Script.DEFAULT_SCRIPT_LANG);
- assertSettingDeprecationsAndWarnings(
- ScriptSettingsTests.buildDeprecatedSettingsArray(scriptSettings, "script.inline"));
}
public void testStoreScript() throws Exception {
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java b/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java
deleted file mode 100644
index b435fff52d..0000000000
--- a/core/src/test/java/org/elasticsearch/script/ScriptSettingsTests.java
+++ /dev/null
@@ -1,98 +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.script;
-
-import org.elasticsearch.common.Nullable;
-import org.elasticsearch.common.settings.Setting;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.search.lookup.SearchLookup;
-import org.elasticsearch.test.ESTestCase;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.equalTo;
-
-public class ScriptSettingsTests extends ESTestCase {
-
-
- public static Setting<?>[] buildDeprecatedSettingsArray(ScriptSettings scriptSettings, String... keys) {
- Setting<?>[] settings = new Setting[keys.length];
- int count = 0;
-
- for (Setting<?> setting : scriptSettings.getSettings()) {
- for (String key : keys) {
- if (setting.getKey().equals(key)) {
- settings[count++] = setting;
- }
- }
- }
-
- return settings;
- }
-
- public void testSettingsAreProperlyPropogated() {
- ScriptEngineRegistry scriptEngineRegistry =
- new ScriptEngineRegistry(Collections.singletonList(new CustomScriptEngine()));
- ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
- ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
- boolean enabled = randomBoolean();
- Settings s = Settings.builder().put("script.inline", enabled).build();
- for (Iterator<Setting<Boolean>> iter = scriptSettings.getScriptLanguageSettings().iterator(); iter.hasNext();) {
- Setting<Boolean> setting = iter.next();
- if (setting.getKey().endsWith(".inline")) {
- assertThat("inline settings should have propagated", setting.get(s), equalTo(enabled));
- assertThat(setting.getDefaultRaw(s), equalTo(Boolean.toString(enabled)));
- }
- }
- assertSettingDeprecationsAndWarnings(buildDeprecatedSettingsArray(scriptSettings, "script.inline"));
- }
-
- private static class CustomScriptEngine implements ScriptEngine {
-
- public static final String NAME = "custom";
-
- @Override
- public String getType() {
- return NAME;
- }
-
- @Override
- public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
- return null;
- }
-
- @Override
- public ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars) {
- return null;
- }
-
- @Override
- public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
- return null;
- }
-
- @Override
- public void close() {
- }
- }
-
-}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java
index 283f964b68..db5a0a1cd8 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java
@@ -1162,7 +1162,61 @@ public class DateHistogramIT extends ESIntegTestCase {
assertThat(bucket.getDocCount(), equalTo(0L));
}
}
- internalCluster().wipeIndices("test12278");
+ internalCluster().wipeIndices(index);
+ }
+
+ /**
+ * Test date histogram aggregation with day interval, offset and
+ * extended bounds (see https://github.com/elastic/elasticsearch/issues/23776)
+ */
+ public void testSingleValueFieldWithExtendedBoundsOffset() throws Exception {
+ String index = "test23776";
+ prepareCreate(index)
+ .setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1).put("index.number_of_replicas", 0))
+ .execute().actionGet();
+
+ List<IndexRequestBuilder> builders = new ArrayList<>();
+ builders.add(indexDoc(index, DateTime.parse("2016-01-03T08:00:00.000Z"), 1));
+ builders.add(indexDoc(index, DateTime.parse("2016-01-03T08:00:00.000Z"), 2));
+ builders.add(indexDoc(index, DateTime.parse("2016-01-06T08:00:00.000Z"), 3));
+ builders.add(indexDoc(index, DateTime.parse("2016-01-06T08:00:00.000Z"), 4));
+ indexRandom(true, builders);
+ ensureSearchable(index);
+
+ SearchResponse response = null;
+ // retrieve those docs with the same time zone and extended bounds
+ response = client()
+ .prepareSearch(index)
+ .addAggregation(
+ dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.days(1)).offset("+6h").minDocCount(0)
+ .extendedBounds(new ExtendedBounds("2016-01-01T06:00:00Z", "2016-01-08T08:00:00Z"))
+ ).execute().actionGet();
+ assertSearchResponse(response);
+
+ Histogram histo = response.getAggregations().get("histo");
+ assertThat(histo, notNullValue());
+ assertThat(histo.getName(), equalTo("histo"));
+ List<? extends Bucket> buckets = histo.getBuckets();
+ assertThat(buckets.size(), equalTo(8));
+
+ assertEquals("2016-01-01T06:00:00.000Z", buckets.get(0).getKeyAsString());
+ assertEquals(0, buckets.get(0).getDocCount());
+ assertEquals("2016-01-02T06:00:00.000Z", buckets.get(1).getKeyAsString());
+ assertEquals(0, buckets.get(1).getDocCount());
+ assertEquals("2016-01-03T06:00:00.000Z", buckets.get(2).getKeyAsString());
+ assertEquals(2, buckets.get(2).getDocCount());
+ assertEquals("2016-01-04T06:00:00.000Z", buckets.get(3).getKeyAsString());
+ assertEquals(0, buckets.get(3).getDocCount());
+ assertEquals("2016-01-05T06:00:00.000Z", buckets.get(4).getKeyAsString());
+ assertEquals(0, buckets.get(4).getDocCount());
+ assertEquals("2016-01-06T06:00:00.000Z", buckets.get(5).getKeyAsString());
+ assertEquals(2, buckets.get(5).getDocCount());
+ assertEquals("2016-01-07T06:00:00.000Z", buckets.get(6).getKeyAsString());
+ assertEquals(0, buckets.get(6).getDocCount());
+ assertEquals("2016-01-08T06:00:00.000Z", buckets.get(7).getKeyAsString());
+ assertEquals(0, buckets.get(7).getDocCount());
+
+ internalCluster().wipeIndices(index);
}
public void testSingleValueWithMultipleDateFormatsFromMapping() throws Exception {
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 33ba2684f7..093dab2f4f 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
@@ -29,7 +29,6 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContextRegistry;
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.ParsedAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@@ -122,10 +121,8 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
}));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
- ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
try {
- return new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry,
- scriptSettings);
+ return new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry);
} catch (IOException e) {
throw new ElasticsearchException(e);
}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java
index 58487a715e..441be5b0e8 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java
@@ -38,7 +38,6 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContextRegistry;
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.AggregatorTestCase;
import org.junit.BeforeClass;
@@ -201,10 +200,9 @@ public class ScriptedMetricAggregatorTests extends AggregatorTestCase {
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS);
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
- ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService;
try {
- scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
+ scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, scriptContextRegistry);
} catch (IOException e) {
throw new ElasticsearchException(e);
}
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 ee671ca3d0..83a3cf8514 100644
--- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java
+++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java
@@ -57,7 +57,6 @@ import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptServiceTests.TestEngine;
-import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.SearchModule;
@@ -89,11 +88,9 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
.put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder)
.build();
- Environment environment = new Environment(baseSettings);
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngine()));
- ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
- scriptService = new ScriptService(baseSettings, scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
+ scriptService = new ScriptService(baseSettings, scriptEngineRegistry, scriptContextRegistry) {
@Override
public CompiledScript compile(Script script, ScriptContext scriptContext) {
return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);