Ejemplo n.º 1
0
    def test_client_notifies_rejection_on_trigger(self):
        db = self.evaluate(
            DefineService("DB", DefineOperation("insert", Think(5)))).value
        storage = self.evaluate(
            DefineService("Storage",
                          DefineOperation("store", Trigger("DB",
                                                           "insert")))).value

        fake_task_pool = MagicMock(ThrottlingPolicyDecorator)
        fake_task_pool._accepts = MagicMock(return_value=False)
        db.tasks = ThrottlingWrapper(db.environment, task_pool=fake_task_pool)
        db.workers.busy_workers.extend(db.workers.idle_workers)
        db.workers.idle_workers = []

        listener = MagicMock(Listener)
        storage.environment.look_up(Symbols.LISTENER).register(listener)

        request = self.trigger("Storage", "store")
        self.simulate_until(10)

        expected_calls = [
            call.task_created(ANY),
            call.task_accepted(ANY),
            call.task_assigned_to(ANY, ANY),
            call.posting_of("DB", ANY),
            call.task_paused(ANY),
            call.rejection_of(ANY),
            call.task_activated(ANY),
            call.task_assigned_to(ANY, ANY),
            call.task_failed(ANY)
        ]

        self.assertEqual(request.status, RequestStatus.ERROR)
        self.assertTrue(listener.method_calls == expected_calls,
                        listener.method_calls)
Ejemplo n.º 2
0
    def test_notifies_arrival_and_failure(self):
        db = self.evaluate(
            DefineService("DB", DefineOperation("Select", Fail()))).value

        listener = MagicMock(Listener)
        db.environment.look_up(Symbols.LISTENER).register(listener)

        self.query("DB", "Select")
        self.simulate_until(10)

        expected_calls = [
            call.task_created(ANY),
            call.task_accepted(ANY),
            call.task_assigned_to(ANY, ANY),
            call.task_failed(ANY)
        ]

        self.assertEqual(expected_calls, listener.method_calls,
                         listener.method_calls)
Ejemplo n.º 3
0
    def test_client_notifies_rejection_on_trigger(self):
        db = self.evaluate(
            DefineService("DB",
                DefineOperation("insert",
                     Think(5)
                )
            )
        ).value
        storage = self.evaluate(
            DefineService("Storage",
                DefineOperation("store",
                     Trigger("DB", "insert")
                )
            )
        ).value

        fake_task_pool = MagicMock(ThrottlingPolicyDecorator)
        fake_task_pool._accepts = MagicMock(return_value=False)
        db.tasks = ThrottlingWrapper(db.environment, task_pool=fake_task_pool)
        db.workers.busy_workers.extend(db.workers.idle_workers)
        db.workers.idle_workers = []

        listener = MagicMock(Listener)
        storage.environment.look_up(Symbols.LISTENER).register(listener)

        request = self.trigger("Storage", "store")
        self.simulate_until(10)

        expected_calls = [
            call.task_created(ANY),
            call.task_accepted(ANY),
            call.task_assigned_to(ANY, ANY),
            call.posting_of("DB", ANY),
            call.task_paused(ANY),
            call.rejection_of(ANY),
            call.task_activated(ANY),
            call.task_assigned_to(ANY, ANY),
            call.task_failed(ANY)
        ]

        self.assertEqual(request.status, RequestStatus.ERROR)
        self.assertTrue(listener.method_calls == expected_calls, listener.method_calls)
Ejemplo n.º 4
0
    def test_notifies_arrival_and_failure(self):
        db = self.evaluate(
            DefineService("DB",
                DefineOperation("Select",
                     Fail()
                )
            )
        ).value

        listener = MagicMock(Listener)
        db.environment.look_up(Symbols.LISTENER).register(listener)

        self.query("DB", "Select")
        self.simulate_until(10)

        expected_calls = [
            call.task_created(ANY),
            call.task_accepted(ANY),
            call.task_assigned_to(ANY, ANY),
            call.task_failed(ANY)]

        self.assertEqual(expected_calls, listener.method_calls, listener.method_calls)