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 2016/03/14 20:28:35 UTC

incubator-tinkerpop git commit: Complete the eval() future after the whole lifecycle.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp31 675d9819d -> da5abb053


Complete the eval() future after the whole lifecycle.

This prevents problems with where the eval future would complete but then an exeption would toss later in the lifecycle and the future wouldn't get notified again.  Fixed a test where this problem was previously hiding that the test was erroring out. CTR


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

Branch: refs/heads/tp31
Commit: da5abb0534123dbf2707fdece6b98d6846a12a27
Parents: 675d981
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Mar 14 15:25:33 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Mar 14 15:28:26 2016 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../engine/GremlinExecutorOverGraphTest.java    |  7 ++---
 .../gremlin/groovy/engine/GremlinExecutor.java  | 12 ++++++---
 .../groovy/engine/GremlinExecutorTest.java      | 27 ++++++++++++++++----
 4 files changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da5abb05/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e03e3bf..fd6a766 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* The future from `GremlinExecutor.eval()` is completed after the entire evaluation lifecyle is completed.
 * Spark `Memory` uses `collect().iterator()` instead of `toLocalIterator()` to reduce noise in Spark UI.
 * Added the `:remote console` option which flips the Gremlin Console into a remote-only mode where all script evaluation is routed to the currently configured remote, which removes the need to use the `:>` command.
 * Added `allowRemoteConsole()` to the `RemoteAcceptor` interface.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da5abb05/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java
index cc6b34f..4ee3bf2 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.groovy.engine;
 import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.junit.Test;
 
@@ -50,9 +51,9 @@ public class GremlinExecutorOverGraphTest extends AbstractGremlinTest {
         final ExecutorService evalExecutor = Executors.newSingleThreadExecutor(testingThreadFactory);
         final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
                 .afterSuccess(b -> {
-                    final Graph graph = (Graph) b.get("g");
-                    if (graph.features().graph().supportsTransactions())
-                        graph.tx().commit();
+                    final GraphTraversalSource g = (GraphTraversalSource) b.get("g");
+                    if (g.getGraph().get().features().graph().supportsTransactions())
+                        g.tx().commit();
                 })
                 .executorService(evalExecutor).create();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da5abb05/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
index df8b583..edd421d 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
@@ -262,7 +262,6 @@ public class GremlinExecutor implements AutoCloseable {
                 // transactional constraints
                 final Object result = lifeCycle.getTransformResult().isPresent() ?
                         lifeCycle.getTransformResult().get().apply(o) : o;
-                evaluationFuture.complete(result);
 
                 // a mechanism for taking the final result and doing something with it in the same thread, but
                 // AFTER the eval and transform are done and that future completed.  this provides a final means
@@ -270,6 +269,12 @@ public class GremlinExecutor implements AutoCloseable {
                 if (lifeCycle.getWithResult().isPresent()) lifeCycle.getWithResult().get().accept(result);
 
                 lifeCycle.getAfterSuccess().orElse(afterSuccess).accept(bindings);
+
+                // the evaluationFuture must be completed after all processing as an exception in lifecycle events
+                // that must raise as an exception to the caller who has the returned evaluationFuture. in other words,
+                // if it occurs before this point, then the handle() method won't be called again if there is an
+                // exception that ends up below trying to completeExceptionally()
+                evaluationFuture.complete(result);
             } catch (Throwable ex) {
                 final Throwable root = null == ex.getCause() ? ex : ExceptionUtils.getRootCause(ex);
 
@@ -746,7 +751,7 @@ public class GremlinExecutor implements AutoCloseable {
 
             /**
              * Specifies the function to execute on the result of the script evaluation just after script evaluation
-             * returns but after the script evaluation is marked as complete.
+             * returns but before the script evaluation is marked as complete.
              */
             public Builder withResult(final Consumer<Object> withResult) {
                 this.withResult = withResult;
@@ -755,7 +760,8 @@ public class GremlinExecutor implements AutoCloseable {
 
             /**
              * Specifies the function to execute after result transformations.  This function can also be
-             * specified globally on {@link GremlinExecutor.Builder#afterSuccess(Consumer)}.
+             * specified globally on {@link GremlinExecutor.Builder#afterSuccess(Consumer)}. The script evaluation
+             * will be marked as "complete" after this method.
              */
             public Builder afterSuccess(final Consumer<Bindings> afterSuccess) {
                 this.afterSuccess = afterSuccess;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da5abb05/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 aad1f77..22c1699 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
@@ -24,11 +24,7 @@ import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCust
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptTimeoutException;
 import org.javatuples.Pair;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TestName;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.script.Bindings;
 import javax.script.CompiledScript;
@@ -41,7 +37,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
@@ -85,6 +81,27 @@ public class GremlinExecutorTest {
     }
 
     @Test
+    public void shouldRaiseExceptionInWithResultOfLifeCycle() throws Exception {
+        final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create();
+        final GremlinExecutor.LifeCycle lc = GremlinExecutor.LifeCycle.build()
+                .withResult(r -> {
+                    throw new RuntimeException("no worky");
+                }).create();
+
+        final AtomicBoolean exceptionRaised = new AtomicBoolean(false);
+
+        final CompletableFuture<Object> future = gremlinExecutor.eval("1+1", "gremlin-groovy", new SimpleBindings(), lc);
+        future.handle((r, t) -> {
+            exceptionRaised.set(t != null && t instanceof RuntimeException && t.getMessage().equals("no worky"));
+            return null;
+        }).get();
+
+        assertThat(exceptionRaised.get(), is(true));
+
+        gremlinExecutor.close();
+    }
+
+    @Test
     public void shouldEvalScript() throws Exception {
         final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create();
         assertEquals(2, gremlinExecutor.eval("1+1").get());