本文整理汇总了Python中slimta.queue.Queue类的典型用法代码示例。如果您正苦于以下问题:Python Queue类的具体用法?Python Queue怎么用?Python Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_all
def test_load_all(self):
self.store.load().AndReturn([(3, 'one'), (5, 'two'), (1, 'three')])
self.mox.ReplayAll()
queue = Queue(self.store, self.relay)
queue._load_all()
self.assertEqual([(1, 'three'), (3, 'one'), (5, 'two')], queue.queued)
self.assertTrue(queue.wake.isSet())
示例2: test_check_ready_missing
def test_check_ready_missing(self):
self.store.get('1234').AndRaise(KeyError)
self.mox.ReplayAll()
queue = Queue(self.store, self.relay, store_pool=Pool(5))
queue._add_queued((10, '1234'))
queue._check_ready(20)
queue.store_pool.join()
示例3: test_load_all_empty
def test_load_all_empty(self):
self.store.load().AndReturn([])
self.mox.ReplayAll()
queue = Queue(self.store, self.relay)
queue._load_all()
self.assertEqual([], queue.queued)
self.assertFalse(queue.wake.isSet())
示例4: test_enqueue_wait
def test_enqueue_wait(self):
self.store.write(self.env, IsA(float)).AndReturn('1234')
self.relay._attempt(self.env, 0)
self.store.remove('1234')
self.mox.ReplayAll()
queue = Queue(self.store, self.relay, relay_pool=5)
self.assertEqual([(self.env, '1234')], queue.enqueue(self.env))
queue.relay_pool.join()
示例5: test_check_ready
def test_check_ready(self):
self.store.get('1234').AndReturn((self.env, 0))
self.relay._attempt(self.env, 0)
self.store.remove('1234')
self.mox.ReplayAll()
queue = Queue(self.store, self.relay, store_pool=Pool(5))
queue._add_queued((10, '1234'))
queue._check_ready(20)
queue.store_pool.join()
示例6: test_wait_ready_nonequeued
def test_wait_ready_nonequeued(self):
queue = Queue(self.store, self.relay)
def wait_func():
queue._wait_ready(20)
thread = gevent.spawn(wait_func)
gevent.sleep(0)
self.assertFalse(thread.ready())
queue._add_queued((10, '1234'))
gevent.sleep(0)
self.assertTrue(thread.ready())
示例7: test_enqueue_wait_permanentfail
def test_enqueue_wait_permanentfail(self):
self.store.write(self.env, IsA(float)).AndReturn('1234')
self.relay._attempt(self.env, 0).AndRaise(PermanentRelayError('permanent', Reply('550', 'permanent')))
self.store.remove('1234')
self.mox.ReplayAll()
def no_bounce(envelope, reply):
return None
queue = Queue(self.store, self.relay, bounce_factory=no_bounce, relay_pool=5)
queue.enqueue(self.env)
queue.relay_pool.join()
示例8: test_enqueue_wait_unhandledfail
def test_enqueue_wait_unhandledfail(self):
self.store.write(self.env, IsA(float)).AndReturn('1234')
self.relay._attempt(self.env, 0).AndRaise(Exception('unhandled error'))
self.store.increment_attempts('1234')
self.store.set_timestamp('1234', IsA(float))
self.mox.ReplayAll()
def backoff(envelope, attempts):
return 0
queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
queue.enqueue(self.env)
queue.relay_pool.join()
示例9: test_enqueue_wait_transientfail
def test_enqueue_wait_transientfail(self):
self.store.write(self.env, IsA(float)).AndReturn('1234')
self.relay._attempt(self.env, 0).AndRaise(TransientRelayError('transient', Reply('450', 'transient')))
self.store.increment_attempts('1234')
self.store.set_timestamp('1234', IsA(float))
self.mox.ReplayAll()
def backoff(envelope, attempts):
return 0
queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
queue.enqueue(self.env)
queue.relay_pool.join()
示例10: test_wait_store
def test_wait_store(self):
queue = Queue(self.store, self.relay, relay_pool=5)
queue.wake = self.mox.CreateMock(AsyncResult)
self.store.wait().AndReturn((1234567890, '1234'))
queue.wake.set()
self.store.wait().AndReturn(None)
self.store.wait().AndReturn((2345678901, '5678'))
queue.wake.set()
self.store.wait().AndRaise(NotImplementedError)
self.mox.ReplayAll()
queue._wait_store()
示例11: test_policies
def test_policies(self):
p1 = self.mox.CreateMock(QueuePolicy)
p2 = self.mox.CreateMock(QueuePolicy)
p1.apply(self.env)
p2.apply(self.env)
self.mox.ReplayAll()
queue = Queue(self.store, self.relay)
queue.add_policy(p1)
queue.add_policy(p2)
self.assertRaises(TypeError, queue.add_policy, None)
queue._run_policies(self.env)
示例12: test_add_queued
def test_add_queued(self):
queue = Queue(self.store, self.relay)
queue._add_queued((10, 'one'))
queue._add_queued((5, 'two'))
queue._add_queued((99, 'one'))
queue._add_queued((7, 'three'))
self.assertEqual([(5, 'two'), (7, 'three'), (10, 'one')], queue.queued)
self.assertTrue(queue.wake.isSet())
示例13: test_wait_ready_noneready
def test_wait_ready_noneready(self):
queue = Queue(self.store, self.relay)
queue._add_queued((20, '1234'))
queue.wake.clear()
def wait_func():
queue._wait_ready(10)
thread = gevent.spawn(wait_func)
gevent.sleep(0)
self.assertFalse(thread.ready())
queue._add_queued((5, '5678'))
gevent.sleep(0)
self.assertTrue(thread.ready())
示例14: test_enqueue_wait_splitpolicy
def test_enqueue_wait_splitpolicy(self):
splitpolicy1 = self.mox.CreateMock(QueuePolicy)
splitpolicy2 = self.mox.CreateMock(QueuePolicy)
regpolicy = self.mox.CreateMock(QueuePolicy)
env1 = Envelope('[email protected]', ['[email protected]'])
env2 = Envelope('[email protected]', ['[email protected]'])
env3 = Envelope('[email protected]', ['[email protected]'])
splitpolicy1.apply(self.env).AndReturn([env1, env2])
regpolicy.apply(env1)
splitpolicy2.apply(env1)
regpolicy.apply(env2)
splitpolicy2.apply(env2).AndReturn([env2, env3])
self.store.write(env1, IsA(float)).AndReturn('1234')
self.store.write(env2, IsA(float)).AndReturn('5678')
self.store.write(env3, IsA(float)).AndReturn('90AB')
self.relay._attempt(env1, 0).InAnyOrder('relay')
self.relay._attempt(env2, 0).InAnyOrder('relay')
self.relay._attempt(env3, 0).InAnyOrder('relay')
self.store.remove('1234').InAnyOrder('relay')
self.store.remove('5678').InAnyOrder('relay')
self.store.remove('90AB').InAnyOrder('relay')
self.mox.ReplayAll()
queue = Queue(self.store, self.relay, relay_pool=5)
queue.add_policy(splitpolicy1)
queue.add_policy(regpolicy)
queue.add_policy(splitpolicy2)
self.assertEqual([(env1, '1234'), (env2, '5678'), (env3, '90AB')],
queue.enqueue(self.env))
queue.relay_pool.join()
示例15: test_enqueue_wait_partial_relay_expired
def test_enqueue_wait_partial_relay_expired(self):
env = Envelope('[email protected]', ['[email protected]',
'[email protected]',
'[email protected]'])
bounce_mock = self.mox.CreateMockAnything()
bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
self.store.write(env, IsA(float)).AndReturn('1234')
self.relay._attempt(env, 0).AndReturn([TransientRelayError('transient', Reply('450', 'transient 1')),
TransientRelayError('transient', Reply('450', 'transient 1')),
TransientRelayError('transient', Reply('450', 'transient 2'))])
self.store.increment_attempts('1234')
self.store.remove('1234')
self.mox.ReplayAll()
queue = Queue(self.store, self.relay, bounce_factory=bounce_mock, relay_pool=5)
queue.enqueue(env)
queue.relay_pool.join()