def install(application, **kwargs):
    """Call this to install avro publishing for the Tornado application."""
    amqp.install(application, **kwargs)

    if 'avro_schema_uri_format' not in application.settings:
        LOGGER.warning('avro_schema_uri_format is not set, using default')

    setattr(application, 'avro', {})
    return True
示例#2
0
    def should_raise_attribute_error_when_timeout_eq_reconnect_delay_test(
            self):
        with self.assertRaises(AttributeError) as context:
            amqp.install(web.Application(),
                         url=AMQP_URL,
                         timeout=5,
                         reconnect_delay=5)

            self.assertTrue('Reconnection must be less than timeout' == str(
                context.exception))
def install(application, io_loop=None, **kwargs):  # pragma: nocover
    """Call this to install Avro publishing for the Tornado application.

    :rtype: bool

    """
    amqp.install(application, io_loop=io_loop, **kwargs)
    if 'avro_schema_uri_format' not in application.settings:
        LOGGER.warning('avro_schema_uri_format is not set, using default')
    return True
示例#4
0
 def setUp(self):
     super(AsyncHTTPTestCase, self).setUp()
     self.correlation_id = str(uuid.uuid4())
     self.exchange = str(uuid.uuid4())
     self.get_delivered_message = concurrent.Future()
     self.get_returned_message = concurrent.Future()
     self.queue = str(uuid.uuid4())
     self.routing_key = str(uuid.uuid4())
     self.ready = locks.Event()
     amqp.install(self._app, self.io_loop, **{
         'on_ready_callback': self.on_amqp_ready,
         'enable_confirmations': self.CONFIRMATIONS,
         'on_return_callback': self.on_message_returned,
         'url': 'amqp://*****:*****@127.0.0.1:5672/%2f'})
     self.io_loop.start()
示例#5
0
 def install(self, **kwargs):
     with mock.patch('sprockets.mixins.amqp.Client.connect') as conn:
         conn.return_value = self.connection
         result = amqp.install(self._app, io_loop=self.io_loop, **kwargs)
         conn.assert_called_once()
         self.client = self._app.amqp
         self.client.connection = self.connection
         self.client.channel = self.channel
         self.client.state = amqp.Client.STATE_READY
     return result
示例#6
0
 def install(self, **kwargs):
     with mock.patch('sprockets.mixins.amqp.Client.connect') as conn:
         conn.return_value = self.connection
         result = amqp.install(self._app, io_loop=self.io_loop, **kwargs)
         conn.assert_called_once()
         self.client = self._app.amqp
         self.client.connection = self.connection
         self.client.channel = self.channel
         self.client.state = amqp.Client.STATE_READY
     return result
示例#7
0
    def setUp(self):
        super(BaseTestCase, self).setUp()

        # make sure that our logging statements get executed
        amqp.amqp.LOGGER.enabled = True
        amqp.amqp.LOGGER.setLevel(logging.DEBUG)
        amqp.mixins.LOGGER.enabled = True
        amqp.mixins.LOGGER.setLevel(logging.DEBUG)

        self.exchange = str(uuid.uuid4())
        self.queue = str(uuid.uuid4())
        self.routing_key = str(uuid.uuid4())
        self.correlation_id = str(uuid.uuid4())
        self.message = None
        self.test_queue_bound = locks.Event()
        self.get_response = locks.Event()
        self.amqp_ready = locks.Event()
        self.condition = locks.Condition()
        self.config = {
            "url": AMQP_URL,
            "reconnect_delay": 1,
            "timeout": 2,
            "on_ready_callback": self.on_ready,
            "on_unavailable_callback": self.on_unavailable,
            "on_persistent_failure_callback": self.on_persistent_failure,
            "on_message_returned_callback": self.on_message_returned,
            "io_loop": self.io_loop,
        }
        self.app = web.Application()
        self.app.settings = {'service': 'unit_tests', 'version': '0.0'}
        self.handler = TestRequestHandler(self.app)

        self.clear_event_tracking()

        amqp.install(self.app, **self.config)
        yield self.condition.wait(self.io_loop.time() + 5)

        LOGGER.info('Connected to RabbitMQ, declaring exchange %s',
                    self.exchange)
        self.app.amqp.channel.exchange_declare(self.on_exchange_declare_ok,
                                               self.exchange,
                                               auto_delete=True)
示例#8
0
    def should_override_settings_with_env_var_settings_test(self):
        amqp_env_vars = {
            'AMQP_URL': 'amqp://*****:*****@127.0.0.1:5672/%2f',
            'AMQP_TIMEOUT': '15',
            'AMQP_RECONNECT_DELAY': '7',
            'AMQP_CONNECTION_ATTEMPTS': '2',
        }
        app = web.Application()
        with mock.patch.dict('os.environ', amqp_env_vars):
            amqp.install(app,
                         url=AMQP_URL,
                         timeout=8,
                         reconnect_delay=5,
                         connection_attempts=3)

            self.assertEqual(app.amqp._url, amqp_env_vars['AMQP_URL'])
            self.assertEqual(app.amqp._timeout,
                             int(amqp_env_vars['AMQP_TIMEOUT']))
            self.assertEqual(app.amqp._reconnect_delay,
                             int(amqp_env_vars['AMQP_RECONNECT_DELAY']))
            self.assertEqual(app.amqp._connection_attempts,
                             int(amqp_env_vars['AMQP_CONNECTION_ATTEMPTS']))
示例#9
0
 def test_double_install(self):
     self.assertFalse(amqp.install(self._app))
 def test_double_install(self):
     self.assertFalse(amqp.install(self._app))