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/15 23:21:24 UTC
[16/46] incubator-tinkerpop git commit: Pulled out TimedInterrupt
compiler provider tests to their own case
Pulled out TimedInterrupt compiler provider tests to their own case
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/9149c205
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/9149c205
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/9149c205
Branch: refs/heads/master
Commit: 9149c2058577c9c7fc5b0c3f703ac8baeb5ab884
Parents: 6b8628b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 9 08:31:47 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 9 08:31:47 2015 -0400
----------------------------------------------------------------------
.../jsr223/GremlinGroovyScriptEngineTest.java | 58 ------------
...linGroovyScriptEngineTimedInterruptTest.java | 94 ++++++++++++++++++++
2 files changed, 94 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9149c205/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 15c4cb4..3fda86b 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
@@ -309,64 +309,6 @@ public class GremlinGroovyScriptEngineTest {
assertEquals("轉注", engine.eval("'轉注'"));
}
- @Test
- public void shouldTimeoutScriptOnTimedWhile() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
- fail("This should have timed out");
- } catch (ScriptException se) {
- assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
- }
- }
-
- @Test
- public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
- Thread.sleep(2000);
- try {
- engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
- fail("This should have timed out");
- } catch (ScriptException se) {
- assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
- }
-
- assertEquals(2, engine.eval("1+1"));
- }
-
- @Test
- public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(50), new DefaultImportCustomizerProvider());
-
- for (int ix = 0; ix < 10; ix++) {
- 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'"));
- }
-
- assertEquals(2, engine.eval("1+1"));
- }
-
- @Test
- public void shouldNotTimeoutStandaloneFunction() throws Exception {
- // use a super fast timeout which should not prevent the call of a cached function
- final ScriptEngine engine = new GremlinGroovyScriptEngine(
- new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider());
- engine.eval("def addItUp(x,y) { x + y }");
-
- assertEquals(3, engine.eval("addItUp(1,2)"));
- }
-
public static class DenyAll extends GroovyValueFilter {
@Override
public Object filter(final Object o) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9149c205/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
new file mode 100644
index 0000000..40d0104
--- /dev/null
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.apache.tinkerpop.gremlin.groovy.jsr223;
+
+import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TimedInterruptCustomizerProvider;
+import org.junit.Test;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GremlinGroovyScriptEngineTimedInterruptTest {
+
+ @Test
+ public void shouldTimeoutScriptOnTimedWhile() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+ }
+
+ @Test
+ public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider());
+ Thread.sleep(2000);
+ try {
+ engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}");
+ fail("This should have timed out");
+ } catch (ScriptException se) {
+ assertEquals(TimeoutException.class, se.getCause().getCause().getClass());
+ }
+
+ assertEquals(2, engine.eval("1+1"));
+ }
+
+ @Test
+ public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(50), new DefaultImportCustomizerProvider());
+
+ for (int ix = 0; ix < 10; ix++) {
+ 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'"));
+ }
+
+ assertEquals(2, engine.eval("1+1"));
+ }
+
+ @Test
+ public void shouldNotTimeoutStandaloneFunction() throws Exception {
+ // use a super fast timeout which should not prevent the call of a cached function
+ final ScriptEngine engine = new GremlinGroovyScriptEngine(
+ new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider());
+ engine.eval("def addItUp(x,y) { x + y }");
+
+ assertEquals(3, engine.eval("addItUp(1,2)"));
+ }
+}