summaryrefslogtreecommitdiff
path: root/python/tests_0-10_preview/persistence.py
blob: ad578474eb72360dc0fe92f0d0807b0f28209a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
from qpid.client import Client, Closed
from qpid.queue import Empty
from qpid.content import Content
from qpid.testlib import testrunner, TestBase

class PersistenceTests(TestBase):
    def test_delete_queue_after_publish(self):
        channel = self.channel
        channel.synchronous = False

        #create queue
        channel.queue_declare(queue = "q", auto_delete=True, durable=True)

        #send message
        for i in range(1, 10):
            channel.message_transfer(content=Content(properties={'routing_key' : "q", 'delivery_mode':2}, body = "my-message"))

        channel.synchronous = True
        #explicitly delete queue
        channel.queue_delete(queue = "q")

    def test_ack_message_from_deleted_queue(self):
        channel = self.channel
        channel.synchronous = False

        #create queue
        channel.queue_declare(queue = "q", auto_delete=True, durable=True)

        #send message
        channel.message_transfer(content=Content(properties={'routing_key' : "q", 'delivery_mode':2}, body = "my-message"))

        #create consumer
        channel.message_subscribe(queue = "q", destination = "a", confirm_mode = 1, acquire_mode=0)
        channel.message_flow(unit = 1, value = 0xFFFFFFFF, destination = "a")
        channel.message_flow(unit = 0, value = 10, destination = "a")
        queue = self.client.queue("a")

        #consume the message, cancel subscription (triggering auto-delete), then ack it
        msg = queue.get(timeout = 5)
        channel.message_cancel(destination = "a")        
        msg.complete()

    def test_queue_deletion(self):
        channel = self.channel
        channel.queue_declare(queue = "durable-subscriber-queue", exclusive=True, durable=True)
        channel.queue_bind(exchange="amq.topic", queue="durable-subscriber-queue", routing_key="xyz")
        channel.message_transfer(destination= "amq.topic", content=Content(properties={'routing_key' : "xyz", 'delivery_mode':2}, body = "my-message"))
        channel.queue_delete(queue = "durable-subscriber-queue")