Пример #1
0
    def test_signalling(self):
        """
        Test connecting to the server, binding a queue to the signalling
        exchange and signalling the outcome of a job.
        """

        # Create the exchange and bind a queue to it
        conn, ch = signalling.connect()

        qname = signalling.declare_and_bind_queue(0, ('succeeded',))

        # Send a message
        signalling.signal_job_outcome(0, 'succeeded')

        messages = []

        def callback(msg):
            messages.append(msg)
            ch.basic_cancel(msg.consumer_tag)

        ch.basic_consume(qname, callback=callback)

        while ch.callbacks:
            ch.wait()

        ch.close()
        conn.close()

        self.assertEqual(1, len(messages))
Пример #2
0
def bind_supervisor_queue(job_id):
    """
    Declare and bind the message queue used by the job supervisor.

    It is safe to call this function more than once.  If the exchange, queue or
    bindings already exists, this function won't create them again.
    """
    return signalling.declare_and_bind_queue(
        job_id, ('error', 'fatal'), get_supervisor_queue_name(job_id))
Пример #3
0
    def test_log_configuration(self):
        """Test that the AMQP log configuration is consistent"""
        conn, ch = signalling.connect()
        # match messages of any level related to any job
        qname = signalling.declare_and_bind_queue('*', '*')

        # now there is a queue, send the log messages from Java
        root_logger = jpype.JClass("org.apache.log4j.Logger").getRootLogger()
        root_logger.debug('Java debug message')
        root_logger.info('Java info message')
        root_logger.warn('Java warn message')
        root_logger.error('Java error message')
        root_logger.fatal('Java fatal message')

        # and from Python
        root_log = logging.getLogger()
        root_log.debug('Python %s message', 'debug')
        root_log.info('Python %s message', 'info')
        root_log.warning('Python %s message', 'warn')
        root_log.error('Python %s message', 'error')
        root_log.critical('Python %s message', 'fatal')

        # process the messages
        messages = []

        def consume(msg):
            messages.append(msg)

            if len(messages) == 10:
                ch.basic_cancel(msg.consumer_tag)

        self.consume_messages(conn, ch, qname, consume)

        self.assertEquals(10, len(messages))

        # check message order
        for source in ['Java', 'Python']:
            for level in ['debug', 'info', 'warn', 'error', 'fatal']:
                routing_key = 'log.%s.123' % level
                fragment = '%s %s message' % (source, level)
                contained = filter(lambda msg: fragment in msg.body, messages)

                self.assertEquals(
                    1, len(contained),
                    '"%s" contained in "%s"' % (fragment, contained))

                recv_routing_key = contained[0].delivery_info['routing_key']
                self.assertEquals(
                    routing_key, recv_routing_key,
                    '%s %s routing key: expected %s got %s' % (
                        source, level, routing_key, recv_routing_key))

        # check process name in messages
        for i, msg in enumerate(messages):
            self.assertTrue(' ->UnitTestProcess<- ' in msg.body,
                            'process name in %d-th log entry "%s"' % (
                    i, msg.body))