blob: a306623210c4d6bed7a7b0fde6f7f960a8998008 [file] [log] [blame]
Malini Kamalambal7458b4b2014-05-29 11:47:28 -04001# Copyright (c) 2014 Rackspace, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import logging
17import urlparse
18
19from tempest.api.queuing import base
20from tempest.common.utils import data_utils
21from tempest import config
22from tempest import test
23
24
25LOG = logging.getLogger(__name__)
26CONF = config.CONF
27
28
29class TestClaims(base.BaseQueuingTest):
30 _interface = 'json'
31
32 @classmethod
33 def setUpClass(cls):
34 super(TestClaims, cls).setUpClass()
35 cls.queue_name = data_utils.rand_name('Queues-Test')
36 # Create Queue
37 cls.create_queue(cls.queue_name)
38
39 def _post_and_claim_messages(self, queue_name, repeat=1):
40 # Post Messages
41 message_body = self.generate_message_body(repeat=repeat)
42 self.client.post_messages(queue_name=self.queue_name,
43 rbody=message_body)
44
45 # Post Claim
46 claim_ttl = data_utils.rand_int_id(start=60,
47 end=CONF.queuing.max_claim_ttl)
48 claim_grace = data_utils.rand_int_id(start=60,
49 end=CONF.queuing.max_claim_grace)
50 claim_body = {"ttl": claim_ttl, "grace": claim_grace}
51 resp, body = self.client.post_claims(queue_name=self.queue_name,
52 rbody=claim_body)
53
54 return resp, body
55
56 @test.attr(type='smoke')
57 def test_post_claim(self):
58 _, body = self._post_and_claim_messages(queue_name=self.queue_name)
59 claimed_message_uri = body[0]['href']
60
61 # Skipping this step till bug-1331517 is fixed
62 # Get posted claim
63 # self.client.query_claim(claimed_message_uri)
64
65 # Delete Claimed message
66 self.client.delete_messages(claimed_message_uri)
67
68 @test.skip_because(bug="1331517")
69 @test.attr(type='smoke')
70 def test_query_claim(self):
71 # Post a Claim
72 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
73
74 # Query Claim
75 claim_uri = resp['location']
76 self.client.query_claim(claim_uri)
77
78 # Delete Claimed message
79 claimed_message_uri = body[0]['href']
80 self.delete_messages(claimed_message_uri)
81
82 @test.skip_because(bug="1328111")
83 @test.attr(type='smoke')
84 def test_update_claim(self):
85 # Post a Claim
86 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
87
88 claim_uri = resp['location']
89 claimed_message_uri = body[0]['href']
90
91 # Update Claim
92 claim_ttl = data_utils.rand_int_id(start=60,
93 end=CONF.queuing.max_claim_ttl)
94 update_rbody = {"ttl": claim_ttl}
95
96 self.client.update_claim(claim_uri, rbody=update_rbody)
97
98 # Verify claim ttl >= updated ttl value
99 _, body = self.client.query_claim(claim_uri)
100 updated_claim_ttl = body["ttl"]
101 self.assertTrue(updated_claim_ttl >= claim_ttl)
102
103 # Delete Claimed message
104 self.client.delete_messages(claimed_message_uri)
105
106 @test.attr(type='smoke')
107 def test_release_claim(self):
108 # Post a Claim
109 resp, body = self._post_and_claim_messages(queue_name=self.queue_name)
110 claim_uri = resp['location']
111
112 # Release Claim
113 self.client.release_claim(claim_uri)
114
115 # Delete Claimed message
116 # This will implicitly verify that the claim is deleted.
117 message_uri = urlparse.urlparse(claim_uri).path
118 self.client.delete_messages(message_uri)
119
120 @classmethod
121 def tearDownClass(cls):
122 cls.delete_queue(cls.queue_name)
123 super(TestClaims, cls).tearDownClass()