Пример #1
0
    def test_run_message_callback_error(self):
        t0 = self.doubler.n()
        t1 = self.doubler.n()
        t0.link(t1, 'run')
        t0.start(None)
        self.assertEqual(2, M.Message.m.find().count())

        m,s = M.Message.reserve('foo', ['chapman'])
        t = Task.from_state(s)
        t.handle(m)

        m,s = M.Message.reserve('foo', ['chapman'])
        t = Task.from_state(s)
        t.handle(m)

        with self.assertRaises(exc.TaskError):
            t.result.get()
Пример #2
0
    def test_run_message_callback(self):
        @Function.decorate('doubler_result')
        def doubler_result(result):
            return result.get() * 2
        t0 = self.doubler.new(ignore_result=True)
        t1 = doubler_result.n()
        t0.link(t1, 'run')
        t0.start(2)
        self.assertEqual(2, M.Message.m.find().count())

        m,s = M.Message.reserve('foo', ['chapman'])
        t = Task.from_state(s)
        t.handle(m)

        m,s = M.Message.reserve('foo', ['chapman'])
        t = Task.from_state(s)
        t.handle(m)
        self.assertEqual(t.result.get(), 8)
        self.assertEqual(M.Message.m.find().count(), 0)
        self.assertEqual(M.TaskState.m.find().count(), 1)
Пример #3
0
 def test_abstract_task(self):
     t = Task.new({})
     with self.assertRaises(NotImplementedError):
         t.run(None)
Пример #4
0
 def _handle_message(self, msg, state):
     print 'Handling %s' % msg
     print '... task is %s' % state.status
     task = Task.from_state(state)
     task.handle(msg)
Пример #5
0
 def _handle_message(self, msg, state):
     print 'Handling %s' % msg
     print '... task is %s' % state.status
     task = Task.from_state(state)
     task.handle(msg)