Пример #1
0
 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]')
Пример #2
0
    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}"
Пример #3
0
 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()
Пример #4
0
 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}"
Пример #5
0
 def test_tool_get_mode(self):
     """
     查看图模式
     :return:
     """
     cmd = "./bin/hugegraph --url %s --graph %s %s %s graph-mode-get "
     res = run_shell(cmd)
     stdout, stderr = res.communicate()
     print(' ---> ' + str(stdout) + ' === ' + str(stderr))
     assert res.returncode == 0
     assert str(stdout, 'utf-8').startswith('Graph mode: NONE')
Пример #6
0
 def test_tool_get_task_success(self):
     """
     查看task列表 (状态为成功)
     :return:
     """
     cmd = "./bin/hugegraph --url  %s  --graph %s %s %s task-list  --status success "
     res = run_shell(cmd)
     stdout, stderr = res.communicate()
     print(' ---> ' + str(stdout) + ' === ' + str(stderr))
     assert res.returncode == 0
     assert str(stdout, 'utf-8').startswith('Tasks:')
Пример #7
0
    def test_tool_set_mode_merge(self):
        """
        设置图模式 MERGING
        :return:
        """
        cmd = "./bin/hugegraph --url  %s --graph %s %s %s  graph-mode-set -m MERGING "
        res_merging = run_shell(cmd)
        stdout, stderr = res_merging.communicate()
        print(' ---> ' + str(stdout) + ' === ' + str(stderr))
        assert res_merging.returncode == 0
        assert str(stdout, 'utf-8').startswith(
            "Set graph '%s' mode to 'MERGING'" % _cfg.graph_name)

        # 清空图模式
        res0 = run_shell(
            "./bin/hugegraph --url  %s --graph %s %s %s  graph-mode-set -m NONE "
        )
        res0.communicate()
        # stdout, stderr = res0.communicate()
        # print(' ---> ' + str(stdout) + ' === ' + str(stderr))
        print('设置图模式 MERGING - 测试case结束 - 清空图模式')
Пример #8
0
 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')
Пример #9
0
 def test_tool_clear_graph(self):
     """
     清理图 并进行二次确认
     :return:
     """
     cmd = "./bin/hugegraph --url %s --graph %s %s %s graph-clear --confirm-message " \
           " \"I'm sure to delete all data\" "
     res = run_shell(cmd)
     stdout, stderr = res.communicate()
     print(' ---> ' + str(stdout) + ' === ' + str(stderr))
     res_v, res_e = tools_assert()
     assert res.returncode == 0
     assert str(stdout, 'utf-8').startswith("Graph '%s' is cleared" % _cfg.graph_name) and \
            res_v == 0 and \
            res_e == 0
Пример #10
0
    def test_ttl_use_migrate(self):
        """
        顶点ttl + 数据迁移
        """
        # premise = 插入设置ttl的数据 顶点:艺人->ttl=5s;边:属于->ttl=5s
        gremlin = "graph.schema().propertyKey('名称').asText().ifNotExist().create();" \
                  "graph.schema().propertyKey('类型').asText().valueSet().ifNotExist().create();" \
                  "graph.schema().propertyKey('发行时间').asDate().ifNotExist().create();" \
                  "graph.schema().propertyKey('演员').asText().ifNotExist().create();" \
                  "graph.schema().vertexLabel('电影').useCustomizeStringId()" \
                  ".properties('名称','类型','发行时间').ifNotExist().create();" \
                  "graph.schema().vertexLabel('艺人').useCustomizeStringId().properties('演员')" \
                  ".ttl(5000L).ifNotExist().create();" \
                  "graph.schema().vertexLabel('类型').useCustomizeStringId().properties('类型').ifNotExist().create();" \
                  "graph.schema().vertexLabel('年份').useCustomizeStringId().properties('发行时间').ifNotExist().create();" \
                  "graph.schema().edgeLabel('导演').link('艺人','电影').ifNotExist().create();" \
                  "graph.schema().edgeLabel('演出').link('艺人','电影').ifNotExist().create();" \
                  "graph.schema().edgeLabel('属于').link('电影','类型').properties('发行时间')" \
                  ".ttl(5000L).ifNotExist().create();" \
                  "graph.schema().edgeLabel('发行于').link('电影','年份').properties('发行时间').ifNotExist().create();"
        code, res_gremlin = Gremlin().gremlin_post(gremlin, auth=auth)
        print(code, res_gremlin)
        assert 200
        assert res_gremlin['result']['data'][0]['name'] == '发行于'

        cmd = "%s/bin/hugegraph-loader.sh -h %s  -p %d  -g %s -f %s "
        res = InsertData(cmd, struct='struct_movie.json',
                         dir='movie').load_graph()
        res.communicate()

        time.sleep(30)  # ttl 生效后进行下边操作

        code, res = Gremlin().gremlin_post("g.V('吴宇森');", auth=auth)
        assert code == 200
        assert res['result']['data'] == []
        code, res = Gremlin().gremlin_post("g.E('S铁汉柔情 > 3 >> S动作');",
                                           auth=auth)
        assert code == 200
        assert res['result']['data'] == []

        #### 数据迁移
        target_clear_graph()

        cmd = "./bin/hugegraph --url %s --graph %s %s %s migrate " \
              "--target-url %s " \
              "--target-graph %s " \
              "%s " \
              "%s " \
              "--graph-mode RESTORING "
        res = run_shell(cmd)
        stdout, stderr = res.communicate()
        print(' ---> ' + str(stdout) + ' === ' + str(stderr))

        code, res = Gremlin().gremlin_post("g.V('吴宇森');",
                                           auth=target_auth,
                                           host=_cfg.tools_target_host,
                                           port=_cfg.tools_target_port,
                                           protocol=taret_protocol)
        print(code, res)
        assert code == 200
        assert res['result']['data'] == []
        code, res = Gremlin().gremlin_post("g.E('S铁汉柔情 > 3 >> S动作');",
                                           auth=target_auth,
                                           host=_cfg.tools_target_host,
                                           port=_cfg.tools_target_port,
                                           protocol=taret_protocol)
        print(code, res)
        assert code == 200
        assert res['result']['data'] == []