You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/07/08 17:21:14 UTC
[2/2] incubator-tinkerpop git commit: Added interruptionTimeout
custom config to ScriptEngines.
Added interruptionTimeout custom config to ScriptEngines.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/46fc9896
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/46fc9896
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/46fc9896
Branch: refs/heads/master
Commit: 46fc98966e8c418189e6ea2cff201418e55a3fa3
Parents: be0c197
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 8 11:20:23 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 8 11:20:23 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/groovy/engine/ScriptEngines.java | 9 ++++--
.../groovy/engine/GremlinExecutorTest.java | 31 ++++++++++++++++++++
.../jsr223/GremlinGroovyScriptEngineTest.java | 3 +-
4 files changed, 41 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46fc9896/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 308a9ce..9c6264e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ TinkerPop 3.0.0.GA (NOT OFFICIALLY RELEASED YET)
* Modified the `GremlinExecutor` to catch `Throwable` as opposed to `Exception` so as to properly handle `Error` based exceptions.
* Modified the `GremlinGroovyScriptEngine` compilation configuration to prevent inappropriate script evaluation timeouts on standalone functions.
+* Added a custom configuration for "timed interrupt" in the `ScriptEngines` instantiation of the `GremlinGroovyScriptEngine`.
* Added `mapKeys()` (`MapKeyStep`) and `mapValues()` (`MapValueStep`) to get the keys and values of a map, respectively.
* `select()` no longer supports empty arguments. The user must specify the keys they are selecting.
* `MatchStep` and `match()` no longer have a "start label" parameter -- it is computed if the incoming traverser does not have requisite labels.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46fc9896/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
index f0b919c..5ff4494 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
@@ -158,7 +158,8 @@ public class ScriptEngines implements AutoCloseable {
* Reload a {@code ScriptEngine} with fresh imports. Waits for any existing script evaluations to complete but
* then blocks other operations until complete.
*/
- public void reload(final String language, final Set<String> imports, final Set<String> staticImports, final Map<String, Object> config) {
+ public void reload(final String language, final Set<String> imports, final Set<String> staticImports,
+ final Map<String, Object> config) {
signalControlOp();
try {
@@ -341,8 +342,12 @@ public class ScriptEngines implements AutoCloseable {
}
}
+ final long interruptionTimeout = ((Number) config.getOrDefault("interruptionTimeout",
+ GremlinGroovyScriptEngine.DEFAULT_SCRIPT_EVALUATION_TIMEOUT)).longValue();
+
return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(
- new DefaultImportCustomizerProvider(imports, staticImports), securityCustomizerProvider));
+ new DefaultImportCustomizerProvider(imports, staticImports), securityCustomizerProvider,
+ interruptionTimeout));
} else {
return Optional.ofNullable(SCRIPT_ENGINE_MANAGER.getEngineByName(language));
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46fc9896/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
index 2507421..480c72f 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
@@ -26,6 +26,7 @@ import org.kohsuke.groovy.sandbox.GroovyInterceptor;
import javax.script.Bindings;
import javax.script.CompiledScript;
+import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.util.Arrays;
import java.util.Collections;
@@ -433,6 +434,36 @@ public class GremlinExecutorTest {
}
@Test
+ public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
+ GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
+ final Map<String, Object> config = new HashMap<>();
+ config.put("interruptionTimeout", 50l);
+ final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
+ .addEngineSettings("gremlin-groovy",
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")),
+ config)
+ .create();
+
+ for (int ix = 0; ix < 10; ix++) {
+ try {
+ // this script takes 10 ms longer than the interruptionTimeout
+ gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 60) {}").get();
+ fail("This should have timed out");
+ } catch (Exception se) {
+ assertEquals(TimeoutException.class, se.getCause().getClass());
+ }
+
+ // this script takes 10 ms less than the interruptionTimeout
+ assertEquals("test", gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 40) {};'test'").get());
+ }
+
+ gremlinExecutor.close();
+ }
+
+
+ @Test
public void shouldSecureAll() throws Exception {
GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
final Map<String, Object> config = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46fc9896/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
index 5c7f74b..6c6ade0 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
@@ -338,14 +338,15 @@ public class GremlinGroovyScriptEngineTest {
final ScriptEngine engine = new GremlinGroovyScriptEngine(new DefaultImportCustomizerProvider(), null, 50);
for (int ix = 0; ix < 10; ix++) {
- Thread.sleep(60);
try {
+ // this script takes 10 ms longer than the interruptionTimeout
engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 60) {}");
fail("This should have timed out");
} catch (ScriptException se) {
assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
}
+ // this script takes 10 ms less than the interruptionTimeout
assertEquals("test", engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 40) {};'test'"));
}