Пример #1
0
    def test2SingleCancelSecond(self):
        log.info("Single Multitask Cancel Second")
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        job1 = taskManager.Job(context=context, description="Job 1")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job 2")
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(initRevertTask())

        job2Id = job2.getId()
        dissomniag.taskManager.Dispatcher.addJob(user=None, job=job1)
        dissomniag.taskManager.Dispatcher.addJob(user=None, job=job2)
        dissomniag.taskManager.Dispatcher.cancelJob(user=None, jobId=job2Id)
        time.sleep(3)
        print(job1.getInfo())
        print(job2.getInfo())
        global counter, counterLock
        assert counter == 4
        with counterLock:
            counter = 0
Пример #2
0
    def test4AddConcurrent(self):
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        context.concurrentRunMethod = "sub"
        context.concurrentRunValue = 1
        context.concurrentRevertMethod = "add"
        context.concurrentRevertValue = 2

        job1 = taskManager.Job(context=context, description="Job A")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job B")
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        jobs = [job1, job2]
        taskManager.Dispatcher.addJobsConcurrent(user=None, jobs=jobs)
        time.sleep(5)
        print(job1.getInfo())
        print(job2.getInfo())
        global counter, counterLock
        print("#### COUNTER %d ####" % counter)
        assert counter == 0
        with counterLock:
            counter = 0
Пример #3
0
    def test4PreemptDispatcher(self):
        sync = synchronizator()

        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        job1 = taskManager.Job(context=context, description="Job 1")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(longRunningTask())

        job2 = taskManager.Job(context=context, description="Job 2")
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(initRevertTask())

        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job1)
        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job2)
Пример #4
0
    def test1Synchronized(self):
        sync = synchronizator()

        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        job1 = taskManager.Job(context=context, description="Job 1")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job 2")
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(initRevertTask())

        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job1)
        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job2)
        time.sleep(3)
        job1.getInfo()
        job2.getInfo()

        global counter, counterLock
        print "#### Counter: %d ####" % counter
        assert counter == 1
        with counterLock:
            counter = 0
Пример #5
0
    def test3CancelRunningTask(self):
        global counter, counterLock
        with counterLock:
            counter = 0
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        log.info("Cancel Running Task")
        job1 = taskManager.Job(context=context, description="Job 3")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(longRunningTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job1Id = job1.getId()
        dissomniag.taskManager.Dispatcher.addJob(user=None, job=job1)
        time.sleep(1)
        dissomniag.taskManager.Dispatcher.cancelJob(user=None, jobId=job1Id)
        time.sleep(5)
        print(job1.getInfo())

        print("#### COUNTER %d ####" % counter)
        if dissomniag.config.dispatcher.revertBeforeCancel:
            assert counter == -3
        else:
            assert counter == 3
        with counterLock:
            counter = 0
Пример #6
0
    def implementation(self, *args):
        sys.stdout = self.terminal
        sys.stderr = self.terminal

        if not self.user.isAdmin:
            self.printError(
                "You are not allowed to use this programm! Go away!")
            return

        parser = argparse.ArgumentParser(
            description='Add a dummy Job with a Time', prog=args[0])
        parser.add_argument("-t",
                            "--time",
                            action="store",
                            dest="time",
                            default=10)
        parser.add_argument("-z",
                            "--zombi",
                            action="store_true",
                            dest="zombi",
                            default=False)
        parser.add_argument("-i",
                            "--independent",
                            action="store_true",
                            dest="independent",
                            default=False)
        options = parser.parse_args(list(args[1:]))

        context = taskManager.Context()
        context.timeToSleep = int(options.time)
        if options.zombi:
            job = taskManager.Job(
                context=context,
                description="Just a dummy Job with a specific Time.")
        else:
            job = taskManager.Job(
                context=context,
                description="Just a dummy Job with a specific Time.",
                user=self.user)
        job.addTask(DummyTask())
        job.addTask(DummyTask())
        jobId = job.id
        if options.independent:
            taskManager.Dispatcher.addJobIndependent(user=self.user, job=job)
        else:
            taskManager.Dispatcher.addJob(user=self.user, job=job)
        self.printSuccess("Your job have the ID %d" % jobId)
Пример #7
0
    def test7GetJob(self):
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        context.concurrentRunMethod = "sub"
        context.concurrentRunValue = 1
        context.concurrentRevertMethod = "add"
        context.concurrentRevertValue = 2

        job1 = taskManager.Job(context=context, description="Job A")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job B")
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(longRunningConcurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        jobBId = job2.getId()
        taskManager.Dispatcher.addJob(user=None, job=job1)
        taskManager.Dispatcher.addJob(user=None, job=job2)
        time.sleep(1)
        taskMJobB = taskManager.Dispatcher.getJob(user=None, jobId=jobBId)
        print(job2.getInfo())
        print(taskMJobB.getInfo())
        assert job2 == taskMJobB
        time.sleep(5)
        taskMJobB = taskManager.Dispatcher.getJob(user=None, jobId=jobBId)
        print(job2.getInfo())
        print(taskMJobB.getInfo())
        assert job2 == taskMJobB
        print(job1.getInfo())
        print(job2.getInfo())
        global counter, counterLock
        print("#### COUNTER %d ####" % counter)
        with counterLock:
            counter = 0
Пример #8
0
 def testMultiTask(self):
     log.debug("TestingMultitask")
     context = taskManager.Context()
     context.counter = 0
     job8 = taskManager.Job(context=context, description="8 Test Job")
     job8.addTask(counterTask())
     job8.addTask(counterTask())
     job8.addTask(counterTask())
     dissomniag.taskManager.Dispatcher.addJob(user=None, job=job8)
     time.sleep(4)
     assert context.counter == 3
     print(job8.getInfo())
Пример #9
0
    def test6CancelConcurrentTaskRunning(self):
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        context.concurrentRunMethod = "sub"
        context.concurrentRunValue = 1
        context.concurrentRevertMethod = "add"
        context.concurrentRevertValue = 2

        job1 = taskManager.Job(context=context, description="Job A")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job B")
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(longRunningConcurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        jobs = [job1, job2]
        jobBId = job2.getId()
        taskManager.Dispatcher.addJobsConcurrent(user=None, jobs=jobs)
        time.sleep(1)
        taskManager.Dispatcher.cancelJob(user=None, jobId=jobBId)
        time.sleep(5)
        print(job1.getInfo())
        print(job2.getInfo())
        global counter, counterLock
        print("#### COUNTER %d ####" % counter)
        if dissomniag.config.dispatcher.revertBeforeCancel:
            assert counter == 8
        else:
            assert counter == 2
        with counterLock:
            counter = 0
Пример #10
0
    def test4GetSyncJobFromDispatcher(self):
        sync = synchronizator()

        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        job1 = taskManager.Job(context=context, description="Job 1")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(longRunningTask())

        job2 = taskManager.Job(context=context, description="Job 2")
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(counterTask())
        job2.addTask(initRevertTask())

        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job1)
        dissomniag.taskManager.Dispatcher.addJobSyncronized(user=None,
                                                            syncObj=sync,
                                                            job=job2)
        job1.getInfo()
        job2.getInfo()

        global counter, counterLock
        print "#### Counter: %d ####" % counter
        assert job2 == dissomniag.taskManager.Dispatcher.getJob(user=None,
                                                                jobId=job2.id)
        assert job1 == dissomniag.taskManager.Dispatcher.getJob(user=None,
                                                                jobId=job1.id)

        #time.sleep(10)
        with counterLock:
            counter = 0
Пример #11
0
    def test8CancelledAll(self):
        context = taskManager.Context()
        context.runMethod = "add"
        context.runValue = 1
        context.revertMethod = "sub"
        context.revertValue = 2
        context.concurrentRunMethod = "sub"
        context.concurrentRunValue = 1
        context.concurrentRevertMethod = "add"
        context.concurrentRevertValue = 2

        job1 = taskManager.Job(context=context, description="Job A")
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())
        job1.addTask(counterTask())

        job2 = taskManager.Job(context=context, description="Job B")
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(longRunningConcurrentTask())
        job2.addTask(concurrentTask())
        job2.addTask(concurrentTask())
        taskManager.Dispatcher.addJob(user=None, job=job1)
        taskManager.Dispatcher.addJob(user=None, job=job2)
        time.sleep(1)
        taskManager.Dispatcher.cleanUpDispatcher()
        time.sleep(5)
        print(job1.getInfo())
        print(job2.getInfo())
        global counter, counterLock
        print("#### COUNTER %d ####" % counter)
        assert counter > 0
        with counterLock:
            counter = 0
Пример #12
0
 def testAddMultiDispatcher(self):
     log.debug("TestingMultitask")
     mContext = taskManager.Context()
     mContext.counter = 0
     job9 = taskManager.Job(context=mContext, description="9 Test Job")
     job9.addTask(counterTask())
     job9.addTask(counterTask())
     job9.addTask(counterTask())
     job9.addTask(testTask2Failing())
     dissomniag.taskManager.Dispatcher.addJob(user=None, job=job9)
     time.sleep(4)
     assert mContext.counter == 0
     global counter, revert, context
     assert revert == True
     counter = 0
     context = None
     revert = False
     print(job9.getInfo())