예제 #1
0
    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
예제 #2
0
def main_test():
    client = None
    try:
        space_name = 'space_' + threading.current_thread().getName()
        print('thread name: %s, space_name : %s' % 
                (threading.current_thread().getName(), space_name))
        # Get one client
        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')
        if has_space(query_resp.rows, space_name):
            print('has %s, drop it' % space_name)
            do_simple_execute(client, 'DROP SPACE %s' % space_name)

        # Create space mySpace
        do_simple_execute(client, 'CREATE SPACE %s'
                          % space_name)

        do_simple_execute(client, 'USE %s' % space_name)
        time.sleep(1)

        # Create tag and edge
        do_simple_execute(client, 'CREATE TAG person(name string, age int); '
                                  'CREATE EDGE like(likeness double)')

        # It should large than the cycle of loading the schema
        time.sleep(6)

        # Insert vertex and edge
        do_simple_execute(client, 'INSERT VERTEX person(name, age) VALUES 1:(\'Bob\', 10)')
        do_simple_execute(client, 'INSERT VERTEX person(name, age) VALUES 2:(\'Lily\', 9)')
        do_simple_execute(client, 'INSERT VERTEX person(name, age) VALUES 3:(\'Tom\', 10)')
        do_simple_execute(client, 'INSERT VERTEX person(name, age) VALUES 4:(\'Jerry\', 13);INSERT VERTEX person(name, age) VALUES 5:(\'John\', 11)')
        do_simple_execute(client, 'INSERT EDGE like(likeness) VALUES 1->2:(80.0)')
        do_simple_execute(client, 'INSERT EDGE like(likeness) VALUES 1->3:(70.0)')
        do_simple_execute(client, 'INSERT EDGE like(likeness) VALUES 2->4:(84.0), 3->5:(68.3), 1->5:(97.2)')

        # Query data
        query_resp = client.execute_query('GO FROM 1 OVER like YIELD $$.person.name, '
                                          '$$.person.age, like.likeness')
        if query_resp.error_code:
            print('Execute failed: %s' % query_resp.error_msg)
            exit(1)

        # Print the result of query
        print(' \n====== The query result of thread[%s]======\n '
              % threading.current_thread().getName())
        print_value(query_resp.column_names, query_resp.rows)
        client.sign_out()
    except Exception as x:
        print(x)

        client.sign_out()
        exit(1)
예제 #3
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