コード例 #1
0
class Test(unittest.TestCase):


    def setUp(self):
        self.hyperdex_client = Client(ADDRESS, PORT)
        self.hyperdex_admin = Admin(ADDRESS, PORT)
        self.typeadmin = TypeAdmin(ADDRESS, PORT, GRAPH, self.hyperdex_client, self.hyperdex_admin)
        self.typeadmin.validate_database()


    def tearDown(self):
        self.hyperdex_admin.rm_space(TYPE_DESCRIPTION)
        


    def test__stringify_attributes(self):
        attributes  = [('string', 'name'), ('int', 'age')]
        result = self.typeadmin._stringify_attributes(attributes)
        self.assertEqual(' string name,\n int age', result)
        
    def test__dictify_attributes(self):
        attributes  = [('string', 'name'), ('int', 'age')]
        result = self.typeadmin._dictify_attributes(attributes)
        self.assertDictEqual({'name':'string', 'age':'int'}, result)

    def test_create_element_type(self):
        attributes  = [('string', 'name'), ('int', 'age')]
        self.typeadmin.create_element_type(vertex_type, attributes)
        self.typeadmin.remove_element_type(vertex_type)
コード例 #2
0
class Test(unittest.TestCase):
    def setUp(self):
        self.hyperdex_client = Client(ADDRESS, PORT)
        self.hyperdex_admin = Admin(ADDRESS, PORT)
        self.typeadmin = TypeAdmin(ADDRESS, PORT, GRAPH, self.hyperdex_client,
                                   self.hyperdex_admin)
        self.typeadmin.validate_database()

    def tearDown(self):
        self.hyperdex_admin.rm_space(TYPE_DESCRIPTION)

    def test__stringify_attributes(self):
        attributes = [('string', 'name'), ('int', 'age')]
        result = self.typeadmin._stringify_attributes(attributes)
        self.assertEqual(' string name,\n int age', result)

    def test__dictify_attributes(self):
        attributes = [('string', 'name'), ('int', 'age')]
        result = self.typeadmin._dictify_attributes(attributes)
        self.assertDictEqual({'name': 'string', 'age': 'int'}, result)

    def test_create_element_type(self):
        attributes = [('string', 'name'), ('int', 'age')]
        self.typeadmin.create_element_type(vertex_type, attributes)
        self.typeadmin.remove_element_type(vertex_type)
コード例 #3
0
ファイル: storage.py プロジェクト: Schille/weimar-graphstore
    def __init__(self, address, port, graph_name):
        '''
        Constructor.
        
        Args:
            address: The IP address of HyperDex's coordinator process (str).
            port: The port number of HyperDex's coordinator process (int).
        
        Returns:
            An instance of the HyperDexStore, which wraps the underlying connection.
        '''
        self._address = address
        self._port = port
        self._graph_name = graph_name
        self.hyperdex_client = Client(address,
                                      port)  #HyperDex python binding (Client)
        self.hyperdex_admin = Admin(address,
                                    port)  #HyperDex python binding (Admin)
        self.sysadmin = SysAdmin(address, port, graph_name,
                                 self.hyperdex_client, self.hyperdex_admin)
        self.typeadmin = TypeAdmin(address, port, graph_name,
                                   self.hyperdex_client, self.hyperdex_admin)
        #validate the underlying database for the particular components, i.e.
        #checking for the system/description space
        self.sysadmin.validate_database()
        self.typeadmin.validate_database()

        self._generic_vertex = graph_name + '_generic_vertex'
        self.validate_database()
コード例 #4
0
ファイル: storage.py プロジェクト: Schille/weimar-graphstore
class HyperDexStore():
    '''
    The HyperDexStore class provides the first level of abstraction towards the client. It
    wraps the HyperDex python language binding. It is used by the HyperDexGraph API and 
    handles the underlying connection to the database.
    '''
    def __init__(self, address, port, graph_name):
        '''
        Constructor.
        
        Args:
            address: The IP address of HyperDex's coordinator process (str).
            port: The port number of HyperDex's coordinator process (int).
        
        Returns:
            An instance of the HyperDexStore, which wraps the underlying connection.
        '''
        self._address = address
        self._port = port
        self._graph_name = graph_name
        self.hyperdex_client = Client(address,
                                      port)  #HyperDex python binding (Client)
        self.hyperdex_admin = Admin(address,
                                    port)  #HyperDex python binding (Admin)
        self.sysadmin = SysAdmin(address, port, graph_name,
                                 self.hyperdex_client, self.hyperdex_admin)
        self.typeadmin = TypeAdmin(address, port, graph_name,
                                   self.hyperdex_client, self.hyperdex_admin)
        #validate the underlying database for the particular components, i.e.
        #checking for the system/description space
        self.sysadmin.validate_database()
        self.typeadmin.validate_database()

        self._generic_vertex = graph_name + '_generic_vertex'
        self.validate_database()

    def validate_database(self):
        try:
            self.hyperdex_client.get(self._generic_vertex, 1)
            logging.info('Generic vertices available')
        except HyperClientException, e:
            if e.symbol() == 'HYPERDEX_CLIENT_UNKNOWNSPACE':
                logging.info('Creating space generic_vertex')
                self.hyperdex_admin.add_space('''
                space ''' + self._generic_vertex + '''
                key int id
                attributes 
                   map(int, string) incoming_edges,
                   map(int, string) outgoing_edges,
                   string value
                ''')
                os.system('hyperdex wait-until-stable -h {} -p {}'.format(
                    self._address, self._port))
                return
            logging.error(str(e))
コード例 #5
0
ファイル: storage.py プロジェクト: Schille/weimar-graphstore
class HyperDexStore():
    '''
    The HyperDexStore class provides the first level of abstraction towards the client. It
    wraps the HyperDex python language binding. It is used by the HyperDexGraph API and 
    handles the underlying connection to the database.
    '''

    def __init__(self, address, port, graph_name):
        '''
        Constructor.
        
        Args:
            address: The IP address of HyperDex's coordinator process (str).
            port: The port number of HyperDex's coordinator process (int).
        
        Returns:
            An instance of the HyperDexStore, which wraps the underlying connection.
        '''
        self._address = address
        self._port = port
        self._graph_name = graph_name
        self.hyperdex_client = Client(address, port)#HyperDex python binding (Client)
        self.hyperdex_admin = Admin(address, port)#HyperDex python binding (Admin)
        self.sysadmin = SysAdmin(address, port, graph_name,  self.hyperdex_client, self.hyperdex_admin)
        self.typeadmin = TypeAdmin(address, port, graph_name, self.hyperdex_client, self.hyperdex_admin)
        #validate the underlying database for the particular components, i.e.
        #checking for the system/description space
        self.sysadmin.validate_database()
        self.typeadmin.validate_database()
        
        self._generic_vertex = graph_name + '_generic_vertex'
        self.validate_database()
        
    def validate_database(self):
        try:
            self.hyperdex_client.get(self._generic_vertex, 1)
            logging.info('Generic vertices available')
        except HyperClientException, e:
            if e.symbol() == 'HYPERDEX_CLIENT_UNKNOWNSPACE':
                logging.info('Creating space generic_vertex')
                self.hyperdex_admin.add_space('''
                space '''+ self._generic_vertex + '''
                key int id
                attributes 
                   map(int, string) incoming_edges,
                   map(int, string) outgoing_edges,
                   string value
                ''')
                os.system('hyperdex wait-until-stable -h {} -p {}'.format(self._address, self._port))
                return
            logging.error(str(e))
コード例 #6
0
ファイル: storage.py プロジェクト: Schille/weimar-graphstore
 def __init__(self, address, port, graph_name):
     '''
     Constructor.
     
     Args:
         address: The IP address of HyperDex's coordinator process (str).
         port: The port number of HyperDex's coordinator process (int).
     
     Returns:
         An instance of the HyperDexStore, which wraps the underlying connection.
     '''
     self._address = address
     self._port = port
     self._graph_name = graph_name
     self.hyperdex_client = Client(address, port)#HyperDex python binding (Client)
     self.hyperdex_admin = Admin(address, port)#HyperDex python binding (Admin)
     self.sysadmin = SysAdmin(address, port, graph_name,  self.hyperdex_client, self.hyperdex_admin)
     self.typeadmin = TypeAdmin(address, port, graph_name, self.hyperdex_client, self.hyperdex_admin)
     #validate the underlying database for the particular components, i.e.
     #checking for the system/description space
     self.sysadmin.validate_database()
     self.typeadmin.validate_database()
     
     self._generic_vertex = graph_name + '_generic_vertex'
     self.validate_database()
コード例 #7
0
class Test(unittest.TestCase):
    def setUp(self):
        self.hyperdex = Admin(ADDRESS, PORT)
        self.hyperdex_client = Client(ADDRESS, PORT)
        self.g = HyperDexGraph(ADDRESS, PORT, GRAPH)

    def tearDown(self):
        self.hyperdex.rm_space(TYPE_DESCRIPTION)
        self.hyperdex.rm_space(SYSTEM)
        self.hyperdex.rm_space(GENERIC_VERTEX)
        self.hyperdex.rm_space('id')
        self.hyperdex.rm_space(GRAPH + '_id_sys')

    def test_count_elements(self):
        user_req = RequestVertexType('User', ('string', 'name'),
                                     ('int', 'age'))
        self.g.create_vertex_type(user_req)
        user = self.g.get_vertex_type('User')
        for i in xrange(50):
            self.g.insert_vertex(
                RequestVertex(user, {
                    'name': 'user' + str(i),
                    'age': i
                }))
        self.assertEqual(50, user.count())
        user.remove()

    def test_iterate_elements(self):
        user_req = RequestVertexType('User', ('string', 'name'),
                                     ('int', 'age'))
        self.g.create_vertex_type(user_req)
        user = self.g.get_vertex_type('User')
        for i in xrange(50):
            self.g.insert_vertex(
                RequestVertex(user, {
                    'name': 'user' + str(i),
                    'age': i
                }))
        user = self.g.get_vertex_type('User')
        all_users = user.get_vertices()
        self.assertEqual(50, len(all_users))
        self.assertTrue(isinstance(all_users[0], Vertex))
        user.remove()
コード例 #8
0
class Test(unittest.TestCase):


    def setUp(self):
        self.hyperdex = Admin(ADDRESS, PORT)
        self.hyperdex_client = Client(ADDRESS, PORT)
        self.g = HyperDexGraph(ADDRESS, PORT, GRAPH)


    def tearDown(self):
        self.hyperdex.rm_space(TYPE_DESCRIPTION)
        self.hyperdex.rm_space(SYSTEM)
        self.hyperdex.rm_space(GENERIC_VERTEX)
        self.hyperdex.rm_space('id')
        self.hyperdex.rm_space(GRAPH + '_id_sys')

    def test_count_elements(self):
        user_req = RequestVertexType('User', ('string', 'name'), ('int', 'age'))
        self.g.create_vertex_type(user_req)
        user = self.g.get_vertex_type('User')
        for i in xrange(50):
            self.g.insert_vertex(RequestVertex(user, {'name':'user'+str(i) , 'age':i}))
        self.assertEqual(50, user.count())
        user.remove()
        
        
    def test_iterate_elements(self):
        user_req = RequestVertexType('User', ('string', 'name'), ('int', 'age'))
        self.g.create_vertex_type(user_req)
        user = self.g.get_vertex_type('User')
        for i in xrange(50):
            self.g.insert_vertex(RequestVertex(user, {'name':'user'+str(i) , 'age':i}))
        user = self.g.get_vertex_type('User')
        all_users = user.get_vertices()
        self.assertEqual(50, len(all_users))
        self.assertTrue(isinstance(all_users[0], Vertex))
        user.remove()
コード例 #9
0
 def setUp(self):
     self.hyperdex_client = Client(ADDRESS, PORT)
     self.hyperdex_admin = Admin(ADDRESS, PORT)
     self.typeadmin = TypeAdmin(ADDRESS, PORT, GRAPH, self.hyperdex_client, self.hyperdex_admin)
     self.typeadmin.validate_database()
コード例 #10
0
 def setUp(self):
     self.hyperdex = Admin(ADDRESS, PORT)
     self.hyperdex_client = Client(ADDRESS, PORT)
     self.g = HyperDexGraph(ADDRESS, PORT, GRAPH)
コード例 #11
0
 def setUp(self):
     self.hyperdex = Admin(ADDRESS, PORT)
     self.hyperdex_client = Client(ADDRESS, PORT)
     self.g = HyperDexGraph(ADDRESS, PORT, GRAPH)
コード例 #12
0
class Test(unittest.TestCase):


    def setUp(self):
        self.hyperdex = Admin(ADDRESS, PORT)
        self.hyperdex_client = Client(ADDRESS, PORT)
        self.g = HyperDexGraph(ADDRESS, PORT, GRAPH)


    def tearDown(self):
        self.hyperdex.rm_space(TYPE_DESCRIPTION)
        self.hyperdex.rm_space(SYSTEM)
        self.hyperdex.rm_space(GENERIC_VERTEX)
        self.hyperdex.rm_space('id')
        self.hyperdex.rm_space(GRAPH + '_id_sys')
        
        


    def test_create_vertex_type(self):
        req1 = RequestVertexType(vertex_type, ('string', 'name'), ('int', 'age'))
        vertext1 = self.g.create_vertex_type(req1)
        self.assertDictEqual({'age': 'int', 'outgoing_edges': 'map(int, string)', 'incoming_edges': 'map(int, string)', 'name': 'string'},
                             vertext1.get_type_definition())
        self.assertEqual(vertex_type, vertext1.get_type_name())
        os.system('hyperdex wait-until-stable -h {} -p {}'.format(ADDRESS, PORT))
        vertext1.remove()
        
    def test_create_edge_type(self):
        req1 = RequestEdgeType(edge_type,('string', 'name'), ('int', 'age'))
        #pydevd.settrace('192.168.57.1', 5678)
        edge1 = self.g.create_edge_type(req1)
        self.assertEqual({'source_vertex_type': 'string', 'age': 'int', 'name': 'string', 'source_uid': 'int', 'target': 'map(int, string)'},
                          edge1.get_type_definition())
        os.system('hyperdex wait-until-stable -h {} -p {}'.format(ADDRESS, PORT))
        edge1.remove()
        
    def test_get_vertex_type(self):
        req1 = RequestVertexType(vertex_type, ('string', 'name'), ('int', 'age'))
        self.g.create_vertex_type(req1)
        vertext1 = self.g.get_vertex_type(vertex_type)
        self.assertDictEqual({'age': 'int', 'outgoing_edges': 'map(int, string)', 'incoming_edges': 'map(int, string)', 'name': 'string'},
                             vertext1.get_type_definition())
        self.assertEqual(vertex_type, vertext1.get_type_name())
        vertext1.remove()
        
    def test_complex_graph(self):
        pass
        #pydevd.settrace('192.168.57.1', 5678)
        #create vertex type User
        user_type=RequestVertexType('User', ('string', 'first'), ('string', 'last'), ('int', 'age'))
        user=self.g.create_vertex_type(user_type)
        #create vertex type Movie
        movie_type=RequestVertexType('Movie', ('string', 'title'), ('int', 'length'), ('int', 'released'), ('string', 'type'))
        movie=self.g.create_vertex_type(movie_type)
        #create edge type rates
        rates_type=RequestEdgeType('rates', ('int', 'stars'))
        rates=self.g.create_edge_type(rates_type)
        #insert some users
        u1=self.g.insert_vertex(RequestVertex(user, {'first':'Scrooge', 'last':'McDuck', 'age':67}))
        u2=self.g.insert_vertex(RequestVertex(user, {'first':'Donald', 'last':'Duck', 'age':77}))
        u3=self.g.insert_vertex(RequestVertex(user, {'first':'Mikey', 'last':'Mouse', 'age':80}))
        u4=self.g.insert_vertex(RequestVertex(user, {'first':'Gus', 'last':'Goose', 'age':76}))
        u5=self.g.insert_vertex(RequestVertex(user, {'first':'Black', 'last':'Pete', 'age':83}))
        #insert some movies
        m1=self.g.insert_vertex(RequestVertex(movie, {'title':'DuckTails', 'length':22, 'released':1987,'type':'series'}))
        m2=self.g.insert_vertex(RequestVertex(movie, {'title':'The Wise Little Hen', 'length':7, 'released':1934,'type':'film'}))
        m3=self.g.insert_vertex(RequestVertex(movie, {'title':'Mickey\'s Christmas Carol', 'length':25, 'released':1983,'type':'film'}))
        m4=self.g.insert_vertex(RequestVertex(movie, {'title':'Darkwing Duck', 'length':22, 'released':1991,'type':'series'}))
        #attach some movie ratings
        u1.add_edge(m1, rates, {'stars':5})
        u2.add_edge(m1, rates, {'stars':3})
        u2.add_edge(m2, rates, {'stars':1})
        u2.add_edge(m4, rates, {'stars':5})
        u3.add_edge(m2, rates, {'stars':4})
        u3.add_edge(m3, rates, {'stars':5})
        u3.add_edge(m1, rates, {'stars':2})
        u4.add_edge(m1, rates, {'stars':4})
        u4.add_edge(m4, rates, {'stars':5})
        u5.add_edge(m1, rates, {'stars':1})
        u5.add_edge(m3, rates, {'stars':1})
        u5.add_edge(m4, rates, {'stars':2})
        
        #count if everything is present
        self.assertEqual(5, user.count())
        self.assertEqual(4, movie.count())
        self.assertEqual(12, rates.count())
        #perform some simple traversals
        self.assertEqual('DuckTails',u1.get_outgoing_edges(rates)[0].get_target()[0].get_property('title'))
        #calc avg rating of DuckTails
        r, c = 0,0
        for rating in m1.get_incoming_edges(rates):
            c = c + 1
            r = r + rating.stars
        self.assertEqual(3, r / c) # Average stars will be 15 / 5 = 3
        #search vertices
        l1=self.g.search_vertex(user, ('last', 'Duck'))
        r = []
        for vertex in l1:
            r.append(vertex.first + ' ' + vertex.last)
        self.assertIn('Donald Duck', r)
        #Reqex search is not yet implemented
        #self.assertIn('Scrooge McDuck', r)
        
        #pydevd.settrace('192.168.57.1', 5678)
        self.assertEqual(3, len(m4.get_incoming_edges()))
        self.assertEqual(3, len(u2.get_outgoing_edges()))
        #remove an item recursively 
        m4.remove()
        self.assertEqual(5, user.count())
        self.assertEqual(3, movie.count())
        self.assertEqual(9, rates.count())
        self.assertEqual(2, len(u2.get_outgoing_edges()))
        #remove yet another item 
        u1.remove()
        #calc avg rating of DuckTails again
        r, c = 0,0
        for rating in m1.get_incoming_edges(rates):
            c = c + 1
            r = r + rating.get_property('stars')
        self.assertEqual(2.5, r / float(c)) # Average stars will be now 10 / 4 = 2.5
        
        #add some unstructured attributes
        m1.set_property('comment', 'DuckTales is an American animated television series produced by Disney Television Animation.')
        #see whether it was stored.
        self.assertItemsEqual(['comment', 'outgoing_edges', 'incoming_edges', 'title',\
                               'released', 'length', 'type'], m1.get_property_keys())
        self.assertEqual('DuckTales is an American animated television series produced by Disney Television Animation.',m1.comment)
        
        
        #remove everything
        user.remove()
        movie.remove()
        rates.remove()

    
    def test_insert_vertex(self):
        user_type=RequestVertexType('User', ('string', 'first'), ('string', 'last'), ('int', 'age'))
        user=self.g.create_vertex_type(user_type)
        u1=self.g.insert_vertex(RequestVertex(user, {'first':'Scrooge', 'last':'McDuck', 'age':67, 'comment': 'Bla Blubb'}))
        u2=self.g.insert_vertex(RequestVertex(user, {'first':'Donald', 'last':'Duck', 'age':77}))
        u3=self.g.insert_vertex(RequestVertex(user, {'first':'Mikey', 'age':80}))
        u4=self.g.insert_vertex(RequestVertex(user, {'first':'Gus'}))
        u5=self.g.insert_vertex(RequestVertex(user, {'first':'Black', 'last':'Pete', 'age':83, 'props': {'attr1': set([1,2,3,4]), 'attr2': [5,6,7,8]}}))
        self.assertIn('comment', u1.get_property_keys())
        self.assertEqual('', u4.last)
        self.assertIsNone(u2.get_property('not_available'))
        self.assertEqual(80, u3.age)
        self.assertEqual({'attr1': set([1,2,3,4]), 'attr2': [5,6,7,8]}, u5.get_property('props'))
        self.assertEqual(5,user.count())
        user.remove()
コード例 #13
0
 def setUp(self):
     self.hyperdex_client = Client(ADDRESS, PORT)
     self.hyperdex_admin = Admin(ADDRESS, PORT)
     self.typeadmin = TypeAdmin(ADDRESS, PORT, GRAPH, self.hyperdex_client,
                                self.hyperdex_admin)
     self.typeadmin.validate_database()