Exemplo n.º 1
0
    def test_get_task(self):
        tk = TaskHeaderKeeper(EnvironmentsManager(), 10)

        self.assertIsNone(tk.get_task())
        task_header = get_dict_task_header()
        task_header["task_id"] = "uvw"
        self.assertTrue(tk.add_task_header(task_header))
        self.assertIsNone(tk.get_task())
        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        task_header["task_id"] = "xyz"
        self.assertTrue(tk.add_task_header(task_header))
        th = tk.get_task()
        assert isinstance(th.task_owner, Node)
        self.assertEqual(task_header["task_id"], th.task_id)
        self.assertEqual(task_header["max_price"], th.max_price)
        self.assertEqual(task_header["node_name"], th.node_name)
        self.assertEqual(task_header["task_owner_port"], th.task_owner_port)
        self.assertEqual(task_header["task_owner_key_id"],
                         th.task_owner_key_id)
        self.assertEqual(task_header["environment"], th.environment)
        self.assertEqual(task_header["deadline"], th.deadline)
        self.assertEqual(task_header["subtask_timeout"], th.subtask_timeout)
        self.assertEqual(task_header["max_price"], th.max_price)
        self.assertEqual(task_header["task_id"], th.task_id)
Exemplo n.º 2
0
    def test_get_task(self):
        em = EnvironmentsManager()
        em.environments = {}
        em.support_statuses = {}

        tk = TaskHeaderKeeper(environments_manager=em,
                              node=p2p.Node(),
                              min_price=10)

        self.assertIsNone(tk.get_task())
        task_header = get_task_header("uvw")
        self.assertTrue(tk.add_task_header(task_header))
        self.assertIsNone(tk.get_task())
        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        task_header2 = get_task_header("xyz")
        self.assertTrue(tk.add_task_header(task_header2))
        th = tk.get_task()
        assert isinstance(th.task_owner, Node)
        self.assertEqual(task_header2.to_dict(), th.to_dict())