示例#1
0
 def setUp(self):
     self.cinder = MockCinder()
     self.scratch = mkdtemp()
     self.stats_path = os.path.join(self.scratch, 'stats')
     self.stat_queue = multiprocessing.Queue()
     with JsonLockFile(self.stats_path) as lock:
         self.stats_lock = lock
     self.backup_id = 'backup_id'
     self.block_count = 10
     self.process = StatsSaveProcess(self.cinder,
                                     self.backup_id,
                                     self.stat_queue,
                                     self.block_count,
                                     self.stats_lock,
                                     update_interval=1)
     self.process.start()
示例#2
0
文件: test_worker.py 项目: audip/lunr
 def setUp(self):
     self.cinder = MockCinder()
     self.scratch = mkdtemp()
     self.stats_path = os.path.join(self.scratch, 'stats')
     self.stat_queue = multiprocessing.Queue()
     with JsonLockFile(self.stats_path) as lock:
         self.stats_lock = lock
     self.backup_id = 'backup_id'
     self.block_count = 10
     self.process = StatsSaveProcess(
         self.cinder, self.backup_id, self.stat_queue,
         self.block_count, self.stats_lock, update_interval=1)
     self.process.start()
示例#3
0
文件: test_worker.py 项目: audip/lunr
class TestStatsSaveProcess(unittest.TestCase):
    def setUp(self):
        self.cinder = MockCinder()
        self.scratch = mkdtemp()
        self.stats_path = os.path.join(self.scratch, 'stats')
        self.stat_queue = multiprocessing.Queue()
        with JsonLockFile(self.stats_path) as lock:
            self.stats_lock = lock
        self.backup_id = 'backup_id'
        self.block_count = 10
        self.process = StatsSaveProcess(
            self.cinder, self.backup_id, self.stat_queue,
            self.block_count, self.stats_lock, update_interval=1)
        self.process.start()

    def tearDown(self):
        rmtree(self.scratch)
        self.assertFalse(self.process.is_alive())

    def test_read(self):
        blocks_read = 8
        for i in xrange(blocks_read):
            task = ('read', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], blocks_read)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], self.block_count)
            self.assertEqual(stats['blocks_uploaded'], 0)
            percent = (8 + 0) * 100.0 / (10 + 10)
            self.assertEqual(stats['progress'], percent)

    def test_uploaded(self):
        blocks_uploaded = 3
        for i in xrange(blocks_uploaded):
            task = ('uploaded', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], 0)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], self.block_count)
            self.assertEqual(stats['blocks_uploaded'], blocks_uploaded)
            percent = (0 + 3) * 100.0 / (10 + 10)
            self.assertEqual(stats['progress'], percent)

    def test_upload_count(self):
        upload_count = 7
        task = ('upload_count', upload_count)
        self.stat_queue.put(task)
        blocks_uploaded = 3
        for i in xrange(blocks_uploaded):
            task = ('uploaded', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], 0)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], upload_count)
            self.assertEqual(stats['blocks_uploaded'], 3)
            percent = (0 + 3) * 100.0 / (10 + 7)
            self.assertEqual(stats['progress'], percent)
示例#4
0
class TestStatsSaveProcess(unittest.TestCase):
    def setUp(self):
        self.cinder = MockCinder()
        self.scratch = mkdtemp()
        self.stats_path = os.path.join(self.scratch, 'stats')
        self.stat_queue = multiprocessing.Queue()
        with JsonLockFile(self.stats_path) as lock:
            self.stats_lock = lock
        self.backup_id = 'backup_id'
        self.block_count = 10
        self.process = StatsSaveProcess(self.cinder,
                                        self.backup_id,
                                        self.stat_queue,
                                        self.block_count,
                                        self.stats_lock,
                                        update_interval=1)
        self.process.start()

    def tearDown(self):
        rmtree(self.scratch)
        self.assertFalse(self.process.is_alive())

    def test_read(self):
        blocks_read = 8
        for i in xrange(blocks_read):
            task = ('read', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], blocks_read)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], self.block_count)
            self.assertEqual(stats['blocks_uploaded'], 0)
            percent = (8 + 0) * 100.0 / (10 + 10)
            self.assertEqual(stats['progress'], percent)

    def test_uploaded(self):
        blocks_uploaded = 3
        for i in xrange(blocks_uploaded):
            task = ('uploaded', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], 0)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], self.block_count)
            self.assertEqual(stats['blocks_uploaded'], blocks_uploaded)
            percent = (0 + 3) * 100.0 / (10 + 10)
            self.assertEqual(stats['progress'], percent)

    def test_upload_count(self):
        upload_count = 7
        task = ('upload_count', upload_count)
        self.stat_queue.put(task)
        blocks_uploaded = 3
        for i in xrange(blocks_uploaded):
            task = ('uploaded', 1)
            self.stat_queue.put(task)
        self.stat_queue.put(None)
        while self.process.is_alive():
            sleep(0.1)
        with open(self.stats_path) as f:
            stats = json.loads(f.read())
            self.assertEqual(stats['blocks_read'], 0)
            self.assertEqual(stats['block_count'], self.block_count)
            self.assertEqual(stats['upload_count'], upload_count)
            self.assertEqual(stats['blocks_uploaded'], 3)
            percent = (0 + 3) * 100.0 / (10 + 7)
            self.assertEqual(stats['progress'], percent)