当前位置: 首页>>代码示例>>Python>>正文


Python TestDisk.size方法代码示例

本文整理汇总了Python中ovs.dal.hybrids.t_testdisk.TestDisk.size方法的典型用法代码示例。如果您正苦于以下问题:Python TestDisk.size方法的具体用法?Python TestDisk.size怎么用?Python TestDisk.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ovs.dal.hybrids.t_testdisk.TestDisk的用法示例。


在下文中一共展示了TestDisk.size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ownrelations

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_ownrelations(self):
     """
     Validates whether relations to the object itself are working
     """
     pdisk = TestDisk()
     pdisk.name = 'parent'
     pdisk.save()
     cdisk1 = TestDisk()
     cdisk1.name = 'child 1'
     cdisk1.size = 100
     cdisk1.parent = pdisk
     cdisk1.save()
     cdisk2 = TestDisk()
     cdisk2.name = 'child 2'
     cdisk2.size = 100
     cdisk2.parent = pdisk
     cdisk2.save()
     self.assertEqual(len(pdisk.children), 2, 'There should be 2 children ({0})'.format(len(pdisk.children)))
     self.assertEqual(cdisk1.parent.name, 'parent', 'Parent should be loaded correctly')
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': [('parent.name', DataList.operator.EQUALS, 'parent')]}}).data
     datalist = DataObjectList(data, TestDisk)
     self.assertEqual(len(datalist), 2, 'There should be two items ({0})'.format(len(datalist)))
     cdisk2.parent = None
     cdisk2.save()
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': [('parent.name', DataList.operator.EQUALS, 'parent')]}}).data
     datalist = DataObjectList(data, TestDisk)
     self.assertEqual(len(datalist), 1, 'There should be one item ({0})'.format(len(datalist)))
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:35,代码来源:test_basic.py

示例2: test_dol_advanced

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_dol_advanced(self):
     """
     Validates the DataObjectList advanced functions (indexer, sort)
     """
     sizes = [7, 2, 0, 4, 6, 1, 5, 9, 3, 8]
     guids = []
     for i in xrange(0, 10):
         disk = TestDisk()
         disk.name = 'disk_{0}'.format(i)
         disk.size = sizes[i]
         disk.save()
         guids.append(disk.guid)
     data = DataList({'object': TestDisk,
                      'data': DataList.select.GUIDS,
                      'query': {'type': DataList.where_operator.AND,
                                'items': []}}).data
     disks = DataObjectList(data, TestDisk)
     disks.sort()
     guids.sort()
     self.assertEqual(disks[0].guid, guids[0], 'Disks should be sorted on guid')
     self.assertEqual(disks[4].guid, guids[4], 'Disks should be sorted on guid')
     disks.sort(cmp=lambda a, b: a.size - b.size)
     self.assertEqual(disks[0].size, 0, 'Disks should be sorted on size')
     self.assertEqual(disks[4].size, 4, 'Disks should be sorted on size')
     disks.sort(key=lambda a: a.name)
     self.assertEqual(disks[0].name, 'disk_0', 'Disks should be sorted on name')
     self.assertEqual(disks[4].name, 'disk_4', 'Disks should be sorted on name')
     filtered = disks[1:4]
     self.assertEqual(filtered[0].name, 'disk_1', 'Disks should be properly sliced')
     self.assertEqual(filtered[2].name, 'disk_3', 'Disks should be properly sliced')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:32,代码来源:test_basic.py

示例3: test_copy

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_copy(self):
     """
     Validates whether the copy function works correct
     """
     machine = TestMachine()
     machine.name = 'testmachine1'
     machine.save()
     disk1 = TestDisk()
     disk1.name = 'test1'
     disk1.size = 100
     disk1.order = 1
     disk1.type = 'ONE'
     disk1.machine = machine
     disk1.save()
     disk2 = TestDisk()
     disk2.copy(disk1)
     self.assertEqual(disk2.name, 'test1', 'Properties should be copied')
     self.assertEqual(disk2.size, 100, 'Properties should be copied')
     self.assertEqual(disk2.order, 1, 'Properties should be copied')
     self.assertEqual(disk2.type, 'ONE', 'Properties should be copied')
     self.assertEqual(disk2.machine, None, 'Relations should not be copied')
     disk3 = TestDisk()
     disk3.copy(disk1, include_relations=True)
     self.assertEqual(disk3.machine.name, 'testmachine1', 'Relations should be copied')
     disk4 = TestDisk()
     disk4.copy(disk1, include=['name'])
     self.assertEqual(disk4.name, 'test1', 'Name should be copied')
     self.assertEqual(disk4.size, 0, 'Size should not be copied')
     self.assertEqual(disk4.machine, None, 'Relations should not be copied')
     disk5 = TestDisk()
     disk5.copy(disk1, exclude=['name'])
     self.assertEqual(disk5.name, None, 'Name should not be copied')
     self.assertEqual(disk5.size, 100, 'Size should be copied')
     self.assertEqual(disk5.machine, None, 'Relations should not be copied')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:36,代码来源:test_basic.py

示例4: test_recursive

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_recursive(self):
     """
     Validates the recursive save
     """
     machine = TestMachine()
     machine.name = 'original'
     machine.save()
     disks = []
     for i in xrange(0, 10):
         disk = TestDisk()
         disk.name = 'test_{0}'.format(i)
         if i % 2:
             disk.machine = machine
         else:
             disk.machine = machine
             self.assertEqual(disk.machine.name, 'original', 'child should be set')
             disk.machine = None
             self.assertIsNone(disk.machine, 'child should be cleared')
             disks.append(disk)
         disk.save()
     counter = 1
     for disk in machine.disks:
         disk.size = counter
         counter += 1
     machine.save(recursive=True)
     disk = TestDisk(machine.disks[0].guid)
     self.assertEqual(disk.size, 1, 'lists should be saved recursively')
     disk.machine.name = 'mtest'
     disk.save(recursive=True)
     machine2 = TestMachine(machine.guid)
     self.assertEqual(machine2.disks[1].size, 2, 'lists should be saved recursively')
     self.assertEqual(machine2.name, 'mtest', 'properties should be saved recursively')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:34,代码来源:test_basic.py

示例5: test_invalidpropertyassignment

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_invalidpropertyassignment(self):
     """
     Validates whether the correct exception is raised when properties are assigned with a wrong
     type
     """
     disk = TestDisk()
     disk.size = 100
     with self.assertRaises(TypeError):
         disk.machine = TestDisk()
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:11,代码来源:test_basic.py

示例6: test_querydynamic

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_querydynamic(self):
     """
     Validates whether a query that queried dynamic properties is never cached
     """
     def get_disks():
         return DataList({'object': TestDisk,
                          'data': DataList.select.GUIDS,
                          'query': {'type': DataList.where_operator.AND,
                                    'items': [('used_size', DataList.operator.NOT_EQUALS, -1)]}})
     disk1 = TestDisk()
     disk1.name = 'disk 1'
     disk1.size = 100
     disk1.save()
     disk2 = TestDisk()
     disk2.name = 'disk 2'
     disk2.size = 100
     disk2.save()
     query_result = get_disks()
     self.assertEqual(len(query_result.data), 2, 'There should be 2 disks ({0})'.format(len(query_result.data)))
     self.assertFalse(query_result.from_cache, 'Disk should not be loaded from cache')
     query_result = get_disks()
     self.assertFalse(query_result.from_cache, 'Disk should not be loaded from cache')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:24,代码来源:test_basic.py

示例7: test_volatileproperty

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_volatileproperty(self):
     """
     Validates the volatile behavior of dynamic properties
     """
     disk = TestDisk()
     disk.size = 1000000
     value = disk.used_size
     # Volatile properties should be stored for the correct amount of time
     time.sleep(2)
     self.assertEqual(disk.used_size, value, 'Value should still be from cache')
     time.sleep(2)
     self.assertEqual(disk.used_size, value, 'Value should still be from cache')
     time.sleep(2)
     # ... after which they should be reloaded from the backend
     self.assertNotEqual(disk.used_size, value, 'Value should be different')
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:17,代码来源:test_basic.py

示例8: test_typesafety

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_typesafety(self):
     """
     Validates typesafety checking on object properties
     """
     disk = TestDisk()
     disk.name = 'test'
     disk.name = u'test'
     disk.name = None
     disk.size = 100
     disk.size = 100.5
     disk.order = 100
     with self.assertRaises(TypeError):
         disk.order = 100.5
     with self.assertRaises(TypeError):
         disk.__dict__['wrong_type_data'] = None
         disk.wrong_type_data = 'string'
         _ = disk.wrong_type
     with self.assertRaises(TypeError):
         disk.type = 'THREE'
     disk.type = 'ONE'
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:22,代码来源:test_basic.py

示例9: test_lotsofobjects

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
    def test_lotsofobjects(self):
        """
        A test creating, linking and querying a lot of objects
        """
        print ''
        print 'cleaning up'
        self._clean_all()
        print 'start test'
        tstart = time.time()
        if getattr(LotsOfObjects, 'amount_of_machines', None) is None:
            LotsOfObjects.amount_of_machines = 50
        if getattr(LotsOfObjects, 'amount_of_disks', None) is None:
            LotsOfObjects.amount_of_disks = 5
        load_data = True
        mguids = []
        if load_data:
            print '\nstart loading data'
            start = time.time()
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine()
                machine.name = 'machine_{0}'.format(i)
                machine.save()
                mguids.append(machine.guid)
                for ii in xrange(0, int(LotsOfObjects.amount_of_disks)):
                    disk = TestDisk()
                    disk.name = 'disk_{0}_{1}'.format(i, ii)
                    disk.size = ii * 100
                    disk.machine = machine
                    disk.save()
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                LotsOfObjects._print_progress('* machine {0}/{1} (run: {2} dps, avg: {3} dps)'.format(i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)))
            runtimes.sort()
            print '\nloading done ({0}s). min: {1} dps, max: {2} dps'.format(round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2))

        test_queries = True
        if test_queries:
            print '\nstart queries'
            start = time.time()
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine(mguids[i])
                assert len(machine.disks) == LotsOfObjects.amount_of_disks, 'Not all disks were retrieved ({0})'.format(len(machine.disks))
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                LotsOfObjects._print_progress('* machine {0}/{1} (run: {2} dps, avg: {3} dps)'.format(i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)))
            runtimes.sort()
            print '\ncompleted ({0}s). min: {1} dps, max: {2} dps'.format(round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2))

            print '\nstart full query on disk property'
            start = time.time()
            dlist = DataList(TestDisk, {'type': DataList.where_operator.AND,
                                        'items': [('size', DataList.operator.GT, 100),
                                                  ('size', DataList.operator.LT, (LotsOfObjects.amount_of_disks - 1) * 100)]})
            amount = len(dlist)
            assert amount == (LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines, 'Incorrect amount of disks. Found {0} instead of {1}'.format(amount, int((LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines))
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

            print '\nloading disks (all)'
            start = time.time()
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                machine = TestMachine(mguids[i])
                _ = [_ for _ in machine.disks]
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

            print '\nstart full query on disk property (using cached objects)'
            dlist._volatile.delete(dlist._key)
            start = time.time()
            dlist = DataList(TestDisk, {'type': DataList.where_operator.AND,
                                        'items': [('size', DataList.operator.GT, 100),
                                                  ('size', DataList.operator.LT, (LotsOfObjects.amount_of_disks - 1) * 100)]})
            amount = len(dlist)
            assert amount == (LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines, 'Incorrect amount of disks. Found {0} instead of {1}'.format(amount, int((LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines))
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

            print '\nstart property sort'
            dlist = DataList(TestDisk, {'type': DataList.where_operator.AND,
                                        'items': []})
            start = time.time()
            dlist.sort(key=lambda a: Toolbox.extract_key(a, 'size'))
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

            print '\nstart dynamic sort'
            dlist._volatile.delete(dlist._key)
            dlist = DataList(TestDisk, {'type': DataList.where_operator.AND,
                                        'items': []})
            start = time.time()
            dlist.sort(key=lambda a: Toolbox.extract_key(a, 'predictable'))
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

#.........这里部分代码省略.........
开发者ID:grimpy,项目名称:openvstorage,代码行数:103,代码来源:performance_test.py

示例10: test_queries

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
 def test_queries(self):
     """
     Validates whether executing queries returns the expected results
     """
     machine = TestMachine()
     machine.name = 'machine'
     machine.save()
     for i in xrange(0, 20):
         disk = TestDisk()
         disk.name = 'test_{0}'.format(i)
         disk.size = i
         if i < 10:
             disk.machine = machine
         else:
             disk.storage = machine
         disk.save()
     self.assertEqual(len(machine.disks), 10, 'query should find added machines')
     # pylint: disable=line-too-long
     list_1 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('size', DataList.operator.EQUALS, 1)]}}).data  # noqa
     self.assertEqual(list_1, 1, 'list should contain int 1')
     list_2 = DataList({'object': TestDisk,
                        'data': DataList.select.GUIDS,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('size', DataList.operator.EQUALS, 1)]}}).data  # noqa
     found_object = Descriptor(TestDisk, list_2[0]).get_object(True)
     self.assertEqual(found_object.name, 'test_1', 'list should contain correct machine')
     list_3 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('size', DataList.operator.GT, 3),
                                            ('size', DataList.operator.LT, 6)]}}).data  # noqa
     self.assertEqual(list_3, 2, 'list should contain int 2')  # disk 4 and 5
     list_4 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.OR,
                                  'items': [('size', DataList.operator.LT, 3),
                                            ('size', DataList.operator.GT, 6)]}}).data  # noqa
     # at least disk 0, 1, 2, 7, 8, 9, 10-19
     self.assertGreaterEqual(list_4, 16, 'list should contain >= 16')
     list_5 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('machine.guid', DataList.operator.EQUALS, machine.guid),  # noqa
                                            {'type': DataList.where_operator.OR,
                                             'items': [('size', DataList.operator.LT, 3),
                                                       ('size', DataList.operator.GT, 6)]}]}}).data  # noqa
     self.assertEqual(list_5, 6, 'list should contain int 6')  # disk 0, 1, 2, 7, 8, 9
     list_6 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('size', DataList.operator.LT, 3),
                                            ('size', DataList.operator.GT, 6)]}}).data  # noqa
     self.assertEqual(list_6, 0, 'list should contain int 0')  # no disks
     list_7 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.OR,
                                  'items': [('machine.guid', DataList.operator.EQUALS, '123'),  # noqa
                                            ('used_size', DataList.operator.EQUALS, -1),
                                            {'type': DataList.where_operator.AND,
                                             'items': [('size', DataList.operator.GT, 3),
                                                       ('size', DataList.operator.LT, 6)]}]}}).data  # noqa
     self.assertEqual(list_7, 2, 'list should contain int 2')  # disk 4 and 5
     list_8 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('machine.name', DataList.operator.EQUALS, 'machine'),  # noqa
                                            ('name', DataList.operator.EQUALS, 'test_3')]}}).data  # noqa
     self.assertEqual(list_8, 1, 'list should contain int 1')  # disk 3
     list_9 = DataList({'object': TestDisk,
                        'data': DataList.select.COUNT,
                        'query': {'type': DataList.where_operator.AND,
                                  'items': [('size', DataList.operator.GT, 3),
                                            {'type': DataList.where_operator.AND,
                                             'items': [('size', DataList.operator.LT, 6)]}]}}).data  # noqa
     self.assertEqual(list_9, 2, 'list should contain int 2')  # disk 4 and 5
     list_10 = DataList({'object': TestDisk,
                         'data': DataList.select.COUNT,
                         'query': {'type': DataList.where_operator.OR,
                                   'items': [('size', DataList.operator.LT, 3),
                                             {'type': DataList.where_operator.OR,
                                              'items': [('size', DataList.operator.GT, 6)]}]}}).data  # noqa
     # at least disk 0, 1, 2, 7, 8, 9, 10-19
     self.assertGreaterEqual(list_10, 16, 'list should contain >= 16')
     list_11 = DataList({'object': TestDisk,
                         'data': DataList.select.COUNT,
                         'query': {'type': DataList.where_operator.AND,
                                   'items': [('storage.name', DataList.operator.EQUALS, 'machine')]}}).data  # noqa
     self.assertEqual(list_11, 10, 'list should contain int 10')  # disk 10-19
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:93,代码来源:test_basic.py

示例11: test_lotsofobjects

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
    def test_lotsofobjects(self):
        """
        A test creating, linking and querying a lot of objects
        """
        print ''
        print 'cleaning up'
        self._clean_all()
        print 'start test'
        tstart = time.time()
        if getattr(LotsOfObjects, 'amount_of_machines', None) is None:
            LotsOfObjects.amount_of_machines = 50
        if getattr(LotsOfObjects, 'amount_of_disks', None) is None:
            LotsOfObjects.amount_of_disks = 5
        load_data = True
        if load_data:
            print 'start loading data'
            start = time.time()
            mguids = []
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine()
                machine.name = 'machine_{0}'.format(i)
                machine.save()
                mguids.append(machine.guid)
                for ii in xrange(0, int(LotsOfObjects.amount_of_disks)):
                    disk = TestDisk()
                    disk.name = 'disk_{0}_{1}'.format(i, ii)
                    disk.size = ii * 100
                    disk.machine = machine
                    disk.save()
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                self._print_progress('* machine {0}/{1} (run: {2} dps, avg: {3} dps)'.format(i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)))
            runtimes.sort()
            print '\nloading done ({0}s). min: {1} dps, max: {2} dps'.format(round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2))

        test_queries = True
        if test_queries:
            print 'start queries'
            start = time.time()
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine(mguids[i])
                self.assertEqual(len(machine.disks), LotsOfObjects.amount_of_disks, 'Not all disks were retreived ({0})'.format(len(machine.disks)))
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                self._print_progress('* machine {0}/{1} (run: {2} dps, avg: {3} dps)'.format(i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)))
            runtimes.sort()
            print '\ncompleted ({0}s). min: {1} dps, max: {2} dps'.format(round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2))

            print 'start full query on disk property'
            start = time.time()
            amount = DataList({'object': TestDisk,
                               'data': DataList.select.COUNT,
                               'query': {'type': DataList.where_operator.AND,
                                         'items': [('size', DataList.operator.GT, 100),
                                                   ('size', DataList.operator.LT, (LotsOfObjects.amount_of_disks - 1) * 100)]}}).data
            self.assertEqual(amount, (LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines, 'Incorrect amount of disks. Found {0} instead of {1}'.format(amount, int((LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines)))
            seconds_passed = (time.time() - start)
            print 'completed ({0}s) in {1} seconds (avg: {2} dps)'.format(round(time.time() - tstart, 2), round(seconds_passed, 2), round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2))

        clean_data = True
        if clean_data:
            print 'cleaning up'
            start = time.time()
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine(mguids[i])
                for disk in machine.disks:
                    disk.delete()
                machine.delete()
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                self._print_progress('* machine {0}/{1} (run: {2} dps, avg: {3} dps)'.format(i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)))
            runtimes.sort()
            print '\ncompleted ({0}s). min: {1} dps, max: {2} dps'.format(round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2))
开发者ID:JasperLue,项目名称:openvstorage,代码行数:84,代码来源:test_performance.py

示例12: test_lotsofobjects

# 需要导入模块: from ovs.dal.hybrids.t_testdisk import TestDisk [as 别名]
# 或者: from ovs.dal.hybrids.t_testdisk.TestDisk import size [as 别名]
    def test_lotsofobjects(self):
        """
        A test creating, linking and querying a lot of objects
        """
        print ""
        print "cleaning up"
        self._clean_all()
        print "start test"
        tstart = time.time()
        if getattr(LotsOfObjects, "amount_of_machines", None) is None:
            LotsOfObjects.amount_of_machines = 50
        if getattr(LotsOfObjects, "amount_of_disks", None) is None:
            LotsOfObjects.amount_of_disks = 5
        load_data = True
        if load_data:
            print "start loading data"
            start = time.time()
            mguids = []
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine()
                machine.name = "machine_{0}".format(i)
                machine.save()
                mguids.append(machine.guid)
                for ii in xrange(0, int(LotsOfObjects.amount_of_disks)):
                    disk = TestDisk()
                    disk.name = "disk_{0}_{1}".format(i, ii)
                    disk.size = ii * 100
                    disk.machine = machine
                    disk.save()
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                self._print_progress(
                    "* machine {0}/{1} (run: {2} dps, avg: {3} dps)".format(
                        i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)
                    )
                )
            runtimes.sort()
            print "\nloading done ({0}s). min: {1} dps, max: {2} dps".format(
                round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2)
            )

        test_queries = True
        if test_queries:
            print "start queries"
            start = time.time()
            runtimes = []
            for i in xrange(0, int(LotsOfObjects.amount_of_machines)):
                mstart = time.time()
                machine = TestMachine(mguids[i])
                self.assertEqual(
                    len(machine.disks),
                    LotsOfObjects.amount_of_disks,
                    "Not all disks were retreived ({0})".format(len(machine.disks)),
                )
                avgitemspersec = ((i + 1) * LotsOfObjects.amount_of_disks) / (time.time() - start)
                itemspersec = LotsOfObjects.amount_of_disks / (time.time() - mstart)
                runtimes.append(itemspersec)
                self._print_progress(
                    "* machine {0}/{1} (run: {2} dps, avg: {3} dps)".format(
                        i + 1, int(LotsOfObjects.amount_of_machines), round(itemspersec, 2), round(avgitemspersec, 2)
                    )
                )
            runtimes.sort()
            print "\ncompleted ({0}s). min: {1} dps, max: {2} dps".format(
                round(time.time() - tstart, 2), round(runtimes[1], 2), round(runtimes[-2], 2)
            )

            print "start full query on disk property"
            start = time.time()
            amount = DataList(
                {
                    "object": TestDisk,
                    "data": DataList.select.COUNT,
                    "query": {
                        "type": DataList.where_operator.AND,
                        "items": [
                            ("size", DataList.operator.GT, 100),
                            ("size", DataList.operator.LT, (LotsOfObjects.amount_of_disks - 1) * 100),
                        ],
                    },
                }
            ).data
            self.assertEqual(
                amount,
                (LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines,
                "Incorrect amount of disks. Found {0} instead of {1}".format(
                    amount, int((LotsOfObjects.amount_of_disks - 3) * LotsOfObjects.amount_of_machines)
                ),
            )
            seconds_passed = time.time() - start
            print "completed ({0}s) in {1} seconds (avg: {2} dps)".format(
                round(time.time() - tstart, 2),
                round(seconds_passed, 2),
                round(LotsOfObjects.amount_of_machines * LotsOfObjects.amount_of_disks / seconds_passed, 2),
            )

        clean_data = True
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:103,代码来源:test_performance.py


注:本文中的ovs.dal.hybrids.t_testdisk.TestDisk.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。