def testCommitBulk(self): """ _testCommitBulk_ Exactly the same as testCommit, but using commitBulk() instead of commit() """ myThread = threading.currentThread() testJobGroupA = self.createLargerTestJobGroup(commitFlag=False) testJobGroupB = JobGroup(id=testJobGroupA.id) testJobGroupB.loadData() assert len(testJobGroupA.getJobs()) == 0, \ "ERROR: Original object commited too early" assert len(testJobGroupB.getJobs()) == 0, \ "ERROR: Loaded JobGroup has too many jobs" testJobGroupA.commitBulk() testJobGroupA.loadData() self.assertEqual(len(testJobGroupA.getJobs()), 102) testJobGroupC = JobGroup(id=testJobGroupA.id) testJobGroupC.loadData() self.assertEqual(len(testJobGroupC.getJobs()), 102) self.assertEqual(testJobGroupC.jobs[0].getFiles()[0]['lfn'], '/this/is/a/lfnC') self.assertEqual(testJobGroupC.jobs[1].getFiles()[0]['lfn'], '/this/is/a/lfnD') return
def testCommit(self): """ _testCommit_ Verify that jobs are not added to a job group until commit() is called on the JobGroup. Also verify that commit() correctly commits the jobs to the database. """ testJobGroupA = self.createTestJobGroup(commitFlag=False) testJobGroupB = JobGroup(id=testJobGroupA.id) testJobGroupB.loadData() assert len(testJobGroupA.getJobs()) == 0, \ "ERROR: Original object commited too early" assert len(testJobGroupB.getJobs()) == 0, \ "ERROR: Loaded JobGroup has too many jobs" testJobGroupA.commit() testJobGroupA.loadData() assert len(testJobGroupA.getJobs()) == 2, \ "ERROR: Original object did not commit jobs" testJobGroupC = JobGroup(id=testJobGroupA.id) testJobGroupC.loadData() assert len(testJobGroupC.getJobs()) == 2, \ "ERROR: Loaded object has too few jobs." return
def testLoadData(self): """ _testLoadData_ Test loading the JobGroup, it's meta data and any data associated with its output fileset and jobs from the database. """ testJobGroupA = self.createTestJobGroup() testJobGroupB = JobGroup(id=testJobGroupA.id) testJobGroupB.loadData() assert testJobGroupB.subscription["id"] == \ testJobGroupA.subscription["id"], \ "ERROR: Job group did not load subscription correctly" goldenJobs = testJobGroupA.getJobs(type="list") for job in testJobGroupB.getJobs(type="list"): assert job in goldenJobs, \ "ERROR: JobGroup loaded an unknown job: %s, %s" % (job, goldenJobs) goldenJobs.remove(job) assert len(goldenJobs) == 0, \ "ERROR: JobGroup didn't load all jobs" assert testJobGroupB.output.id == testJobGroupA.output.id, \ "ERROR: Output fileset didn't load properly" return
def testLoadData(self): """ _testLoadData_ Test loading the JobGroup, it's meta data and any data associated with its output fileset and jobs from the database. """ testJobGroupA = self.createTestJobGroup() testJobGroupB = JobGroup(id=testJobGroupA.id) testJobGroupB.loadData() self.assertEqual(testJobGroupB.subscription["id"], testJobGroupA.subscription["id"], "Job group did not load subscription correctly") # Build a tuple with important job information for each job group goldenJobs = [(job['id'], job['name'], sorted([inp_file['lfn'] for inp_file in job['input_files']])) for job in testJobGroupA.getJobs(type="list")] loadedJobs = [(job['id'], job['name'], sorted([inp_file['lfn'] for inp_file in job['input_files']])) for job in testJobGroupB.getJobs(type="list")] # Make sure each job from one group is in the other list for job in loadedJobs: self.assertIn(job, goldenJobs, "JobGroup loaded an unknown job: \n%s \nis not in \n%s" % (pretty(job), pretty(goldenJobs))) goldenJobs.remove(job) self.assertFalse(goldenJobs, "JobGroup didn't load all jobs") self.assertEqual(testJobGroupB.output.id, testJobGroupA.output.id, "Output fileset didn't load properly") return
def testCommitTransaction(self): """ _testCommitTransaction_ Create a JobGroup and then add some jobs to it. Begin a transaction and then call commit() on the JobGroup. Verify that the newly committed jobs can be loaded from the database. Rollback the transaction and then verify that the jobs that were committed before are no longer associated with the JobGroup. """ testJobGroupA = self.createTestJobGroup(commitFlag=False) testJobGroupB = JobGroup(id=testJobGroupA.id) testJobGroupB.loadData() assert len(testJobGroupA.getJobs()) == 0, \ "ERROR: Original object commited too early" assert len(testJobGroupB.getJobs()) == 0, \ "ERROR: Loaded JobGroup has too many jobs" myThread = threading.currentThread() myThread.transaction.begin() testJobGroupA.commit() assert len(testJobGroupA.getJobs()) == 2, \ "ERROR: Original object did not commit jobs" testJobGroupC = JobGroup(id=testJobGroupA.id) testJobGroupC.loadData() assert len(testJobGroupC.getJobs()) == 2, \ "ERROR: Loaded object has too few jobs." myThread.transaction.rollback() testJobGroupD = JobGroup(id=testJobGroupA.id) testJobGroupD.loadData() assert len(testJobGroupD.getJobs()) == 0, \ "ERROR: Loaded object has too many jobs." return