本文整理汇总了Python中hotqueue.HotQueue.ack方法的典型用法代码示例。如果您正苦于以下问题:Python HotQueue.ack方法的具体用法?Python HotQueue.ack怎么用?Python HotQueue.ack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hotqueue.HotQueue
的用法示例。
在下文中一共展示了HotQueue.ack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HotQueueTestCase
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import ack [as 别名]
class HotQueueTestCase(unittest.TestCase):
def setUp(self):
"""Create the queue instance before the test."""
self.queue = HotQueue('testqueue')
def tearDown(self):
"""Clear the queue after the test."""
self.queue.clear()
def test_arguments(self):
"""Test that HotQueue.__init__ accepts arguments correctly, and that
the Redis key is correctly formed.
"""
kwargs = {
'name': "testqueue",
'serializer': DummySerializer,
'host': "localhost",
'port': 6379,
'db': 0}
# Instantiate the HotQueue instance:
self.queue = HotQueue(**kwargs)
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertEqual(self.queue.serializer, kwargs['serializer'])
# Instantiate a HotQueue instance with only the required args:
self.queue = HotQueue(kwargs['name'])
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertTrue(self.queue.serializer is pickle) # Defaults to cPickle
# or pickle, depending
# on the platform.
def test_consume(self):
"""Test the consume generator method."""
nums = [1, 2, 3, 4, 5, 6, 7, 8]
# Test blocking with timeout:
nums_added = self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(timeout=1):
msgs.append(msg)
self.assertEqual(msgs, nums_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
# Test non-blocking:
nums_added = self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(block=False):
msgs.append(msg)
self.assertEqual(msgs, nums_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
def test_nack(self):
"""Test the consume generator method."""
nums_added = self.queue.put("1")
msg = self.queue.get() #1
self.assertEqual(msg, nums_added[0])
self.queue.nack(msg.get_reservationId())
msg = self.queue.get() #2
self.assertEqual(msg, nums_added[0])
self.queue.nack(msg.get_reservationId())
msg = self.queue.get() #3
if msg:
self.assertEqual(msg, nums_added[0])
self.queue.ack(msg.get_reservationId())
self.assertEqual(msg, nums_added[0])
self.assertEqual(len(self.queue), 0)
self.assertEqual(msg.get_deliveryCount(),3) #3
def test_cleared(self):
"""Test for correct behaviour if the Redis list does not exist."""
self.assertEqual(len(self.queue), 0)
self.assertEqual(self.queue.get(), None)
def test_get_order(self):
"""Test that messages are get in the same order they are put."""
alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
msg_added = []
msg_added.extend(self.queue.put(alphabet[0], alphabet[1], alphabet[2]))
msg_added.extend(self.queue.put(alphabet[3]))
msg_added.extend(self.queue.put(alphabet[4]))
msgs = []
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
self.assertEqual(msgs, msg_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
def test_length(self):
"""Test that the length of a queue is returned correctly."""
self.queue.put('a message')
self.queue.put('another message')
self.assertEqual(len(self.queue), 2)
#.........这里部分代码省略.........