コード例 #1
0
ファイル: testlib.py プロジェクト: wputra/MOS-centos
class TestBase010(unittest.TestCase):
    """
    Base class for Qpid test cases. using the final 0-10 spec
    """
    def configure(self, config):
        self.config = config
        self.broker = config.broker
        self.defines = self.config.defines

    def setUp(self):
        self.conn = self.connect()
        self.session = self.conn.session("test-session", timeout=10)
        self.qmf = None

    def startQmf(self, handler=None):
        self.qmf = qmf.console.Session(handler)
        self.qmf_broker = self.qmf.addBroker(str(self.broker))

    def connect(self, host=None, port=None):
        url = self.broker
        if url.scheme == URL.AMQPS:
            default_port = 5671
        else:
            default_port = 5672
        try:
            sock = connect(host or url.host, port or url.port or default_port)
        except socket.error, e:
            raise Skipped(e)
        if url.scheme == URL.AMQPS:
            sock = ssl(sock)
        conn = Connection(sock,
                          username=url.user or "guest",
                          password=url.password or "guest")
        try:
            conn.start(timeout=10)
        except VersionError, e:
            raise Skipped(e)
コード例 #2
0
ファイル: testlib.py プロジェクト: wputra/MOS-centos
class TestBase(unittest.TestCase):
    """Base class for Qpid test cases.

    self.client is automatically connected with channel 1 open before
    the test methods are run.

    Deletes queues and exchanges after.  Tests call
    self.queue_declare(channel, ...) and self.exchange_declare(chanel,
    ...) which are wrappers for the Channel functions that note
    resources to clean up later.
    """
    def configure(self, config):
        self.config = config

    def setUp(self):
        self.queues = []
        self.exchanges = []
        self.client = self.connect()
        self.channel = self.client.channel(1)
        self.version = (self.client.spec.major, self.client.spec.minor)
        if self.version == (8, 0) or self.version == (0, 9):
            self.channel.channel_open()
        else:
            self.channel.session_open()

    def tearDown(self):
        try:
            for ch, q in self.queues:
                ch.queue_delete(queue=q)
            for ch, ex in self.exchanges:
                ch.exchange_delete(exchange=ex)
        except:
            print "Error on tearDown:"
            print traceback.print_exc()

        if not self.client.closed:
            self.client.channel(0).connection_close(reply_code=200)
        else:
            self.client.close()

    def connect(self,
                host=None,
                port=None,
                user=None,
                password=None,
                tune_params=None):
        """Create a new connction, return the Client object"""
        host = host or self.config.broker.host
        port = port or self.config.broker.port or 5672
        user = user or "guest"
        password = password or "guest"
        client = qpid.client.Client(host, port)
        try:
            if client.spec.major == 8 and client.spec.minor == 0:
                client.start({
                    "LOGIN": user,
                    "PASSWORD": password
                },
                             tune_params=tune_params)
            else:
                client.start("\x00" + user + "\x00" + password,
                             mechanism="PLAIN",
                             tune_params=tune_params)
        except qpid.client.Closed, e:
            if isinstance(e.args[0], VersionError):
                raise Skipped(e.args[0])
            else:
                raise e
        except socket.error, e:
            raise Skipped(e)
コード例 #3
0
class TestBase(unittest.TestCase):
    """Base class for Qpid test cases.

    self.client is automatically connected with channel 1 open before
    the test methods are run.

    Deletes queues and exchanges after.  Tests call
    self.queue_declare(channel, ...) and self.exchange_declare(chanel,
    ...) which are wrappers for the Channel functions that note
    resources to clean up later.
    """
    DEFAULT_USERNAME = "******"
    DEFAULT_PASSWORD = "******"
    DEFAULT_PORT = 5672

    def configure(self, config):
        self.config = config

    def setUp(self):
        self.queues = []
        self.exchanges = []
        self.client = self.connect()
        self.channel = self.client.channel(1)
        self.version = (self.client.spec.major, self.client.spec.minor)
        if self.version == (8, 0) or self.version == (0, 9):
            self.channel.channel_open()
        else:
            self.channel.session_open()

    def tearDown(self):
        try:
            for ch, q in self.queues:
                ch.queue_delete(queue=q)
            for ch, ex in self.exchanges:
                ch.exchange_delete(exchange=ex)
        except:
            print "Error on tearDown:"
            print traceback.print_exc()

        self.client.close()

    def recv_timeout(self):
        """Timeout used when a message is anticipated."""
        return float(self.config.defines.get("qpid.recv_timeout", "1"))

    def recv_timeout_negative(self):
        """Timeout used when a message is NOT expected."""
        return float(self.config.defines.get("qpid.recv_timeout_negative", "0.5"))

    def connect(self, host=None, port=None, user=None, password=None, tune_params=None, client_properties=None, channel_options=None):
        """Create a new connction, return the Client object"""
        host = host or self.config.broker.host
        port = port or self.config.broker.port or self.DEFAULT_PORT
        user = user or self.config.broker.user or self.DEFAULT_USERNAME
        password = password or self.config.broker.password or self.DEFAULT_PASSWORD
        client = qpid.client.Client(host, port)
        try:
          client.start(username = user, password=password, tune_params=tune_params, client_properties=client_properties, channel_options=channel_options)
        except qpid.client.Closed, e:
            if isinstance(e.args[0], VersionError):
                raise Skipped(e.args[0])
            else:
                raise e
        except socket.error, e:
            raise Skipped(e)
コード例 #4
0
 def call(self, parser, mode, input):
     try:
         from subprocess import Popen, PIPE, STDOUT
         po = Popen([parser, mode], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
     except ImportError, e:
         raise Skipped("%s" % e)
コード例 #5
0
ファイル: echo.py プロジェクト: irinabov/debian-qpid-python
    def test_large_message_received_in_many_content_frames(self):
        if self.client.conn.FRAME_MIN_SIZE == self.frame_max_size:
            raise Skipped(
                "Test requires that frame_max_size (%d) exceeds frame_min_size (%d)"
                % (self.frame_max_size, self.frame_max_size))

        channel = self.channel

        queue_name = "q"
        self.queue_declare(queue=queue_name)

        channel.tx_select()

        body = self.randomLongString()
        channel.basic_publish(content=Content(body), routing_key=queue_name)
        channel.tx_commit()

        consuming_client = None
        try:
            # Create a second connection with minimum framesize.  The Broker will then be forced to chunk
            # the content in order to send it to us.
            consuming_client = qpid.client.Client(
                self.config.broker.host, self.config.broker.port
                or self.DEFAULT_PORT)
            tune_params = {"frame_max": self.client.conn.FRAME_MIN_SIZE}
            consuming_client.start(username=self.config.broker.user
                                   or self.DEFAULT_USERNAME,
                                   password=self.config.broker.password
                                   or self.DEFAULT_PASSWORD,
                                   tune_params=tune_params)

            consuming_channel = consuming_client.channel(1)
            consuming_channel.channel_open()
            consuming_channel.tx_select()

            consumer_reply = consuming_channel.basic_consume(queue=queue_name,
                                                             no_ack=False)
            consumer = consuming_client.queue(consumer_reply.consumer_tag)
            msg = consumer.get(timeout=self.recv_timeout())
            consuming_channel.basic_ack(delivery_tag=msg.delivery_tag)
            consuming_channel.tx_commit()

            self.assertEqual(len(body), len(msg.content.body))
            self.assertEqual(body, msg.content.body)
        finally:
            if consuming_client:
                consuming_client.close()

        def test_commit_ok_possibly_interleaved_with_message_delivery(self):
            """This test exposes an defect on the Java Broker (QPID-6094).  The Java Broker (0.32 and below)
         can contravene the AMQP spec by sending other frames between the message header/frames.
         As this is a long standing defect in the Java Broker, QPID-6082 changed
         the Python client to allow it to tolerate such illegal interleaving.
         """
            channel = self.channel

            queue_name = "q"
            self.queue_declare(queue=queue_name)

            count = 25
            channel.basic_qos(prefetch_count=count)

            channel.tx_select()

            bodies = []
            for i in range(count):
                body = self.randomLongString()
                bodies.append(body)
                channel.basic_publish(content=Content(bodies[i]),
                                      routing_key=queue_name)
                channel.tx_commit()

            # Start consuming.  Prefetch will mean the Broker will start to send us
            # all the messages accumulating them in the client.
            consumer = self.consume("q", no_ack=False)

            # Get and ack/commit the first message
            msg = consumer.get(timeout=self.recv_timeout())
            channel.basic_ack(delivery_tag=msg.delivery_tag)
            channel.tx_commit()
            # In the problematic case, the Broker interleaves our commit-ok response amongst the content
            # frames of message.   QPID-6082 means the Python client now tolerates this
            # problem and all messages should arrive correctly.

            expectedBody = bodies[0]
            self.assertEqual(len(expectedBody), len(msg.content.body))
            self.assertEqual(expectedBody, msg.content.body)

            for i in range(1, len(bodies)):
                msg = consumer.get(timeout=self.recv_timeout())

                expectedBody = bodies[i]
                self.assertEqual(len(expectedBody), len(msg.content.body))
                self.assertEqual(expectedBody, msg.content.body)