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")}))
     print GraphSONWriter.writeObject(g.bytecode)
     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")))
     print GraphSONWriter.writeObject(g.bytecode)
     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()
     connection.close()
Esempio n. 2
0
 def test_numbers(self):
     assert """{"@type":"g:Int32","@value":1}""" == GraphSONWriter.writeObject(
         1)
     assert """{"@type":"g:Int64","@value":2}""" == GraphSONWriter.writeObject(
         2L)
     assert """{"@type":"g:Float","@value":3.2}""" == GraphSONWriter.writeObject(
         3.2)
     assert """true""" == GraphSONWriter.writeObject(True)
Esempio n. 3
0
 def test_numbers(self):
     assert {
         "@type": "g:Int64",
         "@value": 2
     } == json.loads(GraphSONWriter.writeObject(long(2)))
     assert {
         "@type": "g:Int32",
         "@value": 1
     } == json.loads(GraphSONWriter.writeObject(1))
     assert {
         "@type": "g:Float",
         "@value": 3.2
     } == json.loads(GraphSONWriter.writeObject(3.2))
     assert """true""" == GraphSONWriter.writeObject(True)
Esempio n. 4
0
 def bytecode(self, args):
     gremlin = args['gremlin']
     args['gremlin'] = GraphSONWriter.writeObject(gremlin)
     aliases = args.get('aliases', '')
     if not aliases:
         aliases = {'g': 'g'}
     args['aliases'] = aliases
     return args
Esempio n. 5
0
 def bytecode(self, args):
     gremlin = args['gremlin']
     args['gremlin'] = GraphSONWriter.writeObject(gremlin)
     aliases = args.get('aliases', '')
     if not aliases:
         aliases = {'g': 'g'}
     args['aliases'] = aliases
     return args
Esempio n. 6
0
 def test_strategies(self):
     # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
     assert {
         "@type": "g:SubgraphStrategy",
         "@value": {}
     } == json.loads(GraphSONWriter.writeObject(SubgraphStrategy))
     assert {
         "@type": "g:SubgraphStrategy",
         "@value": {
             "vertices": {
                 "@type": "g:Bytecode",
                 "@value": {
                     "step": [["has", "name", "marko"]]
                 }
             }
         }
     } == json.loads(
         GraphSONWriter.writeObject(
             SubgraphStrategy(vertices=__.has("name", "marko"))))
 def submit_traversal_bytecode(self, request_id, bytecode):
     message = {
         "requestId": {
             "@type": "g:UUID",
             "@value": request_id
         },
         "op": "bytecode",
         "processor": "traversal",
         "args": {
             "gremlin": GraphSONWriter.writeObject(bytecode),
             "aliases": {"g": self.traversal_source}
         }
     }
     traversers = yield self._execute_message(message)
     raise gen.Return(traversers)
Esempio n. 8
0
 def submit_traversal_bytecode(self, request_id, bytecode):
     message = {
         "requestId": {
             "@type": "g:UUID",
             "@value": request_id
         },
         "op": "bytecode",
         "processor": "traversal",
         "args": {
             "gremlin": GraphSONWriter.writeObject(bytecode),
             "aliases": {
                 "g": self.traversal_source
             }
         }
     }
     traversers = yield self._execute_message(message)
     raise gen.Return(traversers)
Esempio n. 9
0
 def test_P(self):
     assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == GraphSONWriter.writeObject(
         P.lt("b").or_(P.gt("c")).and_(P.neq("d")))