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)
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)
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)
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)
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)
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)
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)
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)
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)
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)