示例#1
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel,
                               'on_open_callback',
                               channel_number=ch_number)
        if amq_chan is None:
            log.error(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s",
                ch_number)
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast(
                    "AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError(
                "AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s"
                % ch_number)

        transport = AMQPTransport(amq_chan)

        # return the pending in collection (lets this number be assigned again later)
        self.client._pending.remove(transport.channel_number)

        # by default, everything should have a prefetch count of 1 (configurable)
        # this can be overridden by the channel get_n related methods
        transport.qos_impl(prefetch_count=CFG.get_safe(
            'container.messaging.endpoint.prefetch_count', 1))

        return transport
示例#2
0
    def test__on_underlying_close_error(self, mocklog):
        tp = AMQPTransport(Mock())

        tp._on_underlying_close(404, sentinel.text)

        self.assertEquals(mocklog.error.call_count, 1)
        self.assertIn(sentinel.text, mocklog.error.call_args[0])
        self.assertEquals(mocklog.debug.call_count, 0)
示例#3
0
    def test__sync_call_with_kwarg_rets(self):
        def async_func(*args, **kwargs):
            cbparam = kwargs.get('callback')
            cbparam(sup=sentinel.val, sup2=sentinel.val2)

        tp = AMQPTransport(Mock())
        rv = tp._sync_call(async_func, 'callback')
        self.assertEquals(rv, {'sup': sentinel.val, 'sup2': sentinel.val2})
示例#4
0
    def test__sync_call_with_ret_value(self):
        def async_func(*args, **kwargs):
            cbparam = kwargs.get('callback')
            cbparam(sentinel.val)

        tp = AMQPTransport(Mock())
        rv = tp._sync_call(async_func, 'callback')
        self.assertEquals(rv, sentinel.val)
示例#5
0
    def test__sync_call_no_ret_value(self):
        def async_func(*args, **kwargs):
            cbparam = kwargs.get('callback')
            cbparam()

        tp = AMQPTransport(Mock())
        rv = tp._sync_call(async_func, 'callback')
        self.assertIsNone(rv)
示例#6
0
    def test_close_while_locked(self):
        tp = AMQPTransport(Mock())
        tp.lock = True

        tp.close()

        self.assertEquals(tp._client.close.call_count, 0)
        self.assertEquals(tp._client.callbacks.remove.call_count, 0)
示例#7
0
    def test__sync_call_with_error(self):
        tp = AMQPTransport(Mock())

        def async_func(*args, **kwargs):
            raise TransportError('haha')

        self.assertRaises(TransportError, tp._sync_call, async_func,
                          'callback')
示例#8
0
    def test__on_underlying_close(self, mocklog):
        tp = AMQPTransport(Mock())
        cb = Mock()
        tp.add_on_close_callback(cb)

        tp._on_underlying_close(200, sentinel.text)

        cb.assert_called_once_with(tp, 200, sentinel.text)
        self.assertEquals(mocklog.debug.call_count, 1)
        self.assertIn(sentinel.text, mocklog.debug.call_args[0])
示例#9
0
    def test_close_does_delete_if_anonymous_and_not_auto_delete(self):
        transport = AMQPTransport(Mock())
        ch = SubscriberChannel()
        ch.on_channel_open(transport)
        ch._queue_auto_delete = False
        ch._destroy_queue = Mock()
        ch._recv_name = NameTrio(sentinel.exchange, 'amq.gen-ABCD')

        ch.close_impl()
        ch._destroy_queue.assert_called_once_with()
示例#10
0
    def test__sync_call_with_close_indicating_error(self):
        tp = AMQPTransport(Mock())

        def async_func(*args, **kwargs):
            tp._client.add_on_close_callback.call_args[0][0](sentinel.ch,
                                                             sentinel.arg)

        self.assertRaises(TransportError, tp._sync_call, async_func,
                          'callback')
        tp._client.transport.connection.mark_bad_channel.assert_called_once_with(
            tp._client.channel_number)
示例#11
0
    def test_start_consume_with_consumer_tag_and_auto_delete(self, mocklog):
        transport = AMQPTransport(Mock())
        self.ch.on_channel_open(transport)
        self.ch._fsm.current_state = self.ch.S_ACTIVE

        # set up recv name for queue
        self.ch._recv_name = NameTrio(sentinel.xp, sentinel.queue)
        self.ch._consumer_tag = sentinel.consumer_tag
        self.ch._queue_auto_delete = True

        self.ch.start_consume()
        self.assertTrue(mocklog.warn.called)
示例#12
0
    def test_close(self):
        client = Mock()
        tp = AMQPTransport(client)
        tp.close()

        client.close.assert_called_once_with()

        self.assertEquals(client.callbacks.remove.call_count, 4)
        self.assertEquals(client.callbacks.remove.call_args_list, [
            call(client.channel_number, 'Basic.GetEmpty'),
            call(client.channel_number, 'Channel.Close'),
            call(client.channel_number, '_on_basic_deliver'),
            call(client.channel_number, '_on_basic_get')
        ])
示例#13
0
    def _new_transport(self, ch_number=None):
        """
        Creates a new AMQPTransport with an underlying Pika channel.
        """
        amq_chan = blocking_cb(self.client.channel, 'on_open_callback', channel_number=ch_number)
        if amq_chan is None:
            log.error("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s", ch_number)
            traceback.print_stack()
            from pyon.container.cc import Container
            if Container.instance is not None:
                Container.instance.fail_fast("AMQCHAN IS NONE, messaging has failed", True)
            raise StandardError("AMQCHAN IS NONE THIS SHOULD NEVER HAPPEN, chan number requested: %s" % ch_number)

        transport = AMQPTransport(amq_chan)
        return transport
示例#14
0
    def test__on_underlying_close(self):
        client = Mock()
        tp = AMQPTransport(client)
        cb = Mock()
        tp.add_on_close_callback(cb)

        tp._on_underlying_close(200, sentinel.text)

        cb.assert_called_once_with(tp, 200, sentinel.text)

        self.assertEquals(client.callbacks.remove.call_count, 4)
        self.assertEquals(client.callbacks.remove.call_args_list, [
            call(client.channel_number, 'Basic.GetEmpty'),
            call(client.channel_number, 'Channel.Close'),
            call(client.channel_number, '_on_basic_deliver'),
            call(client.channel_number, '_on_basic_get')
        ])
示例#15
0
    def test_stop_consume_raises_warning_with_auto_delete(self, mocklog):
        transport = AMQPTransport(Mock())
        transport.stop_consume_impl = Mock()
        self.ch.on_channel_open(transport)
        #transport.channel_number = sentinel.channel_number

        self.ch._consumer_tag = sentinel.consumer_tag
        self.ch._recv_name = NameTrio(sentinel.ex, sentinel.queue,
                                      sentinel.binding)
        self.ch._fsm.current_state = self.ch.S_ACTIVE
        self.ch._consuming = True

        #self.ch._ensure_transport = MagicMock()
        self.ch._queue_auto_delete = True

        self.ch.stop_consume()

        self.assertTrue(mocklog.debug.called)
        self.assertIn(sentinel.queue, mocklog.debug.call_args[0])
示例#16
0
    def test_add_on_close_callback(self):
        tp = AMQPTransport(Mock())
        tp.add_on_close_callback(sentinel.one)
        tp.add_on_close_callback(sentinel.two)

        self.assertEquals(tp._close_callbacks, [sentinel.one, sentinel.two])
示例#17
0
 def setUp(self):
     self.tp = AMQPTransport(MagicMock())
     self.tp._sync_call = Mock()
示例#18
0
 def test_channel_number(self):
     client = Mock()
     tp = AMQPTransport(client)
     self.assertEquals(tp.channel_number, client.channel_number)
示例#19
0
 def test_active(self):
     tp = AMQPTransport(Mock())
     tp._client.closing = None
     self.assertTrue(tp.active)
示例#20
0
    def test_close(self):
        client = Mock()
        tp = AMQPTransport(client)
        tp.close()

        client.close.assert_called_once_with()
示例#21
0
    def test_active_closing(self):
        tp = AMQPTransport(Mock())
        tp._client.closing = True

        self.assertFalse(tp.active)
示例#22
0
    def test_active_no_client(self):
        tp = AMQPTransport(Mock())
        tp._client = None

        self.assertFalse(tp.active)