def upload(self, json_graph, source_name, verbose=True, drop_graph=True): def printX(obj=""): if clargs.verbose: print(obj) if isinstance(json_graph, str): input_graph = nx.readwrite.json_graph.node_link_graph( json.loads(json_graph)) elif isinstance(json_graph, io.TextIOBase): input_graph = nx.readwrite.json_graph.node_link_graph( json.load(json_graph)) printX("output Gremlin server: %s, %s" % (clargs.output_server, clargs.output_source)) output_graph = Graph().traversal().withRemote( DriverRemoteConnection(self.server_url, self.traversal_source)) if drop_graph: printX("Clearing ouput graph...") output_graph.V().drop().toList() output_graph.E().drop().toList() printX("done") for id, props in input_graph.nodes(data=True): printX("processing node: %s\nwith data: %s" % (id, props)) new_node = output_graph.addV('node_link_node').next() output_graph.V(new_node).property('original_id', id).toList() output_graph.V(new_node).property('source_name', source_name).toList() for prop, value in props.items(): output_graph.V(new_node).property(prop, value).toList() printX("added properties: %s" % output_graph.V(new_node).properties().toList()) for out_id, in_id, props in input_graph.edges(data=True): printX("processing edge: %s --> %s" % (out_id, in_id)) out_node = output_graph.V().where( __.has('original_id', out_id).has('source_name', source_name)).next() in_node = output_graph.V().where( __.has('original_id', in_id).has('source_name', source_name)).next() new_edge = output_graph.addE('node_link_connection').from_( out_node).to(in_node).next() for prop, value in props.items(): output_graph.E(new_edge).property(prop, value).toList() printX("added properties: %s" % output_graph.E(new_edge).properties().toList()) printX("total nodes added: %d" % output_graph.V().count().next()) printX("total edges added: %d" % output_graph.E().count().next())
def test_big_result_set(client): g = Graph().traversal() t = g.inject(1).repeat(__.addV('person').property('name', __.loops())).times(20000).count() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'g'}}) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 1 t = g.V().limit(10) message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'g'}}) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 10 t = g.V().limit(100) message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'g'}}) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 100 t = g.V().limit(1000) message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'g'}}) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 1000 t = g.V().limit(10000) message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'g'}}) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 10000
def test_client_async(client): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', { 'gremlin': t.bytecode, 'aliases': { 'g': 'gmodern' } }) future = client.submitAsync(message) result_set = future.result() assert len(result_set.all().result()) == 6
def _executor(self, q, loop): try: connection = DriverRemoteConnection('ws://localhost:45940/gremlin', 'g', loop=loop) g = Graph().traversal().withRemote(connection) assert len(g.V().toList()) == 6 except: q.put(sys.exc_info()[0]) else: q.put('success!') connection.close()
def test_odd_bits(remote_connection): if not isinstance(remote_connection._client._message_serializer, GraphSONSerializersV2d0): g = Graph().traversal().withRemote(remote_connection) char_lower = str.__new__(SingleChar, chr(78)) resp = g.addV('test_vertex').property('char_lower', char_lower).toList() vid = resp[0].id try: v = g.V(vid).values('char_lower').toList()[0] assert v == char_lower finally: g.V(vid).drop().iterate() char_upper = str.__new__(SingleChar, chr(57344)) resp = g.addV('test_vertex').property('char_upper', char_upper).toList() vid = resp[0].id try: v = g.V(vid).values('char_upper').toList()[0] assert v == char_upper finally: g.V(vid).drop().iterate() dur = datetime.timedelta(seconds=1000, microseconds=1000) resp = g.addV('test_vertex').property('dur', dur).toList() vid = resp[0].id try: v = g.V(vid).values('dur').toList()[0] assert v == dur finally: g.V(vid).drop().iterate()
def test_multi_thread_pool(client): g = Graph().traversal() traversals = [g.V(), g.V().count(), g.E(), g.E().count()] results = [[] for _ in traversals] # Use a condition variable to synchronise a group of threads, which should also inject some # non-determinism into the run-time execution order condition = threading.Condition() def thread_run(tr, result_list): message = RequestMessage('traversal', 'bytecode', { 'gremlin': tr.bytecode, 'aliases': { 'g': 'gmodern' } }) with condition: condition.wait(5) result_set = client.submit(message) for result in result_set: result_list.append(result) threads = [] for i in range(len(results)): thread = threading.Thread(target=thread_run, args=(traversals[i], results[i]), name="test_multi_thread_pool_%d" % i) thread.daemon = True threads.append(thread) thread.start() with condition: condition.notify_all() for t in threads: t.join(5) assert len(results[0][0]) == 6 assert results[1][0][0].object == 6 assert len(results[2][0]) == 6 assert results[3][0][0].object == 6
def test_multi_conn_pool(client): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode}) future = client.submitAsync(message) future2 = client.submitAsync(message) result_set2 = future2.result() assert len(result_set2.all().result()) == 6 # with connection pool `future` may or may not be done here result_set = future.result() assert len(result_set.all().result()) == 6
def test_bytecode(self): g = Graph().traversal() bytecode = g.V().out("created").bytecode assert 0 == len(bytecode.bindings.keys()) assert 0 == len(bytecode.source_instructions) assert 2 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] assert "out" == bytecode.step_instructions[1][0] assert "created" == bytecode.step_instructions[1][1] assert 1 == len(bytecode.step_instructions[0]) assert 2 == len(bytecode.step_instructions[1]) ## bytecode = g.withSack(1).E().groupCount().by("weight").bytecode assert 0 == len(bytecode.bindings.keys()) assert 1 == len(bytecode.source_instructions) assert "withSack" == bytecode.source_instructions[0][0] assert 1 == bytecode.source_instructions[0][1] assert 3 == len(bytecode.step_instructions) assert "E" == bytecode.step_instructions[0][0] assert "groupCount" == bytecode.step_instructions[1][0] assert "by" == bytecode.step_instructions[2][0] assert "weight" == bytecode.step_instructions[2][1] assert 1 == len(bytecode.step_instructions[0]) assert 1 == len(bytecode.step_instructions[1]) assert 2 == len(bytecode.step_instructions[2]) ## bytecode = g.V(Bindings.of('a', [1,2,3])) \ .out(Bindings.of('b','created')) \ .where(__.in_(Bindings.of('c','created'), Bindings.of('d','knows')) \ .count().is_(Bindings.of('e',P.gt(2)))).bytecode assert 5 == len(bytecode.bindings.keys()) assert [1, 2, 3] == bytecode.bindings['a'] assert 'created' == bytecode.bindings['b'] assert 'created' == bytecode.bindings['c'] assert 'knows' == bytecode.bindings['d'] assert P.gt(2) == bytecode.bindings['e'] assert Binding('b', 'created') == bytecode.step_instructions[1][1] assert 'binding[b=created]' == str(bytecode.step_instructions[1][1]) assert isinstance(hash(bytecode.step_instructions[1][1]), int)
def test_iterate_result_set(client): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', { 'gremlin': t.bytecode, 'aliases': { 'g': 'gmodern' } }) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 6
def test_client_bytecode_with_int(client): g = Graph().traversal() t = g.V().has('age', 851401972585122).count() message = RequestMessage('traversal', 'bytecode', { 'gremlin': t.bytecode, 'aliases': { 'g': 'gmodern' } }) result_set = client.submit(message) results = [] for result in result_set: results += result assert len(results) == 1
def test_iteration(self, remote_connection): statics.load_statics(globals()) assert "remoteconnection[ws://localhost:45940/gremlin,gmodern]" == str(remote_connection) g = Graph().traversal().withRemote(remote_connection) t = g.V().count() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert 6 == t.next() assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) t = g.V().has('name', P.within('marko', 'peter')).values('name').order() assert "marko" == t.next() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert t.hasNext() assert "peter" == t.next() assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) assert not(t.hasNext()) try: t.next() assert False except StopIteration: assert True
def test_multi_conn_pool(client): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'gmodern'}}) message2 = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'gmodern'}}) client = Client('ws://localhost:45940/gremlin', 'g', pool_size=1) future = client.submitAsync(message) future2 = client.submitAsync(message2) result_set2 = future2.result() assert len(result_set2.all().result()) == 6 # with connection pool `future` may or may not be done here result_set = future.result() assert len(result_set.all().result()) == 6
def test_connection_share(client): # Overwrite fixture with pool_size=1 client client = Client('ws://localhost:45940/gremlin', 'g', pool_size=1) g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode}) future = client.submitAsync(message) future2 = client.submitAsync(message) result_set2 = future2.result() assert len(result_set2.all().result()) == 6 # This future has to finish for the second to yield result - pool_size=1 assert future.done() result_set = future.result() assert len(result_set.all().result()) == 6
def test_connection(connection): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', { 'gremlin': t.bytecode, 'aliases': { 'g': 'gmodern' } }) results_set = connection.write(message).result() future = results_set.all() results = future.result() assert len(results) == 6 assert isinstance(results, list) assert results_set.done.done() assert 'host' in results_set.status_attributes
def _executor(q, conn): close = False if not conn: # This isn't a fixture so close manually close = True conn = DriverRemoteConnection('ws://localhost:45940/gremlin', 'gmodern', pool_size=4) try: g = Graph().traversal().withRemote(conn) future = g.V().promise() t = future.result() assert len(t.toList()) == 6 except: q.put(sys.exc_info()[0]) else: q.put('success!') # Close conn if close: conn.close()
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 if not ("graphson" in world.config.user_data): raise ValueError( 'test configuration requires setting of --user-data="graphson=*" to one of [v2,v3]' ) if world.config.user_data["graphson"] == "v3": s = serializer.GraphSONSerializersV3d0() elif world.config.user_data["graphson"] == "v2": s = serializer.GraphSONSerializersV2d0() else: raise ValueError( 'serializer set with --user-data="graphson=v2" must be one of [v2,v3]' ) remote = DriverRemoteConnection('ws://localhost:45940/gremlin', "ggraph", message_serializer=s) scenario.context.remote_conn["empty"] = remote g = Graph().traversal().withRemote(remote) g.V().drop().iterate()
def test_text_regex(self): self.container.start() docker_ip = Popen(["docker-machine", "ip"], stdout=PIPE).communicate()[0] docker_ip = docker_ip.strip().decode("utf-8") client = JanusGraphClient() client = client.connect( host=str(docker_ip), port="8182", traversal_source="gods_traversal").get_connection() g = Graph().traversal().withRemote(client) truth = {"s.{2}": 2, "shouldNotBeFound": 0} for k, v in truth.items(): count = g.V().has("name", Text.textRegex(k)).count().next() self.assertEqual(count, v) client.close() self.container.stop()
def test_side_effects(self, remote_connection): statics.load_statics(globals()) # g = Graph().traversal().withRemote(remote_connection) ### t = g.V().hasLabel("project").name.iterate() assert 0 == len(t.side_effects.keys()) with pytest.raises(Exception): m = t.side_effects["m"] ### t = g.V().out("created").groupCount("m").by("name") results = t.toSet() assert 2 == len(results) assert Vertex(3) in results assert Vertex(5) in results assert 1 == len(t.side_effects.keys()) assert "m" in t.side_effects.keys() m = t.side_effects["m"] assert isinstance(m, dict) assert 2 == len(m) assert 3 == m["lop"] assert 1 == m["ripple"] assert isinstance(m["lop"], long) assert isinstance(m["ripple"], long) ## t = g.V().out("created").groupCount("m").by("name").name.aggregate("n") results = t.toSet() assert 2 == len(results) assert "lop" in results assert "ripple" in results assert 2 == len(t.side_effects.keys()) assert "m" in t.side_effects.keys() assert "n" in t.side_effects.keys() n = t.side_effects.get("n") assert isinstance(n, dict) assert 2 == len(n) assert "lop" in n.keys() assert "ripple" in n.keys() assert 3 == n["lop"] assert 1 == n["ripple"] t = g.withSideEffect('m', 32).V().map(lambda: "x: x.sideEffects('m')") results = t.toSet() assert 1 == len(results) assert 32 == list(results)[0] assert 32 == t.side_effects['m'] assert 1 == len(t.side_effects.keys()) with pytest.raises(Exception): x = t.side_effects["x"] a = g.V().has("name", "marko").next() b = g.V().has("name", "peter").next() edge = g.withSideEffect("b", b).V(a).addE("knows").to("b").next() assert "knows" == edge.label assert a == edge.outV assert b == edge.inV g.V().has("name", "marko").outE("knows").where(__.inV().has("name", "peter")).drop().iterate() ## edge = g.withSideEffect("a", a).withSideEffect("b", b).V().limit(1).addE("knows").from_("a").to("b").next() assert "knows" == edge.label assert a == edge.outV assert b == edge.inV g.V().has("name", "marko").outE("knows").where(__.inV().has("name", "peter")).drop().iterate()
ls = set() for item in methodList: for key, value in item.items(): ls.add(str(key) + ":" + value[0]) return ls printX("output Gremlin server: %s, %s" % (clargs.output_server, clargs.output_source)) output_graph = Graph().traversal().withRemote( DriverRemoteConnection(clargs.output_server, clargs.output_source)) printX() nodesInOne = output_graph.V().has( "source_name", clargs.project_name1).order().by("original_id").group().by( "original_id").by("label").toList() edgesInOne = output_graph.V().has( "source_name", clargs.project_name1).as_("a").outE().inV().as_("b").select( "a", "b").by("original_id").toList() nodesInTwo = output_graph.V().has( "source_name", clargs.project_name2).order().by("original_id").group().by( "original_id").by("label").toList() edgesInTwo = output_graph.V().has( "source_name", clargs.project_name2).as_("a").outE().inV().as_("b").select( "a", "b").by("original_id").toList() nodesInOneSet = keysToSet(nodesInOne) nodesInTwoSet = keysToSet(nodesInTwo)
DriverRemoteConnection('ws://169.46.9.99:32344/gremlin', 'dataplatform_dev')) parsed_data = [] with open('assets.csv') as f: parsed_data = [{k: v for k, v in row.items()} for row in csv.DictReader(f, skipinitialspace=True)] # for v in parsed_data: # print(add_vertex(v, g, "VirtualMachineConfigurationItem")) # # # for v in get_property_pivot(parsed_data, 'customer_id')[0:10]: # # g.V().hasLabel("VirtualMachineConfigurationItem").has('') # # # for v in get_property_pivot(parsed_data, 'datacenter_id'): # print(add_vertex({'id': v}, g, "DataCenter")) # # # for v in get_property_pivot(parsed_data, 'hypervisor_cluster_id'): # print(add_vertex({'id': v}, g, "HypervisorCluster")) # print(g.V().hasLabel("VirtualMachineConfigurationItem").has('short_hostname', 'cnbj11v101038').toList()) print(g.V().hasLabel("VirtualMachineConfigurationItem").range( 0, 12).map().toList())
def test_singletons(self): g = Graph().traversal() bytecode = g.withStrategies(ReadOnlyStrategy()).bytecode assert 1 == len(bytecode.source_instructions) assert 2 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert "ReadOnlyStrategy" == str(bytecode.source_instructions[0][1]) assert hash(ReadOnlyStrategy()) == hash( bytecode.source_instructions[0][1]) assert 0 == len(g.traversal_strategies.traversal_strategies ) # these strategies are proxies ## g = g.withStrategies(ReadOnlyStrategy(), IncidentToAdjacentStrategy()) bytecode = g.bytecode assert 1 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] ## bytecode = g.V().bytecode assert 1 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] ## bytecode = g.withoutStrategies(ReadOnlyStrategy()).V().bytecode assert 2 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert 2 == len(bytecode.source_instructions[1]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert "withoutStrategies" == bytecode.source_instructions[1][0] assert ReadOnlyStrategy() == bytecode.source_instructions[1][1] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] ## bytecode = g.withoutStrategies(ReadOnlyStrategy(), LazyBarrierStrategy()).V().bytecode assert 2 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert 3 == len(bytecode.source_instructions[1]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert "withoutStrategies" == bytecode.source_instructions[1][0] assert ReadOnlyStrategy() == bytecode.source_instructions[1][1] assert LazyBarrierStrategy() == bytecode.source_instructions[1][2] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] ### g = Graph().traversal() bytecode = g.with_("x", "test").with_("y").bytecode assert 1 == len(bytecode.source_instructions) assert 2 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert OptionsStrategy() == bytecode.source_instructions[0][1] strategy = bytecode.source_instructions[0][1] assert 2 == len(strategy.configuration) assert "test" == strategy.configuration["x"] assert strategy.configuration["y"]
# if v is not None and v != "": # print(v) # xz = g.withSideEffect( # 'a', # g.V().hasLabel("VirtualMachineConfigurationItem").has('hypervisor_cluster_id', v).range(0, 15).toList() # ).V().hasLabel("HypervisorCluster").has('id', v).outE('owns', 'a') # print(xz.toList()) # # for v in get_property_pivot(parsed_data, 'hypervisor_cluster_id'): # if v is not None and v != "": # print(v) # hypervisor = g.V().hasLabel("HypervisorCluster").has('id', v).range(0, 1).next() # print(hypervisor) cluster: Vertex = g.V().hasLabel("HypervisorCluster").has( 'id', 'test_hypervisor_001').next() print(type(cluster)) vertices = g.V().hasLabel("VirtualMachineConfigurationItem").has( 'hypervisor_cluster_id', 'test_hypervisor_001').range(0, 20).toList() for x in vertices: g.V(cluster).outE("hosts").to(x).next() # print(g.V().hasLabel("VirtualMachineConfigurationItem").has('short_hostname', 'cnbj11v101038').toList()) # pprint.pprint(g.V().hasLabel("VirtualMachineConfigurationItem").range(0, 1).valueMap().toList()) # pprint.pprint(g.V().hasLabel("VirtualMachineConfigurationItem").has('host_shortname', 'gbcnvpwxaa031').range(0, 1).toList())
def test_client_bytecode(client): g = Graph().traversal() t = g.V() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode}) result_set = client.submit(message) assert len(result_set.all().result()) == 6
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 == 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 = Graph().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 = Graph().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 = Graph().traversal().withRemote(remote_connection).withComputer() assert 6 == g.V().count().next() assert 6 == g.E().count().next()
def __create_lookup_v(remote): g = Graph().traversal().withRemote(remote) # hold a map of name/vertex for use in asserting results return g.V().group().by('name').by(tail()).next()
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", message_serializer=serializer.GraphSONSerializersV3d0()) scenario.context.remote_conn["empty"] = remote g = Graph().traversal().withRemote(remote) g.V().drop().iterate()
def test_traversals(self): statics.load_statics(globals()) connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g') assert "remoteconnection[ws://localhost:8182/gremlin,g]" == str( connection) # g = Graph().traversal().withRemote(connection) # assert 6L == g.V().count().toList()[0] # assert Vertex(1) == g.V(1).next() assert 1 == g.V(1).id().next() assert Traverser(Vertex(1)) == g.V(1).nextTraverser() assert 1 == len(g.V(1).toList()) assert isinstance(g.V(1).toList(), list) # results = g.V().repeat(out()).times(2).name.toList() assert 2 == len(results) assert "lop" in results assert "ripple" in results # assert 10 == g.V().repeat(both()).times(5)[0:10].count().next() assert 1 == g.V().repeat(both()).times(5)[0].count().next() assert 0 == g.V().repeat(both()).times(5)[0:0].count().next() assert 4 == g.V()[2:].count().next() assert 2 == g.V()[:2].count().next() # todo: need a traversal metrics deserializer g.V().out().profile().next() connection.close()
def test_traversals(self): statics.load_statics(globals()) connection = DriverRemoteConnection('ws://localhost:45940/gremlin', 'g') assert "remoteconnection[ws://localhost:45940/gremlin,g]" == str( connection) g = Graph().traversal().withRemote(connection) assert long(6) == g.V().count().toList()[0] # assert Vertex(1) == g.V(1).next() assert 1 == g.V(1).id().next() assert Traverser(Vertex(1)) == g.V(1).nextTraverser() assert 1 == len(g.V(1).toList()) assert isinstance(g.V(1).toList(), list) results = g.V().repeat(out()).times(2).name results = results.toList() assert 2 == len(results) assert "lop" in results assert "ripple" in results # assert 10 == g.V().repeat(both()).times(5)[0:10].count().next() assert 1 == g.V().repeat(both()).times(5)[0:1].count().next() assert 0 == g.V().repeat(both()).times(5)[0:0].count().next() assert 4 == g.V()[2:].count().next() assert 2 == g.V()[:2].count().next() # results = g.withSideEffect( 'a', ['josh', 'peter' ]).V(1).out('created').in_('created').values('name').where( within('a')).toList() assert 2 == len(results) assert 'josh' in results assert 'peter' in results # todo: need a traversal metrics deserializer g.V().out().profile().next() connection.close()
def test_traversals(self, remote_connection): statics.load_statics(globals()) assert "remoteconnection[ws://localhost:45940/gremlin,gmodern]" == str(remote_connection) g = Graph().traversal().withRemote(remote_connection) assert long(6) == g.V().count().toList()[0] # # assert Vertex(1) == g.V(1).next() assert 1 == g.V(1).id().next() assert Traverser(Vertex(1)) == g.V(1).nextTraverser() assert 1 == len(g.V(1).toList()) assert isinstance(g.V(1).toList(), list) results = g.V().repeat(out()).times(2).name results = results.toList() assert 2 == len(results) assert "lop" in results assert "ripple" in results # # assert 10 == g.V().repeat(both()).times(5)[0:10].count().next() assert 1 == g.V().repeat(both()).times(5)[0:1].count().next() assert 0 == g.V().repeat(both()).times(5)[0:0].count().next() assert 4 == g.V()[2:].count().next() assert 2 == g.V()[:2].count().next() # # results = g.withSideEffect('a', ['josh', 'peter']).V(1).out('created').in_('created').values('name').where( within('a')).toList() assert 2 == len(results) assert 'josh' in results assert 'peter' in results # # todo: need a traversal metrics deserializer g.V().out().profile().next() # # results = g.V().has('name', 'peter').as_('a').out('created').as_('b').select('a', 'b').by( __.valueMap()).toList() assert 1 == len(results) assert 'peter' == results[0]['a']['name'][0] assert 35 == results[0]['a']['age'][0] assert 'lop' == results[0]['b']['name'][0] assert 'java' == results[0]['b']['lang'][0] assert 2 == len(results[0]['a']) assert 2 == len(results[0]['b']) # # results = g.V(1).inject(g.V(2).next()).values('name').toList() assert 2 == len(results) assert 'marko' in results assert 'vadas' in results