tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject incubator-tinkerpop git commit: Adjust tests to be a bit more bulletproof with respect to thread timing.
Date Wed, 02 Dec 2015 19:21:58 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-1006 [created] 87201658f


Adjust tests to be a bit more bulletproof with respect to thread timing.

Not sure if i've fixed anything with this change as these tests have never failed for me on
my system.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/87201658
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/87201658
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/87201658

Branch: refs/heads/TINKERPOP3-1006
Commit: 87201658f2023c725d4620b4a700b949605099a7
Parents: 59eaa06
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Dec 2 14:20:30 2015 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Dec 2 14:20:49 2015 -0500

----------------------------------------------------------------------
 .../groovy/engine/GremlinExecutorTest.java      |  8 +--
 .../jsr223/GremlinGroovyScriptEngineTest.java   | 52 ++++++++++++--------
 2 files changed, 35 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/87201658/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 c30ad79..7bc0708 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
@@ -478,7 +478,7 @@ public class GremlinExecutorTest {
     public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception {
         final Map<String,List<Object>> compilerCustomizerConfig = new HashMap<>();
         final List<Object> args = new ArrayList<>();
-        args.add(50);
+        args.add(250);
         compilerCustomizerConfig.put(TimedInterruptCustomizerProvider.class.getName(), args);
 
         final Map<String, Object> config = new HashMap<>();
@@ -494,14 +494,14 @@ public class GremlinExecutorTest {
 
         for (int ix = 0; ix < 5; ix++) {
             try {
-                // this script takes 10 ms longer than the interruptionTimeout
-                gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis()
- s) < 100) {}").get();
+                // this script takes significantly longer than the interruptionTimeout
+                gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis()
- s) < 10000) {}").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
+            // this script takes significantly less than the interruptionTimeout
             assertEquals("test", gremlinExecutor.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis()
- s) < 20) {};'test'").get());
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/87201658/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 9e74686..f3b3835 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
@@ -29,12 +29,17 @@ import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 import javax.script.SimpleBindings;
+import java.awt.*;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -203,51 +208,56 @@ public class GremlinGroovyScriptEngineTest {
     @Test
     public void shouldReloadClassLoaderWhileDoingEvalInSeparateThread() throws Exception
{
         final AtomicBoolean fail = new AtomicBoolean(false);
+        final AtomicInteger counter = new AtomicInteger(0);
         final CountDownLatch latch = new CountDownLatch(1);
+        final AtomicReference<Color> color = new AtomicReference<>(Color.RED);
+
         final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine();
-        final Thread t = new Thread(() -> {
-            try {
-                final Object o = scriptEngine.eval("Color.BLACK");
-                System.out.println("Should not print: " + o);
-                fail.set(true);
-            } catch (ScriptException se) {
-                // should get here as Color.BLACK is not imported yet.
-                System.out.println("Failed to execute Color.BLACK as expected.");
-            }
 
+        try {
+            scriptEngine.eval("Color.BLACK");
+            fail("Should fail as class is not yet imported");
+        } catch (ScriptException se) {
+            // should get here as Color.BLACK is not imported yet.
+            System.out.println("Failed to execute Color.BLACK as expected.");
+        }
+
+        final Thread evalThread = new Thread(() -> {
             try {
-                int counter = 0;
+                // execute scripts until the other thread releases this latch (i.e. after
import)
                 while (latch.getCount() == 1) {
                     scriptEngine.eval("1+1");
-                    counter++;
+                    counter.incrementAndGet();
                 }
 
-                System.out.println(counter + " executions.");
-
-                scriptEngine.eval("Color.BLACK");
-                System.out.println("Color.BLACK now evaluates");
+                color.set((Color) scriptEngine.eval("Color.BLACK"));
             } catch (Exception se) {
-                se.printStackTrace();
                 fail.set(true);
             }
         }, "test-reload-classloader-1");
 
-        t.start();
+        evalThread.start();
 
-        // let the first thead execute a bit.
+        // let the first thread execute a bit.
         Thread.sleep(1000);
 
-        new Thread(() -> {
+        final Thread importThread = new Thread(() -> {
             System.out.println("Importing java.awt.Color...");
             final Set<String> imports = new HashSet<String>() {{
                 add("import java.awt.Color");
             }};
             scriptEngine.addImports(imports);
             latch.countDown();
-        }, "test-reload-classloader-2").start();
+        }, "test-reload-classloader-2");
+
+        importThread.start();
 
-        t.join();
+        // block until both threads are done
+        importThread.join();
+        evalThread.join();
 
+        assertEquals(Color.BLACK, color.get());
+        assertThat(counter.get(), greaterThan(0));
         assertFalse(fail.get());
     }
 


Mime
View raw message