launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05128
[Merge] lp:~allenap/txlongpoll/queue-prefix-optional into lp:txlongpoll
Gavin Panella has proposed merging lp:~allenap/txlongpoll/queue-prefix-optional into lp:txlongpoll.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/txlongpoll/queue-prefix-optional/+merge/77535
Allow for an empty prefix, and make it the default.
--
https://code.launchpad.net/~allenap/txlongpoll/queue-prefix-optional/+merge/77535
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/txlongpoll/queue-prefix-optional into lp:txlongpoll.
=== modified file 'twisted/plugins/longpoll.py'
--- twisted/plugins/longpoll.py 2011-09-26 15:22:46 +0000
+++ twisted/plugins/longpoll.py 2011-09-29 14:01:38 +0000
@@ -65,7 +65,7 @@
["brokerpassword", "a", None, "Broker password"],
["brokervhost", "v", '/', "Broker vhost"],
["frontendport", "f", None, "Frontend port"],
- ["prefix", "x", 'XXX', "Queue prefix"],
+ ["prefix", "x", None, "Queue prefix"],
["oops-dir", "r", None, "Where to write OOPS reports"],
["oops-prefix", "o", "LONGPOLL", "String prefix for OOPS IDs"],
]
=== modified file 'txlongpoll/frontend.py'
--- txlongpoll/frontend.py 2011-09-19 10:09:55 +0000
+++ txlongpoll/frontend.py 2011-09-29 14:01:38 +0000
@@ -42,11 +42,19 @@
# is 5 minutes.
message_timeout = 270
- def __init__(self, prefix):
+ def __init__(self, prefix=None):
self._prefix = prefix
self._channel = None
self._client = None
self._pending_requests = []
+ # Preserve compatibility by using special forms for naming when a
+ # prefix is specified.
+ if self._prefix is not None and len(self._prefix) != 0:
+ self._tag_form = "%s.notifications-tag.%%s.%%s" % self._prefix
+ self._queue_form = "%s.notifications-queue.%%s" % self._prefix
+ else:
+ self._tag_form = "%s.%s"
+ self._queue_form = "%s"
def disconnected(self):
"""
@@ -93,11 +101,10 @@
"""
if self._channel is None:
yield self._wait_for_connection()
- tag = "%s.notifications-tag.%s.%s" % (self._prefix, uuid, sequence)
+ tag = self._tag_form % (uuid, sequence)
try:
yield self._channel.basic_consume(
- consumer_tag=tag,
- queue="%s.notifications-queue.%s" % (self._prefix, uuid))
+ consumer_tag=tag, queue=(self._queue_form % uuid))
log.msg("Consuming from queue '%s'" % uuid)
@@ -154,7 +161,7 @@
in the queue.
"""
if self._client is not None:
- tag = "%s.notifications-tag.%s.%s" % (self._prefix, uuid, sequence)
+ tag = self._tag_form % (uuid, sequence)
queue = yield self._client.queue(tag)
queue.put(Empty)
=== modified file 'txlongpoll/tests/test_frontend.py'
--- txlongpoll/tests/test_frontend.py 2011-07-12 06:07:25 +0000
+++ txlongpoll/tests/test_frontend.py 2011-09-29 14:01:38 +0000
@@ -21,9 +21,13 @@
class QueueManagerTest(AMQTest):
+ prefix = None
+ tag_prefix = ""
+ queue_prefix = ""
+
def setUp(self):
self.clock = Clock()
- self.manager = QueueManager("test")
+ self.manager = QueueManager(self.prefix)
return AMQTest.setUp(self)
def test_wb_connected(self):
@@ -46,16 +50,16 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1", auto_delete=True)
+ queue=self.queue_prefix + "uuid1", auto_delete=True)
content = Content("some content")
yield self.channel.basic_publish(
- routing_key="test.notifications-queue.uuid1",
+ routing_key=self.queue_prefix + "uuid1",
content=content)
message = yield self.manager.get_message("uuid1", "0")
self.assertEquals(message[0], "some content")
- self.assertNotIn("test.notifications-tag.uuid1.0", self.client.queues)
+ self.assertNotIn(self.tag_prefix + "uuid1.0", self.client.queues)
@inlineCallbacks
def test_reject_message(self):
@@ -65,11 +69,11 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
content = Content("some content")
yield self.channel.basic_publish(
- routing_key="test.notifications-queue.uuid1",
+ routing_key=self.queue_prefix + "uuid1",
content=content)
message, tag = yield self.manager.get_message("uuid1", "0")
yield self.manager.reject_message(tag)
@@ -84,16 +88,16 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
content = Content("some content")
yield self.channel.basic_publish(
- routing_key="test.notifications-queue.uuid1",
+ routing_key=self.queue_prefix + "uuid1",
content=content)
message, tag = yield self.manager.get_message("uuid1", "0")
yield self.manager.ack_message(tag)
- reply = yield self.client.queue("test.notifications-tag.uuid1.1")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
@@ -127,10 +131,10 @@
self.amq_disconnected = self.manager.disconnected
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
content = Content("some content")
- reply = yield self.client.queue("test.notifications-tag.uuid1.0")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
@@ -147,7 +151,7 @@
yield self.manager.connected((self.client, self.channel))
yield self.channel.basic_publish(
- routing_key="test.notifications-queue.uuid1",
+ routing_key=self.queue_prefix + "uuid1",
content=content)
message = yield d1
@@ -161,9 +165,9 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
- reply = yield self.client.queue("test.notifications-tag.uuid1.0")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
@@ -173,7 +177,7 @@
self.clock.advance(self.manager.message_timeout + 1)
yield assert_fails_with(d, Empty)
- self.assertNotIn("test.notifications-tag.uuid1.0", self.client.queues)
+ self.assertNotIn(self.tag_prefix + "uuid1.0", self.client.queues)
@inlineCallbacks
def test_wb_timeout_race_condition(self):
@@ -184,17 +188,17 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
content = Content("some content")
- reply = yield self.client.queue("test.notifications-tag.uuid1.0")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
old_timeout = reply._timeout
def timeout(deferred):
self.channel.basic_publish(
- routing_key="test.notifications-queue.uuid1",
+ routing_key=self.queue_prefix + "uuid1",
content=content)
old_timeout(deferred)
@@ -216,9 +220,9 @@
"""
yield self.manager.connected((self.client, self.channel))
yield self.channel.queue_declare(
- queue="test.notifications-queue.uuid1")
+ queue=self.queue_prefix + "uuid1")
- reply = yield self.client.queue("test.notifications-tag.uuid1.0")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
@@ -229,7 +233,7 @@
yield assert_fails_with(d1, Empty)
# Let's wrap the queue again
- reply = yield self.client.queue("test.notifications-tag.uuid1.1")
+ reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
reply.clock = self.clock
event_queue = QueueWrapper(reply).event_queue
@@ -240,6 +244,13 @@
yield assert_fails_with(d2, Empty)
+class QueueManagerTestWithPrefix(QueueManagerTest):
+
+ prefix = "test"
+ tag_prefix = "test.notifications-tag."
+ queue_prefix = "test.notifications-queue."
+
+
class FakeMessageQueue(object):
def __init__(self):
Follow ups