예제 #1
0
    def test_server_notifies_rejection(self):
        db = self.evaluate(
            DefineService("DB", DefineOperation("Select", Think(5)))).value

        fake_task_pool = MagicMock(ThrottlingPolicyDecorator)
        fake_task_pool._accepts = MagicMock(return_value=False)
        db.tasks = ThrottlingWrapper(db.environment, task_pool=fake_task_pool)

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

        request1 = self.query("DB", "Select")
        request2 = 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_created(ANY),
            call.task_rejected(ANY),
            call.task_successful(ANY)
        ]

        self.assertEqual(expected_calls, listener.method_calls,
                         listener.method_calls)
예제 #2
0
파일: test_events.py 프로젝트: fchauvel/MAD
    def test_task_status_notification(self):
        db = self.evaluate(
            DefineService("DB",
                DefineOperation("Select",
                     Think(5)
                )
            )
        ).value

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

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

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

        self.assertEqual(expected_calls, listener.method_calls, listener.method_calls)
예제 #3
0
    def test_task_status_notification(self):
        db = self.evaluate(
            DefineService("DB", DefineOperation("Select", Think(5)))).value

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

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

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

        self.assertEqual(expected_calls, listener.method_calls,
                         listener.method_calls)
예제 #4
0
파일: test_events.py 프로젝트: fchauvel/MAD
    def test_server_notifies_rejection(self):
        db = self.evaluate(
            DefineService("DB",
                DefineOperation("Select",
                     Think(5)
                )
            )
        ).value

        fake_task_pool = MagicMock(ThrottlingPolicyDecorator)
        fake_task_pool._accepts = MagicMock(return_value=False)
        db.tasks = ThrottlingWrapper(db.environment, task_pool=fake_task_pool)

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

        request1 = self.query("DB", "Select")
        request2 = 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_created(ANY),
            call.task_rejected(ANY),
            call.task_successful(ANY)]

        self.assertEqual(expected_calls, listener.method_calls, listener.method_calls)
예제 #5
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)
예제 #6
0
    def test_notifies_when_request_timeout(self):
        db = self.evaluate(
            DefineService("DB", DefineOperation("Select", Fail()))).value

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

        request = self.query("DB", "Select")
        request.reply_error()
        self.simulate_until(40)

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

        self.assertEqual(expected_calls, listener.method_calls,
                         listener.method_calls)
예제 #7
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)
예제 #8
0
파일: test_events.py 프로젝트: fchauvel/MAD
    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)
예제 #9
0
파일: test_events.py 프로젝트: fchauvel/MAD
    def test_notifies_when_request_timeout(self):
        db = self.evaluate(
            DefineService("DB",
                DefineOperation("Select",
                     Fail()
                )
            )
        ).value

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

        request = self.query("DB", "Select")
        request.reply_error()
        self.simulate_until(40)

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

        self.assertEqual(expected_calls, listener.method_calls, listener.method_calls)
예제 #10
0
파일: test_events.py 프로젝트: fchauvel/MAD
    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)