Beispiel #1
0
 def LoopConsumer(self, buffer=None, controller=None, timer=None, app=None,
                  without_mingle=True, without_gossip=True,
                  without_heartbeat=True, **kwargs):
     if controller is None:
         controller = Mock(name='.controller')
     buffer = buffer if buffer is not None else self.buffer.put
     timer = timer if timer is not None else self.timer
     app = app if app is not None else self.app
     c = Consumer(
         buffer,
         timer=timer,
         app=app,
         controller=controller,
         without_mingle=without_mingle,
         without_gossip=without_gossip,
         without_heartbeat=without_heartbeat,
         **kwargs
     )
     c.task_consumer = Mock(name='.task_consumer')
     c.qos = QoS(c.task_consumer.qos, 10)
     c.connection = Mock(name='.connection')
     c.controller = c.app.WorkController()
     c.heart = Mock(name='.heart')
     c.controller.consumer = c
     c.pool = c.controller.pool = Mock(name='.controller.pool')
     c.node = Mock(name='.node')
     c.event_dispatcher = mock_event_dispatcher()
     return c
Beispiel #2
0
 def LoopConsumer(self, buffer=None, controller=None, timer=None, app=None,
                  without_mingle=True, without_gossip=True,
                  without_heartbeat=True, **kwargs):
     if controller is None:
         controller = Mock(name='.controller')
     buffer = buffer if buffer is not None else self.buffer.put
     timer = timer if timer is not None else self.timer
     app = app if app is not None else self.app
     c = Consumer(
         buffer,
         timer=timer,
         app=app,
         controller=controller,
         without_mingle=without_mingle,
         without_gossip=without_gossip,
         without_heartbeat=without_heartbeat,
         **kwargs
     )
     c.task_consumer = Mock(name='.task_consumer')
     c.qos = QoS(c.task_consumer.qos, 10)
     c.connection = Mock(name='.connection')
     c.controller = c.app.WorkController()
     c.heart = Mock(name='.heart')
     c.controller.consumer = c
     c.pool = c.controller.pool = Mock(name='.controller.pool')
     c.node = Mock(name='.node')
     c.event_dispatcher = mock_event_dispatcher()
     return c
Beispiel #3
0
 def test_on_task_no_events(self):
     l = Consumer(self.ready_queue, timer=self.timer)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
Beispiel #4
0
 def test_on_task_no_events(self):
     l = MainConsumer(self.ready_queue, self.eta_schedule, send_events=False)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
Beispiel #5
0
 def test_on_task_no_events(self):
     l = Consumer(self.ready_queue, timer=self.timer)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
Beispiel #6
0
 def test_on_task_no_events(self):
     l = MainConsumer(self.ready_queue,
                      self.eta_schedule,
                      send_events=False)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
Beispiel #7
0
    def test_receieve_message_ack_raises(self, logger, warn):
        l = Consumer(self.ready_queue, timer=self.timer)
        backend = Mock()
        m = create_message(backend, args=[2, 4, 8], kwargs={})

        l.event_dispatcher = Mock()
        l.connection_errors = (socket.error, )
        m.reject = Mock()
        m.reject.side_effect = socket.error('foo')
        callback = self._get_on_message(l)
        self.assertFalse(callback(m.decode(), m))
        self.assertTrue(warn.call_count)
        with self.assertRaises(Empty):
            self.ready_queue.get_nowait()
        self.assertTrue(self.timer.empty())
        m.reject.assert_called_with()
        self.assertTrue(logger.critical.call_count)
Beispiel #8
0
    def test_receieve_message_ack_raises(self, logger, warn):
        l = Consumer(self.ready_queue, timer=self.timer)
        backend = Mock()
        m = create_message(backend, args=[2, 4, 8], kwargs={})

        l.event_dispatcher = Mock()
        l.connection_errors = (socket.error, )
        m.reject = Mock()
        m.reject.side_effect = socket.error('foo')
        callback = self._get_on_message(l)
        self.assertFalse(callback(m.decode(), m))
        self.assertTrue(warn.call_count)
        with self.assertRaises(Empty):
            self.ready_queue.get_nowait()
        self.assertTrue(self.timer.empty())
        m.reject.assert_called_with()
        self.assertTrue(logger.critical.call_count)