diff --git a/marconi/storage/base.py b/marconi/storage/base.py index 4d8d0eea..f1ee329f 100644 --- a/marconi/storage/base.py +++ b/marconi/storage/base.py @@ -99,32 +99,19 @@ class QueueBase(ControllerBase): pass @abc.abstractmethod - def create(self, name, tenant=None, ttl=MIN_TTL, **metadata): + def upsert(self, name, tenant=None, metadata=None): """ - Base method for queue creation. + This methods handles both creates and updates + operations for queues. :param name: The queue name :param tenant: Tenant id - :param ttl: Number of seconds the server - will keep messages for this queue. :param metadata: Arbitrary metadata + :returns: True if a queue was created and False + if it was updated. """ - - m = (_("TTL must be an integer between %(min)s and %(max)s") % - dict(min=MIN_TTL, max=MAX_TTL)) - assert (ttl >= MIN_TTL and ttl <= MAX_TTL), m - - @abc.abstractmethod - def update(self, name, tenant=None, **metadata): - """ - Base method for queue update. - - :param name: The queue name - :param tenant: Tenant id - :param metadata: Extra parameters defining - the new metadata for this queue. - """ - pass + msg = _("Metadata should be an instance of dict") + assert isinstance(metadata, dict), msg @abc.abstractmethod def delete(self, name, tenant=None): diff --git a/marconi/tests/storage/base.py b/marconi/tests/storage/base.py index 6fb9b7ba..a7ae1d11 100644 --- a/marconi/tests/storage/base.py +++ b/marconi/tests/storage/base.py @@ -46,26 +46,29 @@ class QueueControllerTest(ControllerBaseTest): def test_queue_lifecycle(self): # Test Queue Creation - self.controller.create("test", tenant=self.tenant, - ttl=60, topic="test_queue") + created = self.controller.upsert("test", tenant=self.tenant, + metadata=dict(topic="test_queue")) + + self.assertTrue(created) # Test Queue retrieval queue = self.controller.get("test", tenant=self.tenant) self.assertEqual(queue["name"], "test") - self.assertEqual(queue["ttl"], 60) # Test Queue Update - self.controller.update("tests", name="test1", tenant=self.tenant) - queue = self.controller.get("test1", tenant=self.tenant) - self.assertEqual(queue["ttl"], 60) + created = self.controller.upsert("test", tenant=self.tenant, + metadata=dict(meta="test_meta")) + self.assertFalse(created) + + queue = self.controller.get("test", tenant=self.tenant) + self.assertEqual(queue["metadata"]["meta"], "test_meta") # Test Queue Deletion - self.controller.delete("test1", tenant=self.tenant) + self.controller.delete("test", tenant=self.tenant) # Test DoesNotExist Exception self.assertRaises(storage.exceptions.DoesNotExist, - self.controller.get, "test1", - tenant=self.tenant) + self.controller.get, "test", tenant=self.tenant) class MessageControllerTest(ControllerBaseTest): diff --git a/marconi/tests/storage/test_base.py b/marconi/tests/storage/test_base.py index 17a1e347..43639a55 100644 --- a/marconi/tests/storage/test_base.py +++ b/marconi/tests/storage/test_base.py @@ -41,12 +41,9 @@ class QueueController(storage.QueueBase): def get(self, name, tenant=None): super(QueueController, self).get(name, tenant=tenant) - def create(self, name, tenant=None, ttl=None, **metadata): - super(QueueController, self).create(name, tenant=tenant, - ttl=ttl, **metadata) - - def update(self, name, tenant=None, **metadata): - super(QueueController, self).update(name, tenant=tenant, **metadata) + def upsert(self, name, tenant=None, metadata=None): + super(QueueController, self).upsert(name, tenant=tenant, + metadata=metadata) def delete(self, name, tenant=None): super(QueueController, self).delete(name, tenant=tenant) @@ -66,13 +63,8 @@ class TestQueueBase(suite.TestSuite): self.driver = Driver() self.controller = self.driver.queue_controller - def test_create(self): - self.assertRaises(AssertionError, self.controller.create, - "test", ttl=30) + def test_upsert(self): + self.assertRaises(AssertionError, self.controller.upsert, + "test", metadata=[]) - self.assertRaises(AssertionError, self.controller.create, - "test", ttl=1209601) - - self.assertIsNone(self.controller.create("test", ttl=60)) - self.assertIsNone(self.controller.create("test", ttl=120)) - self.assertIsNone(self.controller.create("test", ttl=1209600)) + self.assertIsNone(self.controller.upsert("test", metadata={}))