Esempio n. 1
0
 def test_init_with_allocation(self):
     path = "/test"
     alloc_list = [{
         "start": 100,
         "end": 200
     }, {
         "start": 300,
         "end": 400
     }, {
         "start": 10,
         "end": 20
     }, {
         "start": 10000000,
         "end": 340282366920938463463374607431768211455
     }]
     allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                               path,
                                               100,
                                               start_idx=0,
                                               reverse=False,
                                               alloc_list=alloc_list,
                                               max_alloc=0)
     session = self.Session()
     allocations = session.query(vnc_rdbms.IDPool).all()
     self.assertEqual(4, len(allocations))
Esempio n. 2
0
 def test_delete_all(self):
     path = "/test"
     allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                               path,
                                               2,
                                               start_idx=0)
     session = self.Session()
     allocator.alloc("alloc1")
     allocator.alloc("alloc2")
     vnc_rdbms.RDBMSIndexAllocator.delete_all(self.db, path)
     allocations = session.query(vnc_rdbms.IDPool).all()
     self.assertEqual(0, len(allocations))
Esempio n. 3
0
    def test_set_in_use(self):
        path = "/test"
        allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                                  path,
                                                  100,
                                                  start_idx=0)
        session = self.Session()
        allocator.set_in_use(50)

        allocations = session.query(vnc_rdbms.IDPool).all()
        self.assertEqual(3, len(allocations))
        self.assertEqual(1, allocator.get_alloc_count())
Esempio n. 4
0
 def test_init(self):
     path = "/test"
     allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                               path,
                                               100,
                                               start_idx=0,
                                               reverse=False,
                                               alloc_list=None,
                                               max_alloc=0)
     session = self.Session()
     allocations = session.query(vnc_rdbms.IDPool).all()
     self.assertEqual(1, len(allocations))
Esempio n. 5
0
    def test_alloc_exhausted_reverse(self):
        path = "/test"
        allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                                  path,
                                                  2,
                                                  start_idx=0,
                                                  reverse=True)
        session = self.Session()
        allocator.alloc("alloc1")
        allocator.alloc("alloc2")
        with testtools.ExpectedException(ResourceExhaustionError) as e:
            allocator.alloc("alloc3")

        self.assertEqual(2, allocator.get_alloc_count())
Esempio n. 6
0
 def test_alloc_reverse(self):
     path = "/test"
     allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                               path,
                                               100,
                                               start_idx=0,
                                               reverse=True)
     session = self.Session()
     allocations = session.query(vnc_rdbms.IDPool).all()
     id1 = allocator.alloc("alloc1")
     self.assertEqual(99, id1)
     id2 = allocator.alloc("alloc2")
     self.assertEqual(98, id2)
     allocations = session.query(vnc_rdbms.IDPool).all()
     self.assertEqual(2, allocator.get_alloc_count())
Esempio n. 7
0
    def test_alloc(self):
        path = "/test"
        allocator = vnc_rdbms.RDBMSIndexAllocator(self.db,
                                                  path,
                                                  100,
                                                  start_idx=0)
        session = self.Session()
        allocations = session.query(vnc_rdbms.IDPool).all()
        id1 = allocator.alloc("alloc1")
        self.assertEqual(0, id1)
        id2 = allocator.alloc("alloc2")
        self.assertEqual(1, id2)

        self.assertEqual('alloc1', allocator.read(id1))

        allocations = session.query(vnc_rdbms.IDPool).all()
        self.assertEqual(2, allocator.get_alloc_count())
Esempio n. 8
0
    def test_init_with_overlap_allocation(self):
        path = "/test"

        with testtools.ExpectedException(Exception) as e:
            alloc_list = [{
                "start": 100,
                "end": 200
            }, {
                "start": 10,
                "end": 400
            }]
            vnc_rdbms.RDBMSIndexAllocator(self.db,
                                          path,
                                          100,
                                          start_idx=0,
                                          reverse=False,
                                          alloc_list=alloc_list,
                                          max_alloc=0)

        with testtools.ExpectedException(Exception) as e:
            alloc_list = [{
                "start": 10,
                "end": 400
            }, {
                "start": 100,
                "end": 200
            }]
            vnc_rdbms.RDBMSIndexAllocator(self.db,
                                          path,
                                          100,
                                          start_idx=0,
                                          reverse=False,
                                          alloc_list=alloc_list,
                                          max_alloc=0)

        with testtools.ExpectedException(Exception) as e:
            alloc_list = [{
                "start": 100,
                "end": 200
            }, {
                "start": 150,
                "end": 400
            }]
            vnc_rdbms.RDBMSIndexAllocator(self.db,
                                          path,
                                          100,
                                          start_idx=0,
                                          reverse=False,
                                          alloc_list=alloc_list,
                                          max_alloc=0)

        with testtools.ExpectedException(Exception) as e:
            alloc_list = [{
                "start": 150,
                "end": 400
            }, {
                "start": 100,
                "end": 200
            }]
            vnc_rdbms.RDBMSIndexAllocator(self.db,
                                          path,
                                          100,
                                          start_idx=0,
                                          reverse=False,
                                          alloc_list=alloc_list,
                                          max_alloc=0)

        with testtools.ExpectedException(Exception) as e:
            alloc_list = [{
                "start": 20000000,
                "end": 30000000
            }, {
                "start": 10000000,
                "end": 340282366920938463463374607431768211455
            }]
            vnc_rdbms.RDBMSIndexAllocator(self.db,
                                          path,
                                          100,
                                          start_idx=0,
                                          reverse=False,
                                          alloc_list=alloc_list,
                                          max_alloc=0)