Пример #1
0
    def post(self, strategy, quantum=4, ts=10):
        #import pdb; pdb.set_trace()

        # parse process syntax
        args = self.parser.parse_args()
        processDescription = args.get("syntax")
        init_p = args.get("initial_process")
        # trying to parse the syntax
        parseSyntax(processDescription)

        # here comes the critical section: creating the Scheduler environmet including Singletons.
        try:
            # generate scheduler
            scheduler = SchedulerFactory.getScheduler(str(strategy),
                                                      quantum=quantum,
                                                      timeslice=ts)
            # run scheduler
            scheduler.initialize(init_p)
            scheduler.run()
            # generate JSON
            json_result = JsonSerializer().generateData()
        except Exception as e:
            # pass the exceptions to the api - it will translate it to json-requests
            raise e
        finally:
            # we make sure that even after an exception, all Singletons get destroyed.
            ProcessManager._drop()
            SystemTimer._drop()

        return json_result, 200
Пример #2
0
    def test_work_in_append_queue(self):
        """
        after a schedule step is done, we decrease the wait time on every waiting section
        """
        p = PCB(Process("P"), state=State.L)
        p.process.workplan = Workplan().work(10).wait(20)
        p.process.doWork() # get rid of the work section
        self.queue.append(p)

        #and now tick
        st = SystemTimer(timeunit=10)
        st.tick() # tick will trigger a process.work() on every waiting process
        #p.process.work(10)
        for p in self.queue:
            # 10 waits should be left...
            self.assertEqual(p.process.workplan.pop().duration, 10)
Пример #3
0
    def test_notify(self):
        p = PCB(Process("Res_notify"), state=State.L)
        print ProcessManager().jobs

        p.process.workplan = Workplan().work(20).wait(15).work(25)
        p.process.doWork(20) # get rid of work section
        p.setWaiting()

        #wait(15) in queue
        self.queue.append(p)

        st = SystemTimer(timeunit=10)
        st.tick() #wait(5) left
        self.assertListEqual(self.queue.pickup_ready_processes(), [])
        st.tick() #should tick 5
        # process should be in queue
        ready_p_from_queue = self.queue.pickup_ready_processes()
        self.assertListEqual(ready_p_from_queue, [p])
Пример #4
0
 def tearDown(self):
     ProcessManager._drop()
     SystemTimer._drop()
Пример #5
0
 def tearDown(self):
     # cleanup process manager instances
     ProcessManager._drop()
     SystemTimer._drop()
Пример #6
0
 def tearDown(self):
     #clean all processes
     ProcessManager._drop()
     SystemTimer._drop()
Пример #7
0
 def tearDown(self):
     SystemTimer._drop()
     ProcessManager._drop()
Пример #8
0
 def tearDown(self):
     # because the timer class is implemented as Singleton, we have weird side effects
     # while unittesting. So we need un-register every listener after a run.
     self.stimer.unregisterAll()
     # ...hmm.. just to make sure, drop the SystemTimer instance
     SystemTimer._drop()
Пример #9
0
 def test_register_listener_01(self):
     res1, res2 = Foobar(), Foobar()
     stimer = SystemTimer()
     stimer.tick()
Пример #10
0
 def setUp(self):
     self.stimer = SystemTimer()
     self.stimer.timecounter = 0
     self.stimer.timeunit = 10
Пример #11
0
class TimerCase(unittest.TestCase):
    def setUp(self):
        self.stimer = SystemTimer()
        self.stimer.timecounter = 0
        self.stimer.timeunit = 10

    def test_createTimer(self):
        self.assertIsInstance(self.stimer, SystemTimer)

    # @unittest.skip('weird problem with the singleton...')
    def test_timerTick_01(self):
        # weird... it seems that unittest is not invalidating old TimerInstances.
        for i in range(5):
            self.stimer.tick()
        self.assertEqual(self.stimer.timecounter, 50)

    def test_register_listener_01(self):
        res1, res2 = Foobar(), Foobar()
        stimer = SystemTimer()
        stimer.tick()

    def test_singletonType_01(self):
        t1 = SystemTimer()
        t2 = SystemTimer()
        self.assertIs(t1, t2)

    def test_singletonType_02(self):
        t1 = SystemTimer()
        t2 = SystemTimer()
        print "SystemTimer Object is", id(t1)
        self.assertEqual(id(t1), id(t2))

    def test_setAbsoluteTime(self):
        timeunit = self.stimer.timeunit
        self.stimer.tick()
        self.stimer.setAbsoluteTime(timeunit * 2)
        self.assertEqual(self.stimer.timecounter, timeunit * 2)

    def test_next_tick_in(self):
        timeunit = self.stimer.timeunit  # usually, the next step is in 10 ms
        self.stimer.next_tick_in(3)  # but now, the next step is in 3ms
        self.stimer.tick()  # do a tick
        self.assertEqual(self.stimer.timecounter, 3)

    def tearDown(self):
        # because the timer class is implemented as Singleton, we have weird side effects
        # while unittesting. So we need un-register every listener after a run.
        self.stimer.unregisterAll()
        # ...hmm.. just to make sure, drop the SystemTimer instance
        SystemTimer._drop()
Пример #12
0
 def __init__(self):
     st = SystemTimer()
     st.register(self)  # register