예제 #1
0
def test_multi_thread():
    # Test multi thread
    connection_pool = ConnectionPool('127.0.0.1', get_port())

    global success_flag
    success_flag = True

    def main_test():
        client = None
        global success_flag
        try:
            client = GraphClient(connection_pool)
            if client.is_none():
                print("ERROR: None client")
                success_flag = False
                return
            space_name = 'space_' + threading.current_thread().getName()
            resp = client.authenticate('user', 'password')
            if resp.error_code != 0:
                raise AuthException('Auth failed')

            client.execute('DROP SPACE %s' % space_name)
            resp = client.execute('CREATE SPACE %s' % space_name)
            if resp.error_code != 0:
                raise ExecutionException('CREATE SPACE failed')

            resp = client.execute('USE %s' % space_name)
            if resp.error_code != 0:
                raise ExecutionException('USE SPACE failed')

            client.sign_out()
        except Exception as x:
            print(x)
            client.sign_out()
            success_flag = False
            return

    thread1 = threading.Thread(target=main_test, name='thread1')
    thread2 = threading.Thread(target=main_test, name='thread2')
    thread3 = threading.Thread(target=main_test, name='thread3')
    thread4 = threading.Thread(target=main_test, name='thread4')

    thread1.start()
    thread2.start()
    thread3.start()
    thread4.start()

    thread1.join()
    thread2.join()
    thread3.join()
    thread4.join()

    connection_pool.close()
    assert success_flag
예제 #2
0
파일: index.py 프로젝트: Sasasu/bgm-graph
def create_client(arg: Arg) -> typing.Optional[GraphClient]:
    connection_pool = ConnectionPool(arg.addr, arg.port)
    client = GraphClient(connection_pool)
    client.set_space('bgm')
    try:
        client.authenticate(arg.u, arg.p)
    except AuthException as e:
        print(e)
        return None

    return client
예제 #3
0
def read_feats():
    g_ip = '192.168.8.188'
    g_port = 3699
    connection_pool = ConnectionPool(g_ip, g_port)
    client = GraphClient(connection_pool)
    auth_resp = client.authenticate('root', '')
    if auth_resp.error_code:
        raise AuthException("Auth failed")
    client.execute_query("use cora")
    query_resp = client.execute_query("LOOKUP ON paper WHERE paper.num > 0")
    num_nodes = len(query_resp.rows)
    labels = np.empty((num_nodes, 1), dtype=np.int64)
    label_map = {}

    query_resp = client.execute_query("fetch prop ON paper 1")
    feature_str = query_resp.rows[0].columns[2].get_str().decode().replace(
        ' ', '')
    feat_data = np.zeros((num_nodes, len(feature_str)))

    adj_lists = defaultdict(set)

    for i in range(num_nodes):
        query_resp = client.execute_query("fetch prop ON paper {}".format(i))
        feature_str = query_resp.rows[0].columns[2].get_str().decode()
        label = query_resp.rows[0].columns[3].get_str().decode()
        feature = np.fromstring(str(feature_str), dtype=int, sep=' ')
        feat_data[i] = feature
        if not label in label_map:
            label_map[label] = len(label_map)
        labels[i] = label_map[label]

        edge_query = client.execute_query("GO FROM {} OVER cite".format(i + 1))
        if edge_query.rows is None:
            continue
        for row in edge_query.rows:
            paperId = row.columns[0].get_id()
            adj_lists[i].add(int(paperId))
            adj_lists[int(paperId)].add(i)

    return feat_data, labels, adj_lists
예제 #4
0
if __name__ == '__main__':

    g_ip = '127.0.0.1'
    g_port = 3699

    print('input argv num is %d' % len(sys.argv))
    if len(sys.argv) == 3:
        print('input argv num is 3')
        g_ip = sys.argv[1]
        print('ip: %s' % g_ip)
        g_port = sys.argv[2]
        print('port: %s' % g_port)

    # init connection pool
    connection_pool = ConnectionPool(g_ip, g_port)

    # Test multi thread
    thread1 = threading.Thread(target=main_test, name='thread1')
    thread2 = threading.Thread(target=main_test, name='thread2')
    thread3 = threading.Thread(target=main_test, name='thread3')
    thread4 = threading.Thread(target=main_test, name='thread4')

    thread1.start()
    thread2.start()
    thread3.start()
    thread4.start()

    thread1.join()
    thread2.join()
    thread3.join()
예제 #5
0
        g_ip = '127.0.0.1'
        g_port = 3699

        print('input argv num is %d' % len(sys.argv))
        if len(sys.argv) == 3:
            print('input argv num is 3')
            g_ip = sys.argv[1]
            print('ip: %s' % g_ip)
            g_port = sys.argv[2]
            print('port: %s' % g_port)

        # init connection pool
        # if your tags or edges' num is more than 10,
        # please make sure conn_num >= max(tags_num, edges_num) * 2
        conn_num = 20
        connection_pool = ConnectionPool(g_ip, g_port, conn_num)

        clients = []
        for i in range(0, conn_num):
            client = GraphClient(connection_pool)
            client.authenticate('user', 'password')
            client.execute('USE test')
            clients.append(client)
        # Get client
        resp = clients[0].execute_query('SHOW TAGS')
        if resp.error_code:
            raise ExecutionException('SHOW TAGS failed')

        tag_list = []
        for row in resp.rows:
            tag_list.append(row.columns[1].get_str().decode('utf-8'))
 def __init__(self, ip, port):
     connection_pool = ConnectionPool(ip, port, 1, 0)
     self._client = GraphClient(connection_pool)
     self._client.authenticate('root', 'nebula')
     self._spaces = []
     self._stmts = []

def test_response():
    client = GraphClient(connection_pool)
    auth_resp = client.authenticate('user', 'password')
    if auth_resp.error_code:
        raise AuthException("Auth failed")

    query_resp = client.execute_query('SHOW SPACES')
    do_simple_execute(client, 'use nba')
    query_resp = client.execute_query(
        'GO FROM 100 OVER follow,serve yield follow._dst,serve._dst')

    query_resp = client.execute_query('fetch prop on * 100')
    for row in query_resp.rows:
        for ids, col in enumerate(row.columns):
            print(col)
    # query_resp = client.execute_query('FETCH PROP ON follow 100->102')
    # print(query_resp.column_names)
    # print(query_resp.rows)


if __name__ == '__main__':

    g_ip = '127.0.0.1'
    g_port = 3699

    # init connection pool
    connection_pool = ConnectionPool(g_ip, g_port)
    test_response()
예제 #8
0
def create_pool(port):
    return ConnectionPool('127.0.0.1', port)
예제 #9
0
    parser.add_argument('-c',
                        '--config',
                        help='spark importer config path',
                        type=str,
                        default="application.conf")

    parser.add_argument(
        '-l',
        '--log_level',
        help='log level=> 10:debug, 20:info, 30:warn, 40:error',
        type=int,
        default=30)
    args = parser.parse_args()

    connection_pool = ConnectionPool(
        args.address.split(":")[0],
        args.address.split(":")[1])
    client = GraphClient(connection_pool)
    auth_resp = client.authenticate(args.user, args.password)
    if auth_resp.error_code:
        raise AuthException("Auth failed")

    conf = ConfigFactory.parse_file(args.config)

    data = []
    for j in args.jsons:
        with open(j) as f:
            data.append(json.load(f))

    logger.setLevel(args.log_level)
    verify_nebula(client, data, conf)
예제 #10
0
def test_prepare():
    try:
        client = GraphClient(ConnectionPool(host, graph_port))
        if client is None:
            print('Error: None GraphClient')
            assert False
            return
        resp = client.authenticate('user', 'password')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute('DROP SPACE IF EXISTS %s' % space_name)
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute('CREATE SPACE %s(partition_num=1)' % space_name)
        assert resp.error_code == 0, resp.error_msg
        time.sleep(5)
        resp = client.execute('USE %s' % space_name)
        assert resp.error_code == 0, resp.error_msg
        time.sleep(5)
        resp = client.execute(
            'CREATE TAG player(name string, age int, married bool)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute('CREATE TAG team(name string, money double)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'CREATE EDGE follow(degree double, likeness int)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'CREATE EDGE serve(start timestamp, end timestamp)')
        assert resp.error_code == 0, resp.error_msg
        time.sleep(12)
        resp = client.execute(
            'INSERT VERTEX player(name, age, married) VALUES 101:(\'Bob\', 18, FALSE)'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT VERTEX player(name, age, married) VALUES 102:(\'Tom\', 22, TRUE)'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT VERTEX player(name, age, married) VALUES 103:(\'Jerry\', 19, FALSE)'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT VERTEX team(name, money) VALUES 201:(\'Red Bull\', 185.85)'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT VERTEX team(name, money) VALUES 202:(\'River\', 567.93)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT EDGE follow(degree, likeness) VALUES 101->102:(94.7, 45)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT EDGE follow(degree, likeness) VALUES 102->103:(86.3, 79)')
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT EDGE serve(start, end) VALUES 101->201:(\'2001-09-01 08:00:00\', \'2010-09-01 08:00:00\')'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT EDGE serve(start, end) VALUES 102->202:(\'1998-08-22 06:45:54\', \'2020-01-23 17:23:35\')'
        )
        assert resp.error_code == 0, resp.error_msg
        resp = client.execute(
            'INSERT EDGE serve(start, end) VALUES 103->201:(\'2006-11-18 13:28:29\', \'2009-12-12 12:21:46\')'
        )
        assert resp.error_code == 0, resp.error_msg
    except Exception as ex:
        print(ex)
        client.sign_out()
        assert False