Ejemplo n.º 1
0
 def setup_class(cls):
     # create schema
     try:
         conn = Connection()
         conn.open('127.0.0.1', 9669, 1000)
         auth_result = conn.authenticate('root', 'nebula')
         session_id = auth_result.get_session_id()
         assert session_id != 0
         resp = conn.execute(
             session_id,
             'CREATE SPACE IF NOT EXISTS test_meta_cache1(REPLICA_FACTOR=3, vid_type=FIXED_STRING(8));'
             'USE test_meta_cache1;'
             'CREATE TAG IF NOT EXISTS tag11(name string);'
             'CREATE EDGE IF NOT EXISTS edge11(name string);'
             'CREATE SPACE IF NOT EXISTS test_meta_cache2(vid_type=FIXED_STRING(8));'
             'USE test_meta_cache2;'
             'CREATE TAG IF NOT EXISTS tag22(name string);'
             'CREATE EDGE IF NOT EXISTS edge22(name string);')
         assert resp.error_code == 0
         conn.close()
         time.sleep(10)
         cls.meta_cache = MetaCache([('127.0.0.1', 9559),
                                     ('127.0.0.1', 9560),
                                     ('127.0.0.1', 9560)], 50000)
     except Exception as x:
         import traceback
         print(traceback.format_exc())
         assert False
Ejemplo n.º 2
0
    def setup_class(cls):
        try:
            conn = Connection()
            conn.open('127.0.0.1', 9671, 3000)
            auth_result = conn.authenticate('root', 'nebula')
            session_id = auth_result.get_session_id()
            assert session_id != 0
            cls.execute_with_retry(conn,
                                   session_id,
                                   'CREATE SPACE IF NOT EXISTS test_graph_storage_client('
                                   'PARTITION_NUM=10,'
                                   'REPLICA_FACTOR=1,'
                                   'vid_type=FIXED_STRING(20));'
                                   'USE test_graph_storage_client;'
                                   'CREATE TAG IF NOT EXISTS person(name string, age int);'
                                   'CREATE EDGE IF NOT EXISTS friend(start int, end int);')
            time.sleep(5)

            for id in range(1000):
                vid = 'person' + str(id)
                cmd = 'INSERT VERTEX person(name, age) ' \
                      'VALUES \"{}\":(\"{}\", {})'.format(vid, vid, id)
                cls.execute_with_retry(conn, session_id, cmd)
            for id in range(1000):
                src_id = 'person' + str(id)
                dst_id = 'person' + str(1000 - id)
                start = random.randint(2000, 2010)
                end = random.randint(2010, 2020)
                cmd = 'INSERT EDGE friend(start, end) ' \
                      'VALUES \"{}\"->\"{}\":({}, {})'.format(src_id, dst_id, start, end)
                cls.execute_with_retry(conn, session_id, cmd)
            conn.close()

            meta_cache = MetaCache([('172.28.1.1', 9559),
                                    ('172.28.1.2', 9559),
                                    ('172.28.1.3', 9559)],
                                   50000)
            cls.graph_storage_client = GraphStorageClient(meta_cache)

        except Exception:
            import traceback
            print(traceback.format_exc())
            assert False
(person18)-[:friend@0{'start': 2004, 'end': 2012}]->(person2)
(person6)-[:friend@0{'start': 2001, 'end': 2017}]->(person14)
(person7)-[:friend@0{'start': 2009, 'end': 2015}]->(person13)
(person12)-[:friend@0{'start': 2007, 'end': 2010}]->(person8)
(person17)-[:friend@0{'start': 2008, 'end': 2013}]->(person3)
(person5)-[:friend@0{'start': 2005, 'end': 2015}]->(person15)
(person8)-[:friend@0{'start': 2000, 'end': 2019}]->(person12)
"""

if __name__ == '__main__':
    meta_cache = None
    graph_storage_client = None
    try:
        # the metad servers's address
        meta_cache = MetaCache([('172.28.1.1', 45500),
                                ('172.28.1.2', 45500),
                                ('172.28.1.3', 45500)],
                               50000)
        graph_storage_client = GraphStorageClient(meta_cache)
        prepare_data()
        scan_person_vertex(graph_storage_client)
        scan_person_edge(graph_storage_client)

    except Exception as x:
        import traceback
        print(traceback.format_exc())
        if graph_storage_client is not None:
            graph_storage_client.close()
        exit(1)
    finally:
        if graph_storage_client is not None:
            graph_storage_client.close()