def test_Monitoring(self): B.testConfiguration() ns = "monitortest" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) self.assertEqual(B.getProgressInfo(target), None) backupWithMonitoring(self, self.source, target) info = B.getProgressInfo(target) self.assertTrue(type(info), dict) self.assertEqual(info["total_size"], info["seen"]) self.assertEqual(info["still_to_be_examined"], 0) self.assertTrue(info["sent_to_backend"] <= info["total_size"])
def test_Monitoring(self): B.testConfiguration() ns = "monitortest" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) self.assertEqual(B.getProgressInfo(target), None) backupWithMonitoring(self, self.source, target) info = B.getProgressInfo(target) self.assertTrue(type(info), dict) self.assertEqual(info["total_size"], info["seen"]) self.assertEqual(info["still_to_be_examined"], 0) self.assertTrue(info["sent_to_backend"] <= info["total_size"])
def backupWithMonitoring(self, source, target, *args, **kwargs): infoList = [] PITReplication.removeProgressInfo(target) backupThread = ThreadWithExn(target=PITReplication.backup, args=((source, target) + args), kwargs=kwargs) backupThread.start() progressInfo = None def check_progress(self, old, new, infoList): # check monotonicity self.assertTrue(old == None or new != None) if old != None: self.assertEqual(new["total_size"], old["total_size"]) self.assertTrue(new["seen"] >= old["seen"]) self.assertTrue(new["sent_to_backend"] >= old["sent_to_backend"]) if new != None: self.assertTrue(new["status"] in ["running", "finished"]) if old == None or new["seen"] > old["seen"]: infoList.append(new) previoustime = time.time() delta = 1.0 while backupThread.isAlive(): time.sleep(0.01) newtime = time.time() if newtime > previoustime + delta: previoustime = newtime newProgressInfo = PITReplication.getProgressInfo(target) check_progress(self, progressInfo, newProgressInfo, infoList) progressInfo = newProgressInfo backupThread.join_with_exception() newProgressInfo = PITReplication.getProgressInfo(target) check_progress(self, progressInfo, newProgressInfo, infoList) self.assertNotEqual( newProgressInfo, None, "no progressinfo found after backup has successfully finished") self.assertEqual(newProgressInfo["status"], "finished") self.assertTrue( len(infoList) >= 1, "internal test error in backupWithMonitoring") return infoList
def backupWithMonitoring(self, source, target, *args, **kwargs): infoList = [] PITReplication.removeProgressInfo(target) backupThread = ThreadWithExn(target=PITReplication.backup, args=((source, target) + args), kwargs=kwargs) backupThread.start() progressInfo = None def check_progress(self, old, new, infoList): # check monotonicity self.assertTrue(old == None or new != None) if old != None: self.assertEqual(new["total_size"], old["total_size"]) self.assertTrue(new["seen"] >= old["seen"]) self.assertTrue(new["sent_to_backend"] >= old["sent_to_backend"]) if new != None: self.assertTrue(new["status"] in ["running", "finished"]) if old == None or new["seen"] > old["seen"]: infoList.append(new) previoustime = time.time() delta = 1.0 while backupThread.isAlive(): time.sleep(0.01) newtime = time.time() if newtime > previoustime + delta: previoustime = newtime newProgressInfo = PITReplication.getProgressInfo(target) check_progress(self, progressInfo, newProgressInfo, infoList) progressInfo = newProgressInfo backupThread.join_with_exception() newProgressInfo = PITReplication.getProgressInfo(target) check_progress(self, progressInfo, newProgressInfo, infoList) self.assertNotEqual( newProgressInfo, None, "no progressinfo found after backup has successfully finished") self.assertEqual(newProgressInfo["status"], "finished") self.assertTrue(len(infoList) >= 1, "internal test error in backupWithMonitoring") return infoList