1
|
|
|
# Copyright 2016 David M. Brown |
2
|
|
|
# |
3
|
|
|
# This file is part of Goblin. |
4
|
|
|
# |
5
|
|
|
# Goblin is free software: you can redistribute it and/or modify |
6
|
|
|
# it under the terms of the GNU Affero General Public License as published by |
7
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
# (at your option) any later version. |
9
|
|
|
# |
10
|
|
|
# Goblin is distributed in the hope that it will be useful, |
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
# GNU Affero General Public License for more details. |
14
|
|
|
# |
15
|
|
|
# You should have received a copy of the GNU Affero General Public License |
16
|
|
|
# along with Goblin. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
|
18
|
|
|
import asyncio |
19
|
|
|
import uuid |
20
|
|
|
|
21
|
|
|
import pytest |
22
|
|
|
|
23
|
|
|
from aiogremlin.driver.server import GremlinServer |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
@pytest.mark.asyncio |
27
|
|
|
async def test_client_auto_release(cluster): |
28
|
|
|
client = await cluster.connect(hostname='gremlin-server') |
29
|
|
|
resp = await client.submit("1 + 1") |
30
|
|
|
async for msg in resp: |
31
|
|
|
pass |
32
|
|
|
await asyncio.sleep(0) |
33
|
|
|
host = cluster._hosts.popleft() |
34
|
|
|
assert len(host._pool._available) == 1 |
35
|
|
|
await host.close() |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
@pytest.mark.asyncio |
39
|
|
|
async def test_alias(cluster): |
40
|
|
|
client = await cluster.connect(hostname='gremlin-server') |
41
|
|
|
aliased_client = client.alias({"g": "g1"}) |
42
|
|
|
assert aliased_client._aliases == {"g": "g1"} |
43
|
|
|
assert aliased_client._cluster is client._cluster |
44
|
|
|
assert aliased_client._loop is client._loop |
45
|
|
|
await cluster.close() |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@pytest.mark.asyncio |
49
|
|
|
async def test_client_auto_release(cluster): |
50
|
|
|
client = await cluster.connect(hostname='gremlin-server') |
51
|
|
|
resp = await client.submit("1 + 1") |
52
|
|
|
async for msg in resp: |
53
|
|
|
assert msg == 2 |
54
|
|
|
assert client._hostname == 'gremlin-server' |
55
|
|
|
await cluster.close() |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
# @pytest.mark.asyncio |
60
|
|
|
# async def test_sessioned_client(cluster): |
61
|
|
|
# session = str(uuid.uuid4()) |
62
|
|
|
# client = await cluster.connect(session=session) |
63
|
|
|
# assert isinstance(client.cluster, GremlinServer) |
64
|
|
|
# resp = await client.submit(gremlin="v = g.addV('person').property('name', 'joe').next(); v") |
65
|
|
|
# async for msg in resp: |
66
|
|
|
# try: |
67
|
|
|
# assert msg['properties']['name'][0]['value'] == 'joe' |
68
|
|
|
# except KeyError: |
69
|
|
|
# assert msg['properties']['name'][0]['@value']['value'] == 'joe' |
70
|
|
|
# |
71
|
|
|
# resp = await client.submit(gremlin="g.V(v.id()).values('name')") |
72
|
|
|
# |
73
|
|
|
# async for msg in resp: |
74
|
|
|
# assert msg == 'joe' |
75
|
|
|
# await cluster.close() |
76
|
|
|
|