tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [05/16] tinkerpop git commit: added close method to DriverRemoteTraversalSideEffects, implement AutoCloseable on TraversalSideEffects, add test for close method
Date Fri, 07 Oct 2016 22:31:48 GMT
added close method to DriverRemoteTraversalSideEffects, implement AutoCloseable on TraversalSideEffects,
add test for close method


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

Branch: refs/heads/master
Commit: ad97af215584f25fb1da8ad779b8dae8d4ccf72d
Parents: a08fa26
Author: davebshow <davebshow@gmail.com>
Authored: Thu Sep 29 11:55:09 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Fri Oct 7 18:31:34 2016 -0400

----------------------------------------------------------------------
 .../process/traversal/TraversalSideEffects.java |  9 ++++-
 .../DriverRemoteTraversalSideEffects.java       | 21 +++++++++--
 .../server/GremlinServerIntegrateTest.java      | 38 +++++++++++++-------
 3 files changed, 51 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ad97af21/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSideEffects.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSideEffects.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSideEffects.java
index 95b9fb1..ae6ef54 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSideEffects.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSideEffects.java
@@ -32,7 +32,7 @@ import java.util.function.UnaryOperator;
  *
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
-public interface TraversalSideEffects extends Cloneable, Serializable {
+public interface TraversalSideEffects extends Cloneable, Serializable, AutoCloseable {
 
     /**
      * Return true if the key is a registered side-effect.
@@ -83,6 +83,13 @@ public interface TraversalSideEffects extends Cloneable, Serializable {
     public Set<String> keys();
 
     /**
+     * Invalidate the side effect cache for traversal.
+     */
+    public default void close() throws Exception {
+        // do nothing
+    }
+
+    /**
      * Determines if there are any side-effects to be retrieved.
      */
     public default boolean isEmpty() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ad97af21/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
index 85d7abc..c565dfa 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
@@ -45,6 +45,8 @@ public class DriverRemoteTraversalSideEffects extends AbstractRemoteTraversalSid
 
     private final Map<String, Object> sideEffects = new HashMap<>();
 
+    private boolean closed = false;
+
     public DriverRemoteTraversalSideEffects(final Client client, final UUID serverSideEffect,
final Host host) {
         this.client = client;
         this.serverSideEffect = serverSideEffect;
@@ -99,10 +101,23 @@ public class DriverRemoteTraversalSideEffects extends AbstractRemoteTraversalSid
         return keys;
     }
 
+
     @Override
     public void close() throws Exception {
-        // todo: need to add a call to "close" the side effects on the server - probably
should ensure request only sends once
-
-        // leave the client open as it is owned by the DriverRemoteConnection not the traversal
or side-effects
+        if (!closed) {
+            final RequestMessage msg = RequestMessage.build(Tokens.OPS_CLOSE)
+                    .addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffect)
+                    .addArg(Tokens.ARGS_HOST, host)
+                    .processor("traversal").create();
+            try {
+                client.submitAsync(msg).get();
+                sideEffects.clear();
+                keys = null;
+                closed = true;
+            } catch (Exception ex) {
+                final Throwable root = ExceptionUtils.getRootCause(ex);
+                throw new RuntimeException("Error on closing side effects", root);
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ad97af21/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index 5a36acf..7d6c0c9 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@ -49,6 +49,7 @@ import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCust
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider;
 import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
@@ -64,11 +65,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.nio.channels.ClosedChannelException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -102,6 +99,14 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
 
     private Log4jRecordingAppender recordingAppender = null;
 
+    private final Supplier<Graph> graphGetter = () -> server.getServerGremlinExecutor().getGraphManager().getGraphs().get("graph");
+    private final Configuration conf = new BaseConfiguration() {{
+        setProperty(Graph.GRAPH, RemoteGraph.class.getName());
+        setProperty(GREMLIN_REMOTE_CONNECTION_CLASS, DriverRemoteConnection.class.getName());
+        setProperty(DriverRemoteConnection.GREMLIN_REMOTE_DRIVER_SOURCENAME, "g");
+        setProperty("hidden.for.testing.only", graphGetter);
+    }};
+
     @Before
     public void setupForEachTest() {
         recordingAppender = new Log4jRecordingAppender();
@@ -814,18 +819,25 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
 
     @Test
     public void shouldSupportLambdasUsingWithRemote() throws Exception {
-        final Supplier<Graph> graphGetter = () -> server.getServerGremlinExecutor().getGraphManager().getGraphs().get("graph");
-        final Configuration conf = new BaseConfiguration() {{
-            setProperty(Graph.GRAPH, RemoteGraph.class.getName());
-            setProperty(GREMLIN_REMOTE_CONNECTION_CLASS, DriverRemoteConnection.class.getName());
-            setProperty(DriverRemoteConnection.GREMLIN_REMOTE_DRIVER_SOURCENAME, "g");
-            setProperty("hidden.for.testing.only", graphGetter);
-        }};
-
         final Graph graph = EmptyGraph.instance();
         final GraphTraversalSource g = graph.traversal().withRemote(conf);
         g.addV("person").property("age", 20).iterate();
         g.addV("person").property("age", 10).iterate();
         assertEquals(50L, g.V().hasLabel("person").map(Lambda.function("it.get().value('age')
+ 10")).sum().next());
     }
+
+    @Test
+    public void shouldCloseSideEffects() throws Exception {
+        final Graph graph = EmptyGraph.instance();
+        final GraphTraversalSource g = graph.traversal().withRemote(conf);
+        g.addV("person").property("age", 20).iterate();
+        g.addV("person").property("age", 10).iterate();
+        final GraphTraversal traversal = g.V().aggregate("a");
+        traversal.iterate();
+        final Set sideEffects = traversal.asAdmin().getSideEffects().keys();
+        assertTrue(sideEffects.contains("a"));
+        traversal.asAdmin().getSideEffects().close();
+        final Set emptySideEffects = traversal.asAdmin().getSideEffects().keys();
+        assertTrue(emptySideEffects.isEmpty());
+    }
 }


Mime
View raw message