Esempio n. 1
0
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())
Esempio n. 2
0
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()
Esempio n. 3
0
    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)
Esempio n. 4
0
def cell(factory):
    cell = Cell(factory, Mock(), Mock(), Mock())
    cell.handle_system_message(Start)
    return cell
Esempio n. 5
0
def cell(actor, system, dispatcher, supervisor, mailbox):
    cell = Cell(lambda: actor, system, dispatcher, supervisor)
    cell._mailbox = mailbox
    cell.handle_system_message(Start)
    return cell
Esempio n. 6
0
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()
Esempio n. 7
0
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())
Esempio n. 8
0
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())
Esempio n. 9
0
def test_start_constructs_instance():
    factory = Mock()
    cell = Cell(factory, Mock(), Mock(), Mock())
    cell.handle_system_message(Start)
    factory.assert_called_once_with()
Esempio n. 10
0
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())
Esempio n. 11
0
def running_cell(actor, supervisor):
    cell = Cell(lambda: actor, Mock(), Mock(), supervisor)
    cell.handle_system_message(Start)
    return cell
Esempio n. 12
0
def cell(actor):
    cell = Cell(lambda: actor, Mock(), Mock(), Mock())
    cell.handle_system_message(Start)
    return cell
Esempio n. 13
0
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())
Esempio n. 14
0
def cell(actor, system, dispatcher, supervisor, mailbox):
    cell = Cell(lambda: actor, system, dispatcher, supervisor)
    cell._mailbox = mailbox
    cell.handle_system_message(Start)
    return cell
Esempio n. 15
0
def running_cell(actor, supervisor):
    cell = Cell(lambda: actor, Mock(), Mock(), supervisor)
    cell.handle_system_message(Start)
    return cell
Esempio n. 16
0
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()
Esempio n. 17
0
def test_start_constructs_instance():
    factory = Mock()
    cell = Cell(factory, Mock(), Mock(), Mock())
    cell.handle_system_message(Start)
    factory.assert_called_once_with()
Esempio n. 18
0
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())