コード例 #1
0
 async def test_strategies(self, remote_connection):
     statics.load_statics(globals())
     #
     g = Graph().traversal().withRemote(remote_connection). \
         withStrategies(TraversalStrategy("SubgraphStrategy",
                                          {"vertices": __.hasLabel("person"),
                                           "edges": __.hasLabel("created")}))
     assert 4 == await g.V().count().next()
     assert 0 == await g.E().count().next()
     assert 1 == await g.V().label().dedup().count().next()
     assert "person" == await g.V().label().dedup().next()
     #
     g = Graph().traversal().withRemote(remote_connection). \
         withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created")))
     assert 4 == await g.V().count().next()
     assert 0 == await g.E().count().next()
     assert 1 == await g.V().label().dedup().count().next()
     assert "person" == await g.V().label().dedup().next()
     #
     g = g.withoutStrategies(SubgraphStrategy). \
         withComputer(vertices=__.has("name", "marko"), edges=__.limit(0))
     assert 1 == await g.V().count().next()
     assert 0 == await g.E().count().next()
     assert "person" == await g.V().label().next()
     assert "marko" == await g.V().name.next()
     #
     g = Graph().traversal().withRemote(remote_connection).withComputer()
     assert 6 == await g.V().count().next()
     assert 6 == await g.E().count().next()
     await remote_connection.close()
コード例 #2
0
 def test_strategies(self):
     statics.load_statics(globals())
     connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
     #
     g = Graph().traversal().withRemote(connection). \
         withStrategies(TraversalStrategy("SubgraphStrategy",
                                          {"vertices": __.hasLabel("person"),
                                           "edges": __.hasLabel("created")}))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = Graph().traversal().withRemote(connection). \
         withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created")))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = g.withoutStrategies(SubgraphStrategy). \
         withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0))
     assert 1 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert "person" == g.V().label().next()
     assert "marko" == g.V().name.next()
     #
     g = Graph().traversal().withRemote(connection).withComputer()
     assert 6 == g.V().count().next()
     assert 6 == g.E().count().next()
     connection.close()
コード例 #3
0
 def test_strategies(self, remote_connection):
     statics.load_statics(globals())
     g = traversal().withRemote(remote_connection). \
         withStrategies(TraversalStrategy("SubgraphStrategy",
                                          {"vertices": __.hasLabel("person"),
                                           "edges": __.hasLabel("created")},
                                           "org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy"))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert 4 == g.V().filter(
         lambda: ("x -> true", "gremlin-groovy")).count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created")))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(SubgraphStrategy(edges=__.hasLabel("created")))
     assert 6 == g.V().count().next()
     assert 4 == g.E().count().next()
     assert 1 == g.E().label().dedup().count().next()
     assert "created" == g.E().label().dedup().next()
     #
     g = g.withoutStrategies(SubgraphStrategy). \
         withComputer(vertices=__.has("name", "marko"), edges=__.limit(0))
     assert 1 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert "person" == g.V().label().next()
     assert "marko" == g.V().name.next()
     #
     g = traversal().withRemote(remote_connection).withComputer()
     assert 6 == g.V().count().next()
     assert 6 == g.E().count().next()
     #
     g = traversal().withRemote(remote_connection).withStrategies(
         SeedStrategy(12345))
     shuffledResult = g.V().values("name").order().by(
         Order.shuffle).toList()
     assert shuffledResult == g.V().values("name").order().by(
         Order.shuffle).toList()
     assert shuffledResult == g.V().values("name").order().by(
         Order.shuffle).toList()
     assert shuffledResult == g.V().values("name").order().by(
         Order.shuffle).toList()
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(ReservedKeysVerificationStrategy(throw_exception=True))
     try:
         g.addV("person").property("id", "please-don't-use-id").iterate()
         assert False
     except GremlinServerError as gse:
         assert gse.status_code == 500
コード例 #4
0
 def test_strategies(self, remote_connection):
     statics.load_statics(globals())
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(TraversalStrategy("SubgraphStrategy",
                                          {"vertices": __.hasLabel("person"),
                                           "edges": __.hasLabel("created")}))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert 4 == g.V().filter(
         lambda: ("lambda x: True", "gremlin-python")).count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created")))
     assert 4 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert 1 == g.V().label().dedup().count().next()
     assert "person" == g.V().label().dedup().next()
     #
     g = traversal().withRemote(remote_connection). \
         withStrategies(SubgraphStrategy(edges=__.hasLabel("created")))
     assert 6 == g.V().count().next()
     assert 4 == g.E().count().next()
     assert 1 == g.E().label().dedup().count().next()
     assert "created" == g.E().label().dedup().next()
     #
     g = g.withoutStrategies(SubgraphStrategy). \
         withComputer(vertices=__.has("name", "marko"), edges=__.limit(0))
     assert 1 == g.V().count().next()
     assert 0 == g.E().count().next()
     assert "person" == g.V().label().next()
     assert "marko" == g.V().name.next()
     #
     g = traversal().withRemote(remote_connection).withComputer()
     assert 6 == g.V().count().next()
     assert 6 == g.E().count().next()