本文整理汇总了Python中scheduler.Scheduler.setPcbToCPU方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.setPcbToCPU方法的具体用法?Python Scheduler.setPcbToCPU怎么用?Python Scheduler.setPcbToCPU使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scheduler.Scheduler
的用法示例。
在下文中一共展示了Scheduler.setPcbToCPU方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSchedulerPriorityRoundRobin
# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import setPcbToCPU [as 别名]
class TestSchedulerPriorityRoundRobin(unittest.TestCase):
def repeat(self, f, N):
for _ in itertools.repeat(None, N): f()
def setUp(self):
self.comparator = lambda pcb1, pcb2: pcb1.getPriority() > pcb2.getPriority() # the greater, the better
self.semaphore = Mock()
self.myCpu = Mock()
self.queue = OwnHeap(self.semaphore, self.comparator)
self.myScheduler = Scheduler(self.myCpu, self.queue, 1, self.semaphore) # Priority Round Robin
self.highPriorityPCB = PCB(1, 1, 5, 10)
self.higherPriorityPCB = PCB(1, 1, 5, 15)
self.lowPriorityPCB = PCB(2, 6, 5, 1)
self.queue.put(self.highPriorityPCB)
self.queue.put(self.higherPriorityPCB)
self.queue.put(self.lowPriorityPCB)
def test_when_the_cpu_is_free_then_the_scheduler_set_the_pcb_with_the_higher_priority(self):
self.myScheduler.setPcbToCPU()
verify(self.myCpu).setPCB(self.higherPriorityPCB)
def test_when_a_pcb_is_assingned_the_burst_is_assigned_too(self):
self.myScheduler.setPcbToCPU()
self.burstExpected = self.higherPriorityPCB.getBurst()
self.assertEqual(1, self.burstExpected)
def test_when_the_queue_is_empty_it_waits_until_it_is_refilled(self):
try:
self.repeat(self.myScheduler.setPcbToCPU, 3)
self.myScheduler.setPcbToCPU()
verify(self.semaphore).wait()
except Exception:
pass
else:
self.fail("unsexpected exception")