tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davebs...@apache.org
Subject [2/3] tinkerpop git commit: fixed side effect methods and updated tests
Date Wed, 05 Oct 2016 22:00:46 GMT
fixed side effect methods and updated tests


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

Branch: refs/heads/TINKERPOP-1458
Commit: fd2d6eb86f9d45a709d0684a23d57c83c18f5826
Parents: 790aa06
Author: davebshow <davebshow@gmail.com>
Authored: Wed Oct 5 17:59:15 2016 -0400
Committer: davebshow <davebshow@gmail.com>
Committed: Wed Oct 5 17:59:15 2016 -0400

----------------------------------------------------------------------
 .../DriverRemoteTraversalSideEffects.java       |  6 ++++-
 .../DriverRemoteTraversalSideEffectsTest.java   | 24 ++++++++++++++++++--
 .../server/GremlinServerIntegrateTest.java      | 18 +++++++++------
 3 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fd2d6eb8/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 d2fced5..2dece11 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
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.remote.traversal.AbstractRemoteTrave
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
@@ -67,10 +68,13 @@ public class DriverRemoteTraversalSideEffects extends AbstractRemoteTraversalSid
                 try {
                     final Result result = client.submitAsync(msg).get().one();
                     sideEffects.put(key, null == result ? null : result.getObject());
+                    if (keys.isEmpty())
+                        keys = new HashSet<>();
                     keys.add(key);
                 } catch (Exception ex) {
                     final Throwable root = ExceptionUtils.getRootCause(ex);
-                    if (root.getMessage().equals("Could not find side-effects for " + serverSideEffect
+ "."))
+                    final String exMsg = null == root ? "" : root.getMessage();
+                    if (exMsg.equals("Could not find side-effects for " + serverSideEffect
+ "."))
                         sideEffects.put(key, null);
                     else
                         throw new RuntimeException("Could not get keys", root);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fd2d6eb8/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffectsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffectsTest.java
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffectsTest.java
index d4c5618..368ca92 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffectsTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffectsTest.java
@@ -29,6 +29,7 @@ import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
@@ -63,10 +64,29 @@ public class DriverRemoteTraversalSideEffectsTest extends AbstractResultQueueTes
     }
 
     @Test
-    public void shouldNotContactRemoteMoreThanOnceForClose() throws Exception {
+    public void shoudlNotContactRemoteForGetAfterCloseIsCalled() throws Exception {
         final Client client = mock(Client.class);
         mockClientForCall(client);
         mockClientForCall(client);
+        final UUID sideEffectKey = UUID.fromString("31dec2c6-b214-4a6f-a68b-996608dce0d9");
+        final TraversalSideEffects sideEffects = new DriverRemoteTraversalSideEffects(client,
sideEffectKey, null);
+
+        assertNotNull(sideEffects.get("a"));
+        sideEffects.close();
+
+        // Side effect 'a' should be cached locally
+        assertNotNull(sideEffects.get("a"));
+        assertNotNull(sideEffects.get("a"));
+        assertNotNull(sideEffects.get("a"));
+
+        // Once for get and once for close
+        verify(client, times(2)).submitAsync(any(RequestMessage.class));
+    }
+
+    @Test
+    public void shouldNotContactRemoteMoreThanOnceForClose() throws Exception {
+        final Client client = mock(Client.class);
+        mockClientForCall(client);
 
         final UUID sideEffectKey = UUID.fromString("31dec2c6-b214-4a6f-a68b-996608dce0d9");
         final TraversalSideEffects sideEffects = new DriverRemoteTraversalSideEffects(client,
sideEffectKey, null);
@@ -79,7 +99,7 @@ public class DriverRemoteTraversalSideEffectsTest extends AbstractResultQueueTes
 
         assertEquals(0, sideEffects.keys().size());
 
-        // once for the keys and once for the close message
+        // once for the close message
         verify(client, times(1)).submitAsync(any(RequestMessage.class));
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fd2d6eb8/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 61bf994..1c4d19e 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
@@ -52,6 +52,7 @@ import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCusto
 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.process.traversal.step.util.BulkSet;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.server.channel.NioChannelizer;
@@ -850,9 +851,9 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
         assertEquals(2, sideEffectKeys.size());
 
         // Get side effects
-        final List aSideEffects = se.get("a");
+        final BulkSet aSideEffects = se.get("a");
         assertThat(aSideEffects.isEmpty(), is(false));
-        final List bSideEffects = se.get("b");
+        final BulkSet bSideEffects = se.get("b");
         assertThat(bSideEffects.isEmpty(), is(false));
 
         // Should get local keys/side effects after close
@@ -861,10 +862,10 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
         final Set<String> localSideEffectKeys = se.keys();
         assertEquals(2, localSideEffectKeys.size());
 
-        final List localASideEffects = se.get("a");
+        final BulkSet localASideEffects = se.get("a");
         assertThat(localASideEffects.isEmpty(), is(false));
 
-        final List localBSideEffects = se.get("b");
+        final BulkSet localBSideEffects = se.get("b");
         assertThat(localBSideEffects.isEmpty(), is(false));
     }
 
@@ -877,7 +878,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
         final GraphTraversal traversal = g.V().aggregate("a").aggregate("b");
         traversal.iterate();
         final DriverRemoteTraversalSideEffects se = (DriverRemoteTraversalSideEffects) traversal.asAdmin().getSideEffects();
-        final List sideEffects = se.get("a");
+        final BulkSet sideEffects = se.get("a");
         assertThat(sideEffects.isEmpty(), is(false));
         se.close();
 
@@ -887,7 +888,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
         // Earlier keys should be cached locally
         final Set<String> localSideEffectKeys = se.keys();
         assertEquals(1, localSideEffectKeys.size());
-        final List localSideEffects = se.get("a");
+        final BulkSet localSideEffects = se.get("a");
         assertThat(localSideEffects.isEmpty(), is(false));
 
         // Try to get side effect from server
@@ -896,13 +897,16 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration
         Field field = DriverRemoteTraversalSideEffects.class.getDeclaredField("serverSideEffect");
         field.setAccessible(true);
         UUID serverSideEffectId = (UUID) field.get(se);
+        final Map<String, String> aliases = new HashMap<>();
+        aliases.put("g", "g");
         final RequestMessage msg = RequestMessage.build(Tokens.OPS_GATHER)
                 .addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffectId)
                 .addArg(Tokens.ARGS_SIDE_EFFECT_KEY, "b")
+                .addArg(Tokens.ARGS_ALIASES, aliases)
                 .processor("traversal").create();
         boolean error;
         try {
-            client.submitAsync(msg).get();
+            client.submitAsync(msg).get().one();
             error = false;
         } catch (Exception ex) {
             error = true;


Mime
View raw message