You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/11/02 17:38:04 UTC
[07/50] tinkerpop git commit: TINKERPOP-1784 Included grateful graph
and cached remotes/data
TINKERPOP-1784 Included grateful graph and cached remotes/data
Tests should be faster now that remotes and data are cached for the toy graphs.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b7e61961
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b7e61961
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b7e61961
Branch: refs/heads/TINKERPOP-1784
Commit: b7e6196171d297724c273e9c200e9cae77eb9878
Parents: 12c178e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Sep 29 11:54:33 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Nov 2 13:37:22 2017 -0400
----------------------------------------------------------------------
.../src/main/jython/radish/terrain.py | 66 +++++++++++++++-----
1 file changed, 49 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b7e61961/gremlin-python/src/main/jython/radish/terrain.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/terrain.py b/gremlin-python/src/main/jython/radish/terrain.py
index e88272b..5897852 100644
--- a/gremlin-python/src/main/jython/radish/terrain.py
+++ b/gremlin-python/src/main/jython/radish/terrain.py
@@ -21,7 +21,7 @@ import re
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
-from radish import before, after
+from radish import before, after, world
outV = __.outV
label = __.label
@@ -30,16 +30,38 @@ project = __.project
tail = __.tail
-@before.each_scenario
-def prepare_traversal_source(scenario):
- scenario.context.remote_conn = {}
- scenario.context.lookup_v = {}
- scenario.context.lookup_e = {}
+@before.all
+def prepare_static_traversal_source(features, marker):
+ # as the various traversal sources for testing do not change their data, there is no need to re-create remotes
+ # and client side lookup data over and over. it can be created once for all tests and be reused.
+ cache = {}
+ for graph_name in (("modern", "gmodern"), ("classic", "gclassic"), ("crew", "gcrew"), ("grateful", "ggrateful")):
+ cache[graph_name[0]] = {}
+ remote = __create_remote(graph_name[1])
+ cache[graph_name[0]]["remote_conn"] = __create_remote(graph_name[1])
+ cache[graph_name[0]]["lookup_v"] = __create_lookup_v(remote)
+ cache[graph_name[0]]["lookup_e"] = __create_lookup_e(remote)
+
+ # store the cache on the global context so that remotes can be shutdown cleanly at the end of the tests
+ world.cache = cache
+
+ # iterate each feature and apply the cached remotes/lookups to each scenario context so that they are
+ # accessible to the feature steps for test logic
+ for feature in features:
+ for scenario in feature.all_scenarios:
+ scenario.context.remote_conn = {}
+ scenario.context.lookup_v = {}
+ scenario.context.lookup_e = {}
- __prepare(scenario, "modern", "gmodern")
- __prepare(scenario, "classic", "gclassic")
- __prepare(scenario, "crew", "gcrew")
+ for graph_name in ("modern", "classic", "crew", "grateful"):
+ scenario.context.remote_conn[graph_name] = cache[graph_name]["remote_conn"]
+ scenario.context.lookup_v[graph_name] = cache[graph_name]["lookup_v"]
+ scenario.context.lookup_e[graph_name] = cache[graph_name]["lookup_e"]
+
+@before.each_scenario
+def prepare_traversal_source(scenario):
+ # some tests create data - create a fresh remote to the empty graph and clear that graph prior to each test
remote = DriverRemoteConnection('ws://localhost:45940/gremlin', "ggraph")
scenario.context.remote_conn["empty"] = remote
g = Graph().traversal().withRemote(remote)
@@ -48,18 +70,28 @@ def prepare_traversal_source(scenario):
@after.each_scenario
def close_traversal_source(scenario):
- scenario.context.remote_conn["modern"].close()
- scenario.context.remote_conn["classic"].close()
- scenario.context.remote_conn["crew"].close()
+ scenario.context.remote_conn["empty"].close()
-def __prepare(scenario, graph_name, server_graph_name):
- remote = DriverRemoteConnection('ws://localhost:45940/gremlin', server_graph_name)
- scenario.context.remote_conn[graph_name] = remote
+@after.all
+def close_static_traversal_source(features, marker):
+ for key, value in world.cache.iteritems():
+ value["remote_conn"].close()
+
+
+def __create_remote(server_graph_name):
+ return DriverRemoteConnection('ws://localhost:45940/gremlin', server_graph_name)
+
+
+def __create_lookup_v(remote):
g = Graph().traversal().withRemote(remote)
# hold a map of name/vertex for use in asserting results
- scenario.context.lookup_v[graph_name] = g.V().group().by('name').by(tail()).next()
+ return g.V().group().by('name').by(tail()).next()
+
+
+def __create_lookup_e(remote):
+ g = Graph().traversal().withRemote(remote)
# hold a map of the "name"/edge for use in asserting results - "name" in this context is in the form of
# outgoingV-label->incomingV
@@ -79,4 +111,4 @@ def __prepare(scenario, graph_name, server_graph_name):
i = re.search("i=(.+?)[,\}]", key).group(1)
edges[o + "-" + l + "->" + i] = value
- scenario.context.lookup_e[graph_name] = edges
+ return edges