summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java')
-rw-r--r--core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java78
1 files changed, 30 insertions, 48 deletions
diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
index 3c939e7e91..f94835e90a 100644
--- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java
@@ -18,8 +18,6 @@
*/
package org.elasticsearch.script;
-import org.elasticsearch.common.ContextAndHeaderHolder;
-import org.elasticsearch.common.HasContextAndHeaders;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
@@ -101,7 +99,7 @@ public class ScriptServiceTests extends ESTestCase {
Environment environment = new Environment(finalSettings);
scriptService = new ScriptService(finalSettings, environment, Collections.singleton(scriptEngineService), resourceWatcherService, scriptContextRegistry) {
@Override
- String getScriptFromIndex(String scriptLang, String id, HasContextAndHeaders headersContext) {
+ String getScriptFromIndex(String scriptLang, String id) {
//mock the script that gets retrieved from an index
return "100";
}
@@ -119,7 +117,6 @@ public class ScriptServiceTests extends ESTestCase {
public void testScriptsWithoutExtensions() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
logger.info("--> setup two test files one with extension and another without");
Path testFileNoExt = scriptsFilePath.resolve("test_no_ext");
@@ -130,7 +127,7 @@ public class ScriptServiceTests extends ESTestCase {
logger.info("--> verify that file with extension was correctly processed");
CompiledScript compiledScript = scriptService.compile(new Script("test_script", ScriptType.FILE, "test", null),
- ScriptContext.Standard.SEARCH, contextAndHeaders, Collections.emptyMap());
+ ScriptContext.Standard.SEARCH, Collections.emptyMap());
assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file"));
logger.info("--> delete both files");
@@ -141,7 +138,7 @@ public class ScriptServiceTests extends ESTestCase {
logger.info("--> verify that file with extension was correctly removed");
try {
scriptService.compile(new Script("test_script", ScriptType.FILE, "test", null), ScriptContext.Standard.SEARCH,
- contextAndHeaders, Collections.emptyMap());
+ Collections.emptyMap());
fail("the script test_script should no longer exist");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), containsString("Unable to find on disk file script [test_script] using lang [test]"));
@@ -149,38 +146,34 @@ public class ScriptServiceTests extends ESTestCase {
}
public void testInlineScriptCompiledOnceCache() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
CompiledScript compiledScript1 = scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
CompiledScript compiledScript2 = scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
assertThat(compiledScript1.compiled(), sameInstance(compiledScript2.compiled()));
}
public void testInlineScriptCompiledOnceMultipleLangAcronyms() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
CompiledScript compiledScript1 = scriptService.compile(new Script("script", ScriptType.INLINE, "test", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
CompiledScript compiledScript2 = scriptService.compile(new Script("script", ScriptType.INLINE, "test2", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
assertThat(compiledScript1.compiled(), sameInstance(compiledScript2.compiled()));
}
public void testFileScriptCompiledOnceMultipleLangAcronyms() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
createFileScripts("test");
CompiledScript compiledScript1 = scriptService.compile(new Script("file_script", ScriptType.FILE, "test", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
CompiledScript compiledScript2 = scriptService.compile(new Script("file_script", ScriptType.FILE, "test2", null),
- randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ randomFrom(scriptContexts), Collections.emptyMap());
assertThat(compiledScript1.compiled(), sameInstance(compiledScript2.compiled()));
}
public void testDefaultBehaviourFineGrainedSettings() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
Settings.Builder builder = Settings.builder();
//rarely inject the default settings, which have no effect
if (rarely()) {
@@ -197,14 +190,13 @@ public class ScriptServiceTests extends ESTestCase {
for (ScriptContext scriptContext : scriptContexts) {
//custom engine is sandboxed, all scripts are enabled by default
- assertCompileAccepted("test", "script", ScriptType.INLINE, scriptContext, contextAndHeaders);
- assertCompileAccepted("test", "script", ScriptType.INDEXED, scriptContext, contextAndHeaders);
- assertCompileAccepted("test", "file_script", ScriptType.FILE, scriptContext, contextAndHeaders);
+ assertCompileAccepted("test", "script", ScriptType.INLINE, scriptContext);
+ assertCompileAccepted("test", "script", ScriptType.INDEXED, scriptContext);
+ assertCompileAccepted("test", "file_script", ScriptType.FILE, scriptContext);
}
}
public void testFineGrainedSettings() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
//collect the fine-grained settings to set for this run
int numScriptSettings = randomIntBetween(0, ScriptType.values().length);
Map<ScriptType, ScriptMode> scriptSourceSettings = new HashMap<>();
@@ -305,16 +297,16 @@ public class ScriptServiceTests extends ESTestCase {
for (String lang : scriptEngineService.types()) {
switch (scriptMode) {
case ON:
- assertCompileAccepted(lang, script, scriptType, scriptContext, contextAndHeaders);
+ assertCompileAccepted(lang, script, scriptType, scriptContext);
break;
case OFF:
- assertCompileRejected(lang, script, scriptType, scriptContext, contextAndHeaders);
+ assertCompileRejected(lang, script, scriptType, scriptContext);
break;
case SANDBOX:
if (scriptEngineService.sandboxed()) {
- assertCompileAccepted(lang, script, scriptType, scriptContext, contextAndHeaders);
+ assertCompileAccepted(lang, script, scriptType, scriptContext);
} else {
- assertCompileRejected(lang, script, scriptType, scriptContext, contextAndHeaders);
+ assertCompileRejected(lang, script, scriptType, scriptContext);
}
break;
}
@@ -324,7 +316,6 @@ public class ScriptServiceTests extends ESTestCase {
}
public void testCompileNonRegisteredContext() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
String pluginName;
String unknownContext;
@@ -336,7 +327,7 @@ public class ScriptServiceTests extends ESTestCase {
for (String type : scriptEngineService.types()) {
try {
scriptService.compile(new Script("test", randomFrom(ScriptType.values()), type, null), new ScriptContext.Plugin(
- pluginName, unknownContext), contextAndHeaders, Collections.emptyMap());
+ pluginName, unknownContext), Collections.emptyMap());
fail("script compilation should have been rejected");
} catch(IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("script context [" + pluginName + "_" + unknownContext + "] not supported"));
@@ -345,16 +336,14 @@ public class ScriptServiceTests extends ESTestCase {
}
public void testCompileCountedInCompilationStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
- scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.compile(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(1L, scriptService.stats().getCompilations());
}
public void testExecutableCountedInCompilationStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
- scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(1L, scriptService.stats().getCompilations());
}
@@ -365,48 +354,43 @@ public class ScriptServiceTests extends ESTestCase {
}
public void testMultipleCompilationsCountedInCompilationStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
int numberOfCompilations = randomIntBetween(1, 1024);
for (int i = 0; i < numberOfCompilations; i++) {
scriptService
- .compile(new Script(i + " + " + i, ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ .compile(new Script(i + " + " + i, ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
}
assertEquals(numberOfCompilations, scriptService.stats().getCompilations());
}
public void testCompilationStatsOnCacheHit() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
Settings.Builder builder = Settings.builder();
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING, 1);
buildScriptService(builder.build());
- scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
- scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
+ scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(1L, scriptService.stats().getCompilations());
}
public void testFileScriptCountedInCompilationStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
createFileScripts("test");
- scriptService.compile(new Script("file_script", ScriptType.FILE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.compile(new Script("file_script", ScriptType.FILE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(1L, scriptService.stats().getCompilations());
}
public void testIndexedScriptCountedInCompilationStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
buildScriptService(Settings.EMPTY);
- scriptService.compile(new Script("script", ScriptType.INDEXED, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.compile(new Script("script", ScriptType.INDEXED, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(1L, scriptService.stats().getCompilations());
}
public void testCacheEvictionCountedInCacheEvictionsStats() throws IOException {
- ContextAndHeaderHolder contextAndHeaders = new ContextAndHeaderHolder();
Settings.Builder builder = Settings.builder();
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING, 1);
buildScriptService(builder.build());
- scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
- scriptService.executable(new Script("2+2", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), contextAndHeaders, Collections.emptyMap());
+ scriptService.executable(new Script("1+1", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
+ scriptService.executable(new Script("2+2", ScriptType.INLINE, "test", null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(2L, scriptService.stats().getCompilations());
assertEquals(1L, scriptService.stats().getCacheEvictions());
}
@@ -419,19 +403,17 @@ public class ScriptServiceTests extends ESTestCase {
resourceWatcherService.notifyNow();
}
- private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext scriptContext,
- HasContextAndHeaders contextAndHeaders) {
+ private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) {
try {
- scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, contextAndHeaders, Collections.emptyMap());
+ scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, Collections.emptyMap());
fail("compile should have been rejected for lang [" + lang + "], script_type [" + scriptType + "], scripted_op [" + scriptContext + "]");
} catch(ScriptException e) {
//all good
}
}
- private void assertCompileAccepted(String lang, String script, ScriptType scriptType, ScriptContext scriptContext,
- HasContextAndHeaders contextAndHeaders) {
- assertThat(scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, contextAndHeaders, Collections.emptyMap()), notNullValue());
+ private void assertCompileAccepted(String lang, String script, ScriptType scriptType, ScriptContext scriptContext) {
+ assertThat(scriptService.compile(new Script(script, scriptType, lang, null), scriptContext, Collections.emptyMap()), notNullValue());
}
public static class TestEngineService implements ScriptEngineService {