コード例 #1
0
    def test_allocate_when_unavailable_must_raise(self):
        h = Host(0, "n")
        h._set_unavailable()
        with pytest.raises(RuntimeError) as excinfo:
            h._allocate("job")

        assert "unavailable" in str(excinfo.value)
コード例 #2
0
    def test_get_not_allocated_hosts(self):
        h1 = Host(0, "n")
        h2 = Host(1, "n")
        p = Platform([h1, h2])
        h1._allocate("j1")

        assert p.get_not_allocated_hosts() == [h2]
コード例 #3
0
 def test_allocate_multiple_jobs_when_not_shareable_must_raise(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1], allow_sharing=False)
     h._allocate("j1")
     with pytest.raises(RuntimeError) as excinfo:
         h._allocate("j2")
     assert "multiple jobs" in str(excinfo.value)
コード例 #4
0
 def test_release_when_multiple_jobs_must_remain_computing(self):
     h = Host(0, "n", allow_sharing=True)
     h._allocate("j1")
     h._allocate("j2")
     h._start_computing()
     h._release("j1")
     assert h.is_computing and h.state == HostState.COMPUTING
     assert h.jobs and len(h.jobs) == 1 and h.jobs[0] == "j2"
コード例 #5
0
 def test_start_computing_when_unavailable_must_raise(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1])
     h._allocate("job")
     h._set_unavailable()
     with pytest.raises(SystemError) as excinfo:
         h._start_computing()
     assert "Unavailable" in str(excinfo.value)
コード例 #6
0
 def test_allocate_multiple_jobs_valid(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1], allow_sharing=True)
     h._allocate("j1")
     h._allocate("j2")
     assert h.is_idle and h.jobs and len(h.jobs) == 2
     assert "j1" in h.jobs
     assert "j2" in h.jobs
コード例 #7
0
 def test_set_unavailable_must_return_to_last_state(self):
     h = Host(0, "n")
     h._allocate("job")
     h._start_computing()
     h._set_unavailable()
     assert h.is_unavailable and not h.is_computing
     h._set_available()
     assert h.is_computing and not h.is_unavailable
コード例 #8
0
 def test_switch_off_allocated_must_raise(self):
     p1 = PowerState(0, PowerStateType.SLEEP, 10, 10)
     p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     p3 = PowerState(2, PowerStateType.COMPUTATION, 1000, 10000)
     p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50)
     p5 = PowerState(4, PowerStateType.SWITCHING_ON, 25, 25)
     h = Host(0, "n", pstates=[p1, p3, p2, p4, p5])
     h._allocate("job")
     with pytest.raises(RuntimeError) as excinfo:
         h._switch_off()
     assert "idle and free " in str(excinfo.value)
コード例 #9
0
 def test_set_on_when_computing_must_raise(self):
     p1 = PowerState(0, PowerStateType.SLEEP, 10, 10)
     p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     p3 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50)
     p4 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75)
     h = Host(0, "n", pstates=[p1, p3, p2, p4])
     h._allocate("job")
     h._start_computing()
     with pytest.raises(SystemError) as excinfo:
         h._set_on()
     assert "switching on" in str(excinfo.value)
コード例 #10
0
    def test_set_computation_state_when_computing_valid(self):
        p1 = PowerState(0, PowerStateType.SLEEP, 10, 10)
        p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
        p3 = PowerState(2, PowerStateType.COMPUTATION, 15, 150)
        p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50)
        p5 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75)
        h = Host(0, "n", pstates=[p1, p3, p2, p4, p5])

        h._allocate("job")
        h._start_computing()
        h._set_computation_pstate(2)
        assert h.pstate == p3 and h.power == p3.watt_full
コード例 #11
0
    def test_switch_on_allocated_must_raise(self):
        p1 = PowerState(0, PowerStateType.SLEEP, 10, 10)
        p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
        p3 = PowerState(2, PowerStateType.SWITCHING_OFF, 50, 50)
        p4 = PowerState(3, PowerStateType.SWITCHING_ON, 75, 75)
        h = Host(0, "n", pstates=[p1, p3, p2, p4])

        h._allocate("job")

        with pytest.raises(RuntimeError) as excinfo:
            h._switch_on()
        assert "be sleeping" in str(excinfo.value)
コード例 #12
0
 def test_power_computing_state(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1])
     h._allocate("job")
     h._start_computing()
     assert h.power == 100 and h.is_computing
コード例 #13
0
 def test_release_valid(self):
     h = Host(0, "n")
     h._allocate("job")
     h._start_computing()
     h._release("job")
     assert h.is_idle and h.state == HostState.IDLE and not h.jobs
コード例 #14
0
 def test_start_computing_valid(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1])
     h._allocate("job")
     h._start_computing()
     assert h.is_computing and h.state == HostState.COMPUTING
コード例 #15
0
 def test_allocate_job_twice_must_not_raise(self):
     h = Host(0, "n", allow_sharing=True)
     h._allocate("j1")
     h._allocate("j1")
     assert h.jobs and len(h.jobs) == 1
コード例 #16
0
 def test_allocate_valid(self):
     p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100)
     h = Host(0, "n", pstates=[p1])
     h._allocate("job")
     assert h.is_idle and h.jobs and h.jobs[0] == "job"
コード例 #17
0
 def test_set_unavailable_when_already_allocated_must_not_raise(self):
     h = Host(0, "n")
     h._allocate("job")
     h._set_unavailable()
     assert h.is_unavailable and h.jobs