Merge "Add Tests for Queue Stats"

This commit is contained in:
Jenkins 2013-10-03 18:47:18 +00:00 committed by Gerrit Code Review
commit cbd9fda4d2
5 changed files with 97 additions and 21 deletions

View File

@ -84,14 +84,30 @@ class FunctionalTestBase(testing.TestBase):
self.assertTrue(required_values.issubset(actual_values),
msg=form.format((required_values - actual_values)))
def assertMessageCount(self, expectedCount, actualCount):
def assertMessageCount(self, actualCount, expectedCount):
"""Checks if number of messages returned <= limit
:param expectedCount: limit value passed in the url (OR) default(10).
:param actualCount: number of messages returned in the API response.
"""
self.assertTrue(actualCount <= expectedCount,
msg='More Messages returned than allowed')
msg = 'More Messages returned than allowed: expected count = {0}' \
', actual count = {1}'.format(expectedCount, actualCount)
self.assertTrue(actualCount <= expectedCount, msg)
def assertQueueStats(self, result_json, claimed):
"""Checks the Queue Stats results
:param result_json: json response returned for Queue Stats.
:param claimed: expected number of claimed messages.
"""
total = self.limits.message_paging_uplimit
free = total - claimed
self.assertEqual(result_json['messages']['claimed'], claimed)
self.assertEqual(result_json['messages']['free'],
free)
self.assertEqual(result_json['messages']['total'],
total)
class Server(object):

View File

@ -93,7 +93,7 @@ def single_message_body(**kwargs):
return message_body
def get_message_body(**kwargs):
def create_message_body(**kwargs):
"""Returns request body for post message tests.
:param **kwargs: can be {messagecount: x} , x is the # of messages.

View File

@ -42,8 +42,8 @@ class TestClaims(base.FunctionalTestBase):
#Post Messages
url = self.queue_url + '/messages'
doc = helpers.get_message_body(messagecount=
self.limits.message_paging_uplimit)
doc = helpers.create_message_body(messagecount=
self.limits.message_paging_uplimit)
for i in range(25):
self.client.post(url, data=doc)
@ -58,7 +58,7 @@ class TestClaims(base.FunctionalTestBase):
self.assertEqual(result.status_code, 201)
actual_message_count = len(result.json())
self.assertMessageCount(message_count, actual_message_count)
self.assertMessageCount(actual_message_count, message_count)
response_headers = set(result.headers.keys())
self.assertIsSubset(self.headers_response_with_body, response_headers)

View File

@ -45,7 +45,7 @@ class TestMessages(base.FunctionalTestBase):
This test also verifies that claimed messages are
retuned (or not) depending on the include_claimed flag.
"""
doc = helpers.get_message_body(messagecount=1)
doc = helpers.create_message_body(messagecount=1)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -87,8 +87,8 @@ class TestMessages(base.FunctionalTestBase):
def test_message_bulk_insert(self):
"""Bulk Insert Messages into the Queue."""
message_count = 10
doc = helpers.get_message_body(messagecount=message_count)
message_count = self.limits.message_paging_uplimit
doc = helpers.create_message_body(messagecount=message_count)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -119,8 +119,8 @@ class TestMessages(base.FunctionalTestBase):
expected_msg_count = params.get('limit', 10)
# Test Setup
doc = helpers.get_message_body(messagecount=
self.limits.message_paging_uplimit)
doc = helpers.create_message_body(messagecount=
self.limits.message_paging_uplimit)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -146,7 +146,7 @@ class TestMessages(base.FunctionalTestBase):
def test_message_delete(self):
"""Delete Message."""
# Test Setup
doc = helpers.get_message_body(messagecount=1)
doc = helpers.create_message_body(messagecount=1)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -164,7 +164,7 @@ class TestMessages(base.FunctionalTestBase):
def test_message_bulk_delete(self):
"""Bulk Delete Messages."""
doc = helpers.get_message_body(messagecount=10)
doc = helpers.create_message_body(messagecount=10)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -191,7 +191,7 @@ class TestMessages(base.FunctionalTestBase):
def test_message_partial_delete(self):
"""Delete Messages will be partially successful."""
doc = helpers.get_message_body(messagecount=3)
doc = helpers.create_message_body(messagecount=3)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -207,7 +207,7 @@ class TestMessages(base.FunctionalTestBase):
def test_message_partial_get(self):
"""Get Messages will be partially successful."""
doc = helpers.get_message_body(messagecount=3)
doc = helpers.create_message_body(messagecount=3)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 201)
@ -226,7 +226,7 @@ class TestMessages(base.FunctionalTestBase):
Marconi allows a maximum of 50 message per POST.
"""
doc = helpers.get_message_body(messagecount=60)
doc = helpers.create_message_body(messagecount=60)
result = self.client.post(data=doc)
self.assertEqual(result.status_code, 400)

View File

@ -18,6 +18,7 @@ import six
import uuid
from marconi.tests.functional import base # noqa
from marconi.tests.functional import helpers
class NamedBinaryStr(six.binary_type):
@ -255,9 +256,14 @@ class TestQueueMisc(base.FunctionalTestBase):
self.client.set_base_url(self.base_url)
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
def test_list_queues(self):
"""List Queues."""
self.client.put(self.queue_url)
self.addCleanup(self.client.delete, self.queue_url)
result = self.client.get('/queues')
self.assertEqual(result.status_code, 200)
@ -270,6 +276,9 @@ class TestQueueMisc(base.FunctionalTestBase):
def test_list_queues_detailed(self):
"""List Queues with detailed = True."""
self.client.put(self.queue_url)
self.addCleanup(self.client.delete, self.queue_url)
params = {'detailed': True}
result = self.client.get('/queues', params=params)
self.assertEqual(result.status_code, 200)
@ -301,12 +310,12 @@ class TestQueueMisc(base.FunctionalTestBase):
def test_check_queue_exists(self):
"""Checks if queue exists."""
path = '/queues/testqueue'
self.client.put(path)
result = self.client.get(path)
self.client.put(self.queue_url)
self.addCleanup(self.client.delete, self.queue_url)
result = self.client.get(self.queue_url)
self.assertEqual(result.status_code, 204)
result = self.client.head(path)
result = self.client.head(self.queue_url)
self.assertEqual(result.status_code, 204)
test_check_queue_exists.tags = ['positive']
@ -330,3 +339,54 @@ class TestQueueMisc(base.FunctionalTestBase):
self.assertEqual(result.status_code, 204)
test_get_queue_malformed_marker.tags = ['negative']
def test_get_stats_empty_queue(self):
"""Get queue stats on an empty queue."""
result = self.client.put(self.queue_url)
self.addCleanup(self.client.delete, self.queue_url)
self.assertEqual(result.status_code, 201)
stats_url = self.queue_url + '/stats'
#Get stats on an empty queue
result = self.client.get(stats_url)
self.assertEqual(result.status_code, 200)
expected_response = {'messages':
{'claimed': 0, 'total': 0, 'free': 0}}
self.assertEqual(result.json(), expected_response)
test_get_stats_empty_queue.tags = ['positive']
@ddt.data(0, 1)
def test_get_queue_stats_claimed(self, claimed):
"""Get stats on a queue."""
result = self.client.put(self.queue_url)
self.addCleanup(self.client.delete, self.queue_url)
self.assertEqual(result.status_code, 201)
#Post Messages to the test queue
doc = helpers.create_message_body(messagecount=
self.limits.message_paging_uplimit)
message_url = self.queue_url + '/messages'
result = self.client.post(message_url, data=doc)
self.assertEqual(result.status_code, 201)
if claimed > 0:
claim_url = self.queue_url + '/claims?limit=' + str(claimed)
doc = {'ttl': 300, 'grace': 300}
result = self.client.post(claim_url, data=doc)
self.assertEqual(result.status_code, 201)
#Get stats on the queue.
stats_url = self.queue_url + '/stats'
result = self.client.get(stats_url)
self.assertEqual(result.status_code, 200)
self.assertQueueStats(result.json(), claimed)
test_get_queue_stats_claimed.tags = ['positive']
def tearDown(self):
super(TestQueueMisc, self).tearDown()