diff --git a/README.md b/README.md index f0aff85d84b7dc72917a77c6dc9dcf29237650f2..b37414aa227221f85cd53ab5b4fd3ebdfbdb6535 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# aiogremlin 0.0.5 [(gizmo grew up)](https://pypi.python.org/pypi/gizmo/0.1.12) +# aiogremlin 0.0.6 [(gizmo grew up)](https://pypi.python.org/pypi/gizmo/0.1.12) `aiogremlin` is a **Python 3** driver for the the [Tinkerpop 3 Gremlin Server](http://www.tinkerpop.com/docs/3.0.0.M7/#gremlin-server). This module is built on [Asyncio](https://docs.python.org/3/library/asyncio.html). By default it uses the [aiohttp](http://aiohttp.readthedocs.org/en/v0.15.3/index.html) websocket client , but it is easy to plug in a different implementation. `aiogremlin` is currently in **alpha** mode, but all major functionality has test coverage. diff --git a/aiogremlin/__init__.py b/aiogremlin/__init__.py index 2a0601026dfe25244dfd021e4e3fb65778afd16b..e8e37807ef732a940024ba132b5c27ea22084bff 100644 --- a/aiogremlin/__init__.py +++ b/aiogremlin/__init__.py @@ -5,4 +5,4 @@ from .client import (create_client, GremlinClient, GremlinResponse, GremlinResponseStream) from .exceptions import RequestError, GremlinServerError, SocketClientError from .protocol import GremlinWriter -__version__ = "0.0.5" +__version__ = "0.0.6" diff --git a/aiogremlin/client.py b/aiogremlin/client.py index 224a0f2f8636af87670811a2e552d9e294745170..9b40de2f5303f42c7ba1c5c3f7887e9d965c975e 100644 --- a/aiogremlin/client.py +++ b/aiogremlin/client.py @@ -85,7 +85,7 @@ class GremlinClient: @asyncio.coroutine def submit(self, gremlin, connection=None, bindings=None, lang=None, - op=None, processor=None, binary=True): + op=None, processor=None, session=None, binary=True): """ """ lang = lang or self.lang @@ -102,14 +102,15 @@ class GremlinClient: } } if processor == "session": - message["args"]["session"] = str(uuid.uuid4()) + session = session or str(uuid.uuid4()) + message["args"]["session"] = session client_logger.info( "Session ID: {}".format(message["args"]["session"])) if connection is None: connection = yield from self.pool.connect(self.uri, loop=self.loop) writer = GremlinWriter(connection) connection = yield from writer.write(message, binary=binary) - return GremlinResponse(connection, loop=self._loop) + return GremlinResponse(connection, session=session, loop=self._loop) @asyncio.coroutine def execute(self, gremlin, bindings=None, lang=None, @@ -126,14 +127,19 @@ class GremlinClient: class GremlinResponse: - def __init__(self, conn, loop=None): + def __init__(self, conn, session=None, loop=None): self._loop = loop or asyncio.get_event_loop() + self._session = session self._stream = GremlinResponseStream(conn, loop=self._loop) @property def stream(self): return self._stream + @property + def session(self): + return self._session + @asyncio.coroutine def get(self): return (yield from self._run()) diff --git a/benchmark.py b/benchmark.py index 2e8ada786a170166732bc2153434dbd82b352cbf..8ca02735a884b06de7d7388d0ebdb0730b160bcc 100644 --- a/benchmark.py +++ b/benchmark.py @@ -55,7 +55,7 @@ def main(client, tests, count, concurrency, warmups, loop): execute = client.execute # warmup for x in range(warmups): - print("Warmup run {}:".format(x)) + print("Warmup run {}:".format(x + 1)) yield from run(client, count, concurrency, loop) print("Warmup successful!") mps_list = [] diff --git a/setup.py b/setup.py index 3d9b70a07044dbbf2fe84f84dea3447efab793d6..130064f0a74c4830097317903068b4e2a08f3bca 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name="aiogremlin", - version="0.0.5", + version="0.0.6", url="", license="MIT", author="davebshow", diff --git a/tests/tests.py b/tests/tests.py index e66518d47a7c83000847d5fd2f53fbd7417c15a6..5ba9c1309b29af95b94da66888d9aa05687ad4c5 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -4,6 +4,7 @@ import asyncio import itertools import unittest +import uuid from aiogremlin import (GremlinClient, RequestError, GremlinServerError, SocketClientError, WebsocketPool, AiohttpFactory, create_client) @@ -76,11 +77,24 @@ class GremlinClientTests(unittest.TestCase): error = True self.assertTrue(error) - def test_session(self): + def test_session_gen(self): execute = self.gc.execute("x + x", processor="session", bindings={"x": 4}) results = self.loop.run_until_complete(execute) self.assertEqual(results[0].data[0], 8) + def test_session(self): + @asyncio.coroutine + def stream_coro(): + session = str(uuid.uuid4()) + resp = yield from self.gc.submit("x + x", bindings={"x": 4}, + session=session) + while True: + f = yield from resp.stream.read() + if f is None: + break + self.assertEqual(resp.session, session) + self.loop.run_until_complete(stream_coro()) + class WebsocketPoolTests(unittest.TestCase):