Beispiel #1
0
def test_should_stop_processing_when_reaching_throughput_limit(actor):
    mailbox = InternalMailbox(Mock(), actor, throughput=2)
    mailbox.enqueue(1)
    mailbox.enqueue(1)
    mailbox.enqueue(1)
    mailbox.process_messages()
    assert actor.handle_message.call_count == 2
Beispiel #2
0
def test_suspending_in_handler_interrupts_processing(actor):
    mailbox = InternalMailbox(Mock(), actor, throughput=5)
    actor.handle_message.side_effect = lambda *args: mailbox.suspend()
    mailbox.enqueue(Mock())
    mailbox.enqueue(Mock())
    mailbox.process_messages()
    assert actor.handle_message.call_count == 1
Beispiel #3
0
    def __init__(self, actor_factory, system, dispatcher, parent):
        self._actor_factory = actor_factory  # Creates actor instances
        self._actor = None
        self._system = system
        self._dispatcher = dispatcher
        self._mailbox = InternalMailbox(dispatcher, self,
                                        dispatcher.throughput)
        self._dispatcher.attach(self._mailbox)

        self._parent = parent
        self._children = []
        self._stopped = False
        self._self_ref = InternalRef(self)

        self._context = actors.context.ActorContext(system, self._self_ref)
        self._context.system = system

        # TODO: shouldn't expose the internal ref
        self._context.self_ref = self._self_ref
Beispiel #4
0
def mailbox(actor):
    return InternalMailbox(Mock(), actor)