def test_failure_in_start_hook_should_send_failure_to_supervisor( actor, supervisor): actor.pre_start.side_effect = AttributeError() cell = Cell(lambda: actor, Mock(), Mock(), supervisor) cell.handle_system_message(Start) actor.pre_start.assert_called_once_with() _check_sent_failure_message(ActorRef(cell), supervisor, ActorInitializationError())
def test_restart_calls_pre_restart_on_old_and_post_on_new(): actor1 = Mock(spec_set=Actor) actor2 = Mock(spec_set=Actor) it = iter([actor1, actor2]) cell = Cell(lambda: next(it), Mock(), Mock(), Mock()) cell.handle_system_message(Start) cell.handle_system_message(Restart) actor1.pre_restart.assert_called_once_with() actor2.post_restart.assert_called_once_with()
def actor_of(self, cls=None, behaviour=None, dispatcher=None): if cls: factory = cls elif behaviour: factory = _actor_from_behaviour(behaviour) else: raise ValueError() if dispatcher is None: dispatcher = self._system._system_dispatcher from actors.internal.cell import Cell cell = Cell(factory, dispatcher=dispatcher, system=self._system, parent=self._supervisor) internal_ref = InternalRef(cell) self._supervisor.send_system_message(Supervise(internal_ref)) internal_ref.send_system_message(Start) return ActorRef(cell)
def cell(factory): cell = Cell(factory, Mock(), Mock(), Mock()) cell.handle_system_message(Start) return cell
def cell(actor, system, dispatcher, supervisor, mailbox): cell = Cell(lambda: actor, system, dispatcher, supervisor) cell._mailbox = mailbox cell.handle_system_message(Start) return cell
def test_start_calls_start_hook(actor): cell = Cell(lambda: actor, Mock(), Mock(), Mock()) cell.handle_system_message(Start) actor.pre_start.assert_called_once_with()
def test_failure_in_start_hook_should_send_failure_to_supervisor(actor, supervisor): actor.pre_start.side_effect = AttributeError() cell = Cell(lambda: actor, Mock(), Mock(), supervisor) cell.handle_system_message(Start) actor.pre_start.assert_called_once_with() _check_sent_failure_message(ActorRef(cell), supervisor, ActorInitializationError())
def test_handle_message_should_raise_if_actor_not_created(actor): cell = Cell(lambda: actor, Mock(), Mock(), Mock()) with pytest.raises(Exception): cell.handle_message(Mock())
def test_start_constructs_instance(): factory = Mock() cell = Cell(factory, Mock(), Mock(), Mock()) cell.handle_system_message(Start) factory.assert_called_once_with()
def test_sends_failure_if_factory_does_not_return_an_actor(supervisor): cell = Cell(lambda: object(), Mock(), Mock(), supervisor) cell.handle_system_message(Start) _check_sent_failure_message(ActorRef(cell), supervisor, ActorInitializationError())
def running_cell(actor, supervisor): cell = Cell(lambda: actor, Mock(), Mock(), supervisor) cell.handle_system_message(Start) return cell
def cell(actor): cell = Cell(lambda: actor, Mock(), Mock(), Mock()) cell.handle_system_message(Start) return cell