def testJobReadWriteAndDelete(self): jobDir = os.path.join(os.getcwd(), "testJobDir") os.mkdir(jobDir) #If directory already exists then the test will fail command = "by your command" memory = 2^32 cpu = 1 tryCount = 100 for i in xrange(10): startTime = time.time() for j in xrange(100): j = Job(command, memory, cpu, tryCount, jobDir) self.assertEquals(j.remainingRetryCount, tryCount) self.assertEquals(j.jobDir, jobDir) self.assertEquals(j.children, []) self.assertEquals(j.followOnCommands, [ (command, memory, cpu, 0)]) self.assertEquals(j.messages, []) j.write() j = Job.read(j.getJobFileName()) self.assertEquals(j.remainingRetryCount, tryCount) self.assertEquals(j.jobDir, jobDir) self.assertEquals(j.children, []) self.assertEquals(j.followOnCommands, [ (command, memory, cpu, 0)]) self.assertEquals(j.messages, []) self.assertTrue(os.path.exists(j.getJobFileName())) j.delete() self.assertTrue(not os.path.exists(j.getJobFileName())) print "It took %f seconds to load/unload jobs" % (time.time() - startTime) #We've just used it for benchmarking, so far #Would be good to extend this trivial test system("rm -rf %s" % jobDir)
def createFirstJob(command, config, memory=None, cpu=None, time=sys.maxint): """Adds the first job to to the jobtree. """ logger.info("Adding the first job") if memory == None or memory == sys.maxint: memory = float(config.attrib["default_memory"]) if cpu == None or cpu == sys.maxint: cpu = float(config.attrib["default_cpu"]) job = Job(command=command, memory=memory, cpu=cpu, tryCount=int(config.attrib["try_count"]), jobDir=getJobFileDirName(config.attrib["job_tree"])) job.write() logger.info("Added the first job")