示例#1
0
    def do_simple_topic_test(self, pattern, name, properties={}, autodeleted=True):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create("TopicPolicy", pattern, properties)
        try:
            snd = self.ssn.sender(name)
            rcv1 = self.ssn.receiver(name)
            rcv2 = self.ssn.receiver(name)

            msgs = [Message(content=s, subject=s) for s in ["a", "b", "c", "d"]]
            for m in msgs:
                snd.send(m)

            for rcv in [rcv1, rcv2]:
                for expected in msgs:
                    msg = rcv.fetch(0)
                    assert msg.content == expected.content, (msg.content, expected.content)
            self.ssn.acknowledge()
            rcv1.close()
            rcv2.close()
            snd.close()

            matched = [e for e in agent.list("Exchange") if e["name"] == name]
            if autodeleted:
                # ensure that exchange is no longer there (as it is now unused)
                assert len(matched) == 0, matched
            else:
                # ensure that exchange has not been autodeleted in spite of being unused
                assert len(matched) == 1, matched
        finally:
            agent.delete("TopicPolicy", pattern)
            mgmt.close()
示例#2
0
    def do_simple_queue_test(self, pattern, name, properties={}, autodeleted=True):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create("QueuePolicy", pattern, properties)
        try:
            snd = self.ssn.sender(name)
            msgs = [Message(content=s, subject=s) for s in ["a", "b", "c", "d"]]
            for m in msgs:
                snd.send(m)
            snd.close()

            for expected in msgs:
                rcv = self.ssn.receiver(name)
                msg = rcv.fetch(0)
                assert msg.content == expected.content, (msg.content, expected.content)
                self.ssn.acknowledge()
                rcv.close()  # close after each message to ensure queue isn't deleted with messages in it
            self.ssn.close()
            self.conn.close()

            matched = [q for q in agent.list("Queue") if q["name"] == name]
            if autodeleted:
                # ensure that queue is no longer there (as empty and unused)
                assert len(matched) == 0, matched
            else:
                # ensure that queue is still there though empty and unused
                assert len(matched) == 1, matched
        finally:
            agent.delete("QueuePolicy", pattern)
            mgmt.close()
示例#3
0
    def do_simple_topic_test(self,
                             pattern,
                             name,
                             properties={},
                             autodeleted=True):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create('TopicPolicy', pattern, properties)
        try:
            snd = self.ssn.sender(name)
            rcv1 = self.ssn.receiver(name)
            rcv2 = self.ssn.receiver(name)

            msgs = [
                Message(content=s, subject=s) for s in ['a', 'b', 'c', 'd']
            ]
            for m in msgs:
                snd.send(m)

            for rcv in [rcv1, rcv2]:
                for expected in msgs:
                    msg = rcv.fetch(0)
                    assert msg.content == expected.content, (msg.content,
                                                             expected.content)
            self.ssn.acknowledge()
            rcv1.close()
            rcv2.close()
            snd.close()

            matched = [e for e in agent.list("Exchange") if e['name'] == name]
            if autodeleted:
                # ensure that exchange is no longer there (as it is now unused)
                assert len(matched) == 0, (matched)
            else:
                # ensure that exchange has not been autodeleted in spite of being unused
                assert len(matched) == 1, (matched)
        finally:
            agent.delete('TopicPolicy', pattern)
            mgmt.close()
示例#4
0
    def do_simple_queue_test(self,
                             pattern,
                             name,
                             properties={},
                             autodeleted=True):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create('QueuePolicy', pattern, properties)
        try:
            snd = self.ssn.sender(name)
            msgs = [
                Message(content=s, subject=s) for s in ['a', 'b', 'c', 'd']
            ]
            for m in msgs:
                snd.send(m)
            snd.close()

            for expected in msgs:
                rcv = self.ssn.receiver(name)
                msg = rcv.fetch(0)
                assert msg.content == expected.content, (msg.content,
                                                         expected.content)
                self.ssn.acknowledge()
                rcv.close(
                )  #close after each message to ensure queue isn't deleted with messages in it
            self.ssn.close()
            self.conn.close()

            matched = [q for q in agent.list("Queue") if q['name'] == name]
            if autodeleted:
                # ensure that queue is no longer there (as empty and unused)
                assert len(matched) == 0, (matched)
            else:
                # ensure that queue is still there though empty and unused
                assert len(matched) == 1, (matched)
        finally:
            agent.delete('QueuePolicy', pattern)
            mgmt.close()
示例#5
0
    def test_mgmt(self):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create("QueuePolicy", "queue-*")
        agent.create("QueuePolicy", "alt.queue.*")
        agent.create("TopicPolicy", "topic-*")
        try:
            queues = [q["name"] for q in agent.list("QueuePolicy")]
            topics = [t["name"] for t in agent.list("TopicPolicy")]
            assert "queue-*" in queues, queues
            assert "alt.queue.*" in queues, queues

            try:
                agent.delete("TopicPolicy", "queue-*")
                assert False, "Deletion of policy using wrong type should fail"
            except:
                None

        finally:
            agent.delete("QueuePolicy", "queue-*")
            agent.delete("QueuePolicy", "alt.queue.*")
            agent.delete("TopicPolicy", "topic-*")
            mgmt.close()
示例#6
0
    def test_mgmt(self):
        mgmt = self.create_connection("amqp0-10", True)
        agent = Mgmt(mgmt)
        agent.create('QueuePolicy', 'queue-*')
        agent.create('QueuePolicy', 'alt.queue.*')
        agent.create('TopicPolicy', 'topic-*')
        try:
            queues = [q['name'] for q in agent.list("QueuePolicy")]
            topics = [t['name'] for t in agent.list("TopicPolicy")]
            assert 'queue-*' in queues, (queues)
            assert 'alt.queue.*' in queues, (queues)

            try:
                agent.delete('TopicPolicy', 'queue-*')
                assert False, (
                    'Deletion of policy using wrong type should fail')
            except:
                None

        finally:
            agent.delete('QueuePolicy', 'queue-*')
            agent.delete('QueuePolicy', 'alt.queue.*')
            agent.delete('TopicPolicy', 'topic-*')
            mgmt.close()