def test_tool_graph_merge(self): """ 合并图 需要两个server :return: """ # 清空图模式 res0 = run_shell( "./bin/hugegraph --url %s --graph %s %s %s graph-mode-set -m NONE " ) res0.communicate() clear_graph() insert_data() target_clear_graph() target_insert_data() ### 开始测试case cmd = "./bin/hugegraph --url %s --graph %s %s %s migrate " \ "--target-url %s " \ "--target-graph %s " \ "%s " \ "%s " \ "--graph-mode MERGING " res = run_shell(cmd) stdout, stderr = res.communicate() print(' ---> ' + str(stdout) + ' === ' + str(stderr)) assert res.returncode == 0 assert str(stdout, 'utf-8').split('restore summary: ')[1].split('\ncost time(s)')[0] == \ "{\n\tproperty key number: 0,\n" \ "\tvertex label number: 1,\n" \ "\tedge label number: 1,\n" \ "\tindex label number: 0,\n" \ "\tvertex number: 6,\n" \ "\tedge number: 8,\n}"
def test_tool_execute_gremlin_job(self): """ 执行gremlin任务 :return: """ clear_graph() insert_data() ### 执行gremlin的job任务 gremlin_cmd = "./bin/hugegraph --url %s --graph %s %s %s " \ "gremlin-schedule --script 'g.V().count()' " gremlin_res = run_shell(gremlin_cmd) stdout, stderr = gremlin_res.communicate() print(' ---> ' + str(stdout, 'utf-8') + str(stderr, 'utf-8')) ### 查看task内容 time.sleep(60) task_id = str(stdout, 'utf-8').split('\n')[1].split(': ')[1] task_cmd = "./bin/hugegraph --url %s --graph %s %s %s task-get --task-id " + str( task_id) task_res = run_shell(task_cmd) task_stdout, task_stderr = task_res.communicate() print(' ---> ' + str(task_stdout, 'utf-8') + str(task_stderr, 'utf-8')) assert gremlin_res.returncode == 0 assert task_res.returncode == 0 assert str(task_stdout, 'utf-8').split('task_result=')[1].startswith('[6]')
def test_tool_restore(self): """ 恢复数据 :return: """ dir_data = "backup_" + str(int(time.time())) clear_graph() insert_data() ### 数据备份 backup_cmd = "./bin/hugegraph --url %s --graph %s %s %s backup -t all --directory ./" + dir_data backup_res = run_shell(backup_cmd) backup_res.communicate() ### 清空数据 clear_graph() ### 设置图模式 mode_cmd = "./bin/hugegraph --url %s --graph %s %s %s graph-mode-set -m RESTORING " res_mode = run_shell(mode_cmd) res_mode.communicate() ### 恢复数据 restore_cmd = "./bin/hugegraph --url %s --graph %s %s %s restore -t all --directory ./" + dir_data restore_res = run_shell(restore_cmd) restore_res.communicate() res_v, res_e = tools_assert() assert backup_res.returncode == 0 assert res_mode.returncode == 0 assert restore_res.returncode == 0 assert res_v == 6 assert res_e == 8 ### 恢复图模式 mode_none = "./bin/hugegraph --url %s --graph %s %s %s graph-mode-set -m NONE " res_none = run_shell(mode_none) res_none.communicate()
def test_tool_backup_all(self): """ 备份所有数据 :return: """ clear_graph() insert_data() # 开始case测试 cmd = "./bin/hugegraph --url %s --graph %s %s %s backup -t all --directory ./backup" + str( int(time.time())) res = run_shell(cmd) stdout, stderr = res.communicate() print(' ---> ' + str(stdout) + ' === ' + str(stderr)) print( str(stdout, 'utf-8').split('backup summary: ')[1].split( '\ncost time(s)')[0]) assert res.returncode == 0 assert str(stdout, 'utf-8').split('backup summary: ')[1].split('\ncost time(s)')[0] == \ "{\n" \ "\tproperty key number: 0,\n" \ "\tvertex label number: 1,\n" \ "\tedge label number: 1,\n" \ "\tindex label number: 0,\n" \ "\tvertex number: 6,\n" \ "\tedge number: 8,\n}"
def init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作
def setup_class(self): """ 测试类开始 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作 InsertData(gremlin='gremlin_alg_03.txt').gremlin_graph()
def setup(self): """ 测试case开始 :param self: :return: """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作
def test_tool_execute_gremlin(self): """ 执行gremlin语句 :return: """ clear_graph() insert_data() # 测试 case cmd = "./bin/hugegraph --url %s --graph %s %s %s " \ "gremlin-execute --script 'g.V().count()' " res = run_shell(cmd) stdout, stderr = res.communicate() print(' ---> ' + str(stdout) + ' === ' + str(stderr)) assert res.returncode == 0 and str( stdout, 'utf-8').startswith('Run gremlin script\n6\n')
def init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作 query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \ "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \ "graph.schema().vertexLabel('person_name').properties('name').primaryKeys('name').ifNotExist().create();" \ "graph.schema().vertexLabel('person_age').properties('age').primaryKeys('age').ifNotExist().create();" \ "graph.schema().vertexLabel('person_date').properties('date').primaryKeys('date').ifNotExist().create();" code, res = Gremlin().gremlin_post(query, auth=auth) return code == 200
def init_graph(): """ 对测试环境进行初始化操作 """ code, res = GraphConnection().get_graph_connect() assert code == 200 connection_list = res['data']['records'] for each in connection_list: each_id = each['id'] each_graph = each['graph'] each_host = each['host'] each_port = each['port'] # clear graph if _cfg.server_backend == 'cassandra': clear_graph(graph_name=each_graph, graph_host=each_host, graph_port=each_port) else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作 # delete graph_connection code, res = GraphConnection().delete_graph_connect(each_id) assert code == 200
def init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作 query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \ "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name').primaryKeys('name').ifNotExist().create();" \ "graph.schema().edgeLabel('link').sourceLabel('person').targetLabel('person')" \ ".properties('name', 'age', 'date').ifNotExist().create();" \ "a = graph.addVertex(T.label, 'person', 'name', 'marko');" \ "b = graph.addVertex(T.label, 'person', 'name', 'vadas');" \ "a.addEdge('link', b, 'name', 'test', 'age', 29, 'date', '2021-02-07');" print(query) code, res = Gremlin().gremlin_post(query, auth=auth) return code == 200