Exemplo n.º 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
Exemplo n.º 2
0
    def test_loop(self):

        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None

        l = Consumer(self.ready_queue, timer=self.timer)
        l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer, 10)

        l.loop(*l.loop_args())
        l.loop(*l.loop_args())
        self.assertTrue(l.task_consumer.consume.call_count)
        l.task_consumer.qos.assert_called_with(prefetch_count=10)
        l.task_consumer.qos = Mock()
        self.assertEqual(l.qos.value, 10)
        l.qos.decrement_eventually()
        self.assertEqual(l.qos.value, 9)
        l.qos.update()
        self.assertEqual(l.qos.value, 9)
        l.task_consumer.qos.assert_called_with(prefetch_count=9)
Exemplo n.º 3
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
Exemplo n.º 4
0
    def test_loop_when_socket_error(self):
        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None
                raise socket.error('foo')

        l = Consumer(self.ready_queue, timer=self.timer)
        l.namespace.state = RUN
        c = l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer.qos, 10)
        with self.assertRaises(socket.error):
            l.loop(*l.loop_args())

        l.namespace.state = CLOSE
        l.connection = c
        l.loop(*l.loop_args())
Exemplo n.º 5
0
    def test_loop_when_socket_error(self):

        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None
                raise socket.error('foo')

        l = Consumer(self.ready_queue, timer=self.timer)
        l.namespace.state = RUN
        c = l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer, 10)
        with self.assertRaises(socket.error):
            l.loop(*l.loop_args())

        l.namespace.state = CLOSE
        l.connection = c
        l.loop(*l.loop_args())
Exemplo n.º 6
0
    def test_loop(self):
        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None

        l = Consumer(self.ready_queue, timer=self.timer)
        l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer.qos, 10)

        l.loop(*l.loop_args())
        l.loop(*l.loop_args())
        self.assertTrue(l.task_consumer.consume.call_count)
        l.task_consumer.qos.assert_called_with(prefetch_count=10)
        self.assertEqual(l.qos.value, 10)
        l.qos.decrement_eventually()
        self.assertEqual(l.qos.value, 9)
        l.qos.update()
        self.assertEqual(l.qos.value, 9)
        l.task_consumer.qos.assert_called_with(prefetch_count=9)