Exemplo n.º 1
0
    def test_claim(self):
        workload_id = uuid.uuid4()

        t = Thread(42)
        self.assertEqual(0, len(t.get_workload_ids()))

        t.claim(workload_id)
        self.assertEqual(1, len(t.get_workload_ids()))
        self.assertEqual(workload_id, t.get_workload_ids()[0])

        t.clear()
        self.assertEqual(0, len(t.get_workload_ids()))
Exemplo n.º 2
0
    def test_clear_multiple_claims(self):
        workload_id_a = "a"
        workload_id_b = "b"
        t = Thread(42)

        t.claim(workload_id_a)
        t.claim(workload_id_b)
        self.assertTrue(t.is_claimed())
        self.assertEqual(2, len(t.get_workload_ids()))

        t.clear()
        self.assertFalse(t.is_claimed())
        self.assertEqual(0, len(t.get_workload_ids()))
Exemplo n.º 3
0
    def test_free_unknown(self):
        t = Thread(42)
        self.assertEqual(0, len(t.get_workload_ids()))
        self.assertFalse(t.is_claimed())

        t.free("unknown_id")
        self.assertEqual(0, len(t.get_workload_ids()))
        self.assertFalse(t.is_claimed())

        workload_id = "a"
        t.claim(workload_id)
        t.free("unknown_id")
        self.assertEqual(1, len(t.get_workload_ids()))
        self.assertEqual(workload_id, t.get_workload_ids()[0])
        self.assertTrue(t.is_claimed())
Exemplo n.º 4
0
def _is_thread_occupied(thread: Thread, workload_map: dict,
                        w_type: str) -> bool:
    for w_id in thread.get_workload_ids():
        if w_id in workload_map:
            if workload_map[w_id].get_type() == w_type:
                return True

    return False
Exemplo n.º 5
0
    def test_multiple_claims(self):
        workload_id_a = "a"
        workload_id_b = "b"
        t = Thread(42)

        t.claim(workload_id_a)
        self.assertEqual(1, len(t.get_workload_ids()))
        self.assertEqual(workload_id_a, t.get_workload_ids()[0])
        self.assertTrue(t.is_claimed())

        t.claim(workload_id_b)
        self.assertEqual(2, len(t.get_workload_ids()))
        self.assertTrue(workload_id_a in t.get_workload_ids())
        self.assertTrue(workload_id_b in t.get_workload_ids())
        self.assertTrue(t.is_claimed())

        t.free(workload_id_a)
        self.assertEqual(1, len(t.get_workload_ids()))
        self.assertEqual(workload_id_b, t.get_workload_ids()[0])
        self.assertTrue(t.is_claimed())

        t.free(workload_id_b)
        self.assertFalse(t.is_claimed())
        self.assertEqual(0, len(t.get_workload_ids()))
Exemplo n.º 6
0
def __get_workloads_str(t: Thread) -> str:
    return str(sorted([str(w_id) for w_id in t.get_workload_ids()]))