You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by da...@apache.org on 2016/09/26 17:26:46 UTC

[20/21] tinkerpop git commit: added close method to gremlin python sideeffects

added close method to gremlin python sideeffects


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

Branch: refs/heads/TINKERPOP-1458
Commit: c6a8fb8e89c7e42f3aa85a088ba8cb9af3ccd1ae
Parents: ffc98f7
Author: davebshow <da...@apache.org>
Authored: Mon Sep 26 13:25:17 2016 -0400
Committer: davebshow <da...@apache.org>
Committed: Mon Sep 26 13:25:17 2016 -0400

----------------------------------------------------------------------
 .../driver/driver_remote_connection.py          | 22 +++++++++++++++++++-
 .../gremlin_python/driver/remote_connection.py  |  6 +++++-
 .../driver/test_driver_remote_connection.py     |  8 ++++++-
 3 files changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c6a8fb8e/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
index cac5e73..e47c8e6 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
@@ -52,7 +52,8 @@ class DriverRemoteConnection(RemoteConnection):
         traversers = self._loop.run_sync(lambda: self.submit_traversal_bytecode(request_id, bytecode))
         side_effect_keys = lambda: self._loop.run_sync(lambda: self.submit_sideEffect_keys(request_id))
         side_effect_value = lambda key: self._loop.run_sync(lambda: self.submit_sideEffect_value(request_id, key))
-        return RemoteTraversal(iter(traversers), RemoteTraversalSideEffects(side_effect_keys, side_effect_value))
+        side_effect_close = lambda: self._loop.run_sync(lambda: self.submit_sideEffect_close(request_id))
+        return RemoteTraversal(iter(traversers), RemoteTraversalSideEffects(side_effect_keys, side_effect_value, side_effect_close))
 
     @gen.coroutine
     def submit_traversal_bytecode(self, request_id, bytecode):
@@ -115,6 +116,25 @@ class DriverRemoteConnection(RemoteConnection):
         raise gen.Return(value)
 
     @gen.coroutine
+    def submit_sideEffect_close(self, request_id):
+        message = {
+            "requestId": {
+                "@type": "g:UUID",
+                "@value": str(uuid.uuid4())
+            },
+            "op": "close",
+            "processor": "traversal",
+            "args": {
+                "sideEffect": {
+                    "@type": "g:UUID",
+                    "@value": request_id
+                }
+            }
+        }
+        result = yield self._execute_message(message)
+        raise gen.Return(result)
+
+    @gen.coroutine
     def _execute_message(self, send_message):
         send_message = b"".join([b"\x21",
                                  b"application/vnd.gremlin-v2.0+json",

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c6a8fb8e/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py b/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py
index 0b84a26..3e7293f 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/remote_connection.py
@@ -57,9 +57,10 @@ class RemoteTraversal(Traversal):
 
 
 class RemoteTraversalSideEffects(TraversalSideEffects):
-    def __init__(self, keys_lambda, value_lambda):
+    def __init__(self, keys_lambda, value_lambda, close_lambda):
         self.keys_lambda = keys_lambda
         self.value_lambda = value_lambda
+        self.close_lambda = close_lambda
 
     def keys(self):
         return self.keys_lambda()
@@ -67,6 +68,9 @@ class RemoteTraversalSideEffects(TraversalSideEffects):
     def get(self, key):
         return self.value_lambda(key)
 
+    def close(self):
+        return self.close_lambda()
+
 
 class RemoteStrategy(TraversalStrategy):
     def __init__(self, remote_connection):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c6a8fb8e/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index b0efcf1..d96d35d 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -22,6 +22,8 @@ __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
 import unittest
 from unittest import TestCase
 
+import pytest
+
 from gremlin_python import statics
 from gremlin_python.statics import long
 from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
@@ -103,7 +105,7 @@ class TestDriverRemoteConnection(TestCase):
         assert "ripple" in n.keys()
         assert 3 == n["lop"]
         assert 1 == n["ripple"]
-        #
+
         t = g.withSideEffect('m',32).V().map(lambda: "x: x.sideEffects('m')")
         results = t.toSet()
         assert 1 == len(results)
@@ -115,6 +117,10 @@ class TestDriverRemoteConnection(TestCase):
             raise Exception("Accessing a non-existent key should throw an error")
         except KeyError:
             pass
+        result = t.side_effects.close()
+        assert not result
+        with pytest.raises(KeyError):
+            x = t.side_effects['m']
         connection.close()