Example #1
0
def test_proxy_constructor_raises_exception_if_actor_is_dead(actor_class):
    actor_ref = actor_class.start()
    actor_ref.stop()

    with pytest.raises(ActorDeadError) as exc_info:
        ActorProxy(actor_ref)

    assert str(exc_info.value) == '{} not found'.format(actor_ref)
Example #2
0
 def test_proxy_constructor_raises_exception_if_actor_is_dead(self):
     actor_ref = self.AnActor.start()
     actor_ref.stop()
     try:
         ActorProxy(actor_ref)
         self.fail('Should raise ActorDeadError')
     except ActorDeadError as exception:
         self.assertEqual('%s not found' % actor_ref, str(exception))
Example #3
0
    def proxy(self):
        """
        Wraps the :class:`ActorRef` in an :class:`ActorProxy
        <pykka.ActorProxy>`.

        Using this method like this::

            proxy = AnActor.start().proxy()

        is analogous to::

            proxy = ActorProxy(AnActor.start())

        :raise: :exc:`pykka.ActorDeadError` if actor is not available
        :return: :class:`pykka.ActorProxy`
        """
        return ActorProxy(self)
Example #4
0
 def done(self, poller: ActorProxy):
     """
     Recycles, or disposes of, a used poller
     """
     # stops the used poller
     poller.stop()
Example #5
0
def proxy(actor_class):
    proxy = ActorProxy(actor_class.start())
    yield proxy
    proxy.stop()
Example #6
0
 def setUp(self):
     self.proxy = ActorProxy(self.AnActor.start())
Example #7
0
class ProxyTest(object):
    def setUp(self):
        self.proxy = ActorProxy(self.AnActor.start())

    def tearDown(self):
        try:
            self.proxy.stop()
        except ActorDeadError:
            pass

    def test_repr_is_wrapped_in_lt_and_gt(self):
        result = repr(self.proxy)
        self.assertTrue(result.startswith('<'))
        self.assertTrue(result.endswith('>'))

    def test_repr_reveals_that_this_is_a_proxy(self):
        self.assertTrue('ActorProxy' in repr(self.proxy))

    def test_repr_contains_actor_class_name(self):
        self.assertTrue('AnActor' in repr(self.proxy))

    def test_repr_contains_actor_urn(self):
        self.assertTrue(self.proxy.actor_ref.actor_urn in repr(self.proxy))

    def test_repr_contains_attr_path(self):
        self.assertTrue('bar' in repr(self.proxy.bar))

    def test_str_contains_actor_class_name(self):
        self.assertTrue('AnActor' in str(self.proxy))

    def test_str_contains_actor_urn(self):
        self.assertTrue(self.proxy.actor_ref.actor_urn in str(self.proxy))

    def test_dir_on_proxy_lists_attributes_of_the_actor(self):
        result = dir(self.proxy)
        self.assertTrue('foo' in result)
        self.assertTrue('cat' in result)
        self.assertTrue('func' in result)

    def test_dir_on_proxy_lists_private_attributes_of_the_proxy(self):
        result = dir(self.proxy)
        self.assertTrue('__class__' in result)
        self.assertTrue('__dict__' in result)
        self.assertTrue('__getattr__' in result)
        self.assertTrue('__setattr__' in result)

    def test_refs_proxy_method_returns_a_proxy(self):
        proxy_from_ref_proxy = self.AnActor.start().proxy()
        self.assertTrue(isinstance(proxy_from_ref_proxy, ActorProxy))
        proxy_from_ref_proxy.stop().get()

    def test_proxy_constructor_raises_exception_if_actor_is_dead(self):
        actor_ref = self.AnActor.start()
        actor_ref.stop()
        try:
            ActorProxy(actor_ref)
            self.fail('Should raise ActorDeadError')
        except ActorDeadError as exception:
            self.assertEqual('%s not found' % actor_ref, str(exception))

    def test_actor_ref_may_be_retrieved_from_proxy_if_actor_is_dead(self):
        self.proxy.actor_ref.stop()
        self.assertFalse(self.proxy.actor_ref.is_alive())
Example #8
0
 def setUp(self):
     self.proxy = ActorProxy(self.AnActor.start())
Example #9
0
class ProxyTest(object):

    def setUp(self):
        self.proxy = ActorProxy(self.AnActor.start())

    def tearDown(self):
        try:
            self.proxy.stop()
        except ActorDeadError:
            pass

    def test_repr_is_wrapped_in_lt_and_gt(self):
        result = repr(self.proxy)
        self.assert_(result.startswith('<'))
        self.assert_(result.endswith('>'))

    def test_repr_reveals_that_this_is_a_proxy(self):
        self.assert_('ActorProxy' in repr(self.proxy))

    def test_repr_contains_actor_class_name(self):
        self.assert_('AnActor' in repr(self.proxy))

    def test_repr_contains_actor_urn(self):
        self.assert_(self.proxy.actor_ref.actor_urn in repr(self.proxy))

    def test_repr_contains_attr_path(self):
        self.assert_('bar' in repr(self.proxy.bar))

    def test_str_contains_actor_class_name(self):
        self.assert_('AnActor' in str(self.proxy))

    def test_str_contains_actor_urn(self):
        self.assert_(self.proxy.actor_ref.actor_urn in str(self.proxy))

    def test_dir_on_proxy_lists_attributes_of_the_actor(self):
        result = dir(self.proxy)
        self.assert_('foo' in result)
        self.assert_('cat' in result)
        self.assert_('func' in result)

    def test_dir_on_proxy_lists_private_attributes_of_the_proxy(self):
        result = dir(self.proxy)
        self.assert_('__class__' in result)
        self.assert_('__dict__' in result)
        self.assert_('__getattr__' in result)
        self.assert_('__setattr__' in result)

    def test_refs_proxy_method_returns_a_proxy(self):
        proxy_from_ref_proxy = self.AnActor.start().proxy()
        self.assert_(isinstance(proxy_from_ref_proxy, ActorProxy))
        proxy_from_ref_proxy.stop().get()

    def test_proxy_constructor_raises_exception_if_actor_is_dead(self):
        actor_ref = self.AnActor.start()
        actor_ref.stop()
        try:
            ActorProxy(actor_ref)
            self.fail('Should raise ActorDeadError')
        except ActorDeadError as exception:
            self.assertEqual('%s not found' % actor_ref, str(exception))

    def test_actor_ref_may_be_retrieved_from_proxy_if_actor_is_dead(self):
        self.proxy.actor_ref.stop()
        self.assertFalse(self.proxy.actor_ref.is_alive())
Example #10
0
def proxy(actor_class):
    proxy = ActorProxy(actor_class.start())
    yield proxy
    proxy.stop()