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/df9ff696 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/df9ff696 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/df9ff696 Branch: refs/heads/TINKERPOP-1458 Commit: df9ff696a16ff8495b3845e1f1888faf2e539624 Parents: e319ff6 Author: davebshow <[email protected]> Authored: Mon Sep 26 13:25:17 2016 -0400 Committer: davebshow <[email protected]> Committed: Fri Oct 7 10:34:30 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/df9ff696/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/df9ff696/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/df9ff696/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()
