Пример #1
0
    def test_init(self):
        ticket = uuid()
        actor = Mock()
        ares = AsyncResult(ticket, actor)

        self.assertEquals(ares.ticket, ticket)
        self.assertEqual(ares.actor, actor)
        self.assertIsNone(ares._result)
        self.assertEqual(ares.Error, CellError)
        self.assertEqual(ares.NoReplyError, NoReplyError)

        with self.assertRaises(TypeError):
            AsyncResult(ticket)
Пример #2
0
    def test_gather_kwargs(self, conn, collect):
        actor = Actor(conn)
        ares = AsyncResult(uuid(), actor)
        prev_to_python = ares.to_python
        new_to_python = lambda x, propagate = True: x
        ares.to_python = new_to_python

        # Test default kwargs,
        # nothing is passed, the actor does not have agent assigned
        self.assert_gather_kwargs(
            ares, collect, {},
            timeout=actor.default_timeout, ignore_timeout=False)

        # limit - set the default agent limit if NONE is set
        # Test default kwargs, nothing is passed,
        # the actor does have default agent assigned
        actor.agent = dAgent(conn)
        self.assert_gather_kwargs(
            ares, collect, {},
            timeout=actor.default_timeout, limit=None, ignore_timeout=False)

        # limit - set the default agent limit if NONE is set
        # Test default kwargs, nothing is passed,
        # the actor does have agent with custom scatter limit assigned
        ag = Ag(conn)
        actor.agent = ag
        self.assert_gather_kwargs(
            ares, collect, {}, timeout=actor.default_timeout,
            limit=ag.get_default_scatter_limit())

        # pass all args
        actor.agent = Ag(conn)
        timeout, ignore_timeout, limit = 200.0, False, uuid()

        self.assert_gather_kwargs(
            ares, collect,
            {'timeout': timeout, 'ignore_timeout': ignore_timeout,
             'limit': limit},
            timeout=timeout, limit=limit, ignore_timeout=ignore_timeout)

        # ig ignore_tiemout is passed,
        # the custom logic for limit is not applies
        actor.agent = None
        timeout, ignore_timeout = 200.0, True
        self.assert_gather_kwargs(
            ares, collect,
            {'timeout': timeout, 'ignore_timeout': ignore_timeout},
            timeout=timeout, ignore_timeout=ignore_timeout)

        ares.to_python = prev_to_python
Пример #3
0
    def test_gather(self, conn):
        def collect_replies():
            yield 1
            yield 2
            yield 3

        ticket = uuid()
        actor = Actor(conn)
        actor._collect_replies = Mock(return_value=collect_replies())

        ares = AsyncResult(ticket, actor)
        ares.to_python = Mock()

        all = ares.gather()
        list(all)

        actor._collect_replies.assert_caleld_once_with(conn, ANY, ticket)
        self.assertEqual(ares.to_python.call_count,
                         len(list(collect_replies())))

        # test that the to_python is applied to all results
        actor._collect_replies.reset_mock()
        actor._collect_replies = Mock(return_value=collect_replies())
        prev_to_python = ares.to_python
        new_to_python = lambda x, propagate = True: 'called_%s' % x
        ares.to_python = new_to_python

        all = ares.gather()
        vals = list(all)

        expected_vals = [new_to_python(i) for i in collect_replies()]

        actor._collect_replies.assert_caleld_once_with(conn, ANY, ticket)
        self.assertEqual(vals, expected_vals)
        ares.to_python = prev_to_python
Пример #4
0
 def __getitem__(self, to_role):
     print("In._get_from_conv_table")
     self._wf_table.setdefault(to_role, AsyncResult())
     if isinstance(self._wf_table[to_role], AsyncResult):
         # @TODO. Need timeout for the AsyncResult
         print("Wait on the Async Result")
         to_role_addr = self._wf_table[to_role].get()
         print("get the Async Result, value is:%s" % to_role_addr)
         self._wf_table[to_role] = to_role_addr
     return self._wf_table[to_role]
Пример #5
0
 def get_async_result(self):
     ticket = uuid()
     actor = Mock()
     ares = AsyncResult(ticket, actor)
     return ares