fix: Claim can return 404

This patch changes the way creating a claim behaves when the
queue does not exist. Instead of returning 404, it returns
204, meaning the claim was not able to find any messages to
claim.

This was done for two reasons:

1. For eventually-consistent backends, a brand new queue may
not appear to exist, so this new semantic allows the driver
to just try to grab some messages without checking first
whether the queue "exists".
2. For backends like MongoDB that require an extra check to
determine whether a queue exists, this removes an extra
round trip to the DB in order to perform the operation.

Note that the SQLite driver was updated in order to be
consistent with the new behavior.

Change-Id: Icde4ce493a76ef145e99300b67d8344d5092e38d
Partial-Bug: #1218990
This commit is contained in:
kgriffs 2013-08-30 14:47:24 -05:00
parent 7a7771b06e
commit c1a564b444
4 changed files with 6 additions and 9 deletions

View File

@ -118,9 +118,6 @@ class ClaimController(storage.ClaimBase):
"""
msg_ctrl = self.driver.message_controller
if not self.driver.queue_controller.exists(queue, project):
raise exceptions.QueueDoesNotExist(queue, project)
ttl = metadata['ttl']
grace = metadata['grace']
oid = objectid.ObjectId()
@ -148,7 +145,7 @@ class ClaimController(storage.ClaimBase):
ids = [msg['_id'] for msg in msgs]
if len(ids) == 0:
return (str(oid), messages)
return (None, messages)
now = timeutils.utcnow()

View File

@ -78,7 +78,10 @@ class ClaimController(base.ClaimBase):
project = ''
with self.driver('immediate'):
qid = utils.get_qid(self.driver, queue, project)
try:
qid = utils.get_qid(self.driver, queue, project)
except exceptions.QueueDoesNotExist:
return None, iter([])
# Clean up all expired claims in this queue

View File

@ -201,7 +201,7 @@ class ClaimsBaseTest(base.TestBase):
def test_nonexistent(self):
self.simulate_post('/v1/queues/nonexistent/claims', self.project_id,
body='{"ttl": 100, "grace": 60}')
self.assertEquals(self.srmock.status, falcon.HTTP_404)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
# NOTE(cpp-cabrera): regression test against bug #1203842
def test_get_nonexistent_claim_404s(self):

View File

@ -76,9 +76,6 @@ class CollectionResource(object):
except input_exceptions.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestBody(str(ex))
except storage_exceptions.DoesNotExist:
raise falcon.HTTPNotFound()
except Exception as ex:
LOG.exception(ex)
description = _(u'Claim could not be created.')