本文整理汇总了Python中kombu.connection.BrokerConnection.autoretry方法的典型用法代码示例。如果您正苦于以下问题:Python BrokerConnection.autoretry方法的具体用法?Python BrokerConnection.autoretry怎么用?Python BrokerConnection.autoretry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.connection.BrokerConnection
的用法示例。
在下文中一共展示了BrokerConnection.autoretry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Connection
# 需要导入模块: from kombu.connection import BrokerConnection [as 别名]
# 或者: from kombu.connection.BrokerConnection import autoretry [as 别名]
#.........这里部分代码省略.........
def test_ensure_connection(self):
self.assertTrue(self.conn.ensure_connection())
def test_ensure_success(self):
def publish():
return "foobar"
ensured = self.conn.ensure(None, publish)
self.assertEqual(ensured(), "foobar")
def test_ensure_failure(self):
class _CustomError(Exception):
pass
def publish():
raise _CustomError("bar")
ensured = self.conn.ensure(None, publish)
with self.assertRaises(_CustomError):
ensured()
def test_ensure_connection_failure(self):
class _ConnectionError(Exception):
pass
def publish():
raise _ConnectionError("failed connection")
self.conn.transport.connection_errors = (_ConnectionError,)
ensured = self.conn.ensure(self.conn, publish)
with self.assertRaises(_ConnectionError):
ensured()
def test_autoretry(self):
myfun = Mock()
myfun.__name__ = "test_autoretry"
self.conn.transport.connection_errors = (KeyError, )
def on_call(*args, **kwargs):
myfun.side_effect = None
raise KeyError("foo")
myfun.side_effect = on_call
insured = self.conn.autoretry(myfun)
insured()
self.assertTrue(myfun.called)
def test_SimpleQueue(self):
conn = self.conn
q = conn.SimpleQueue("foo")
self.assertTrue(q.channel)
self.assertTrue(q.channel_autoclose)
chan = conn.channel()
q2 = conn.SimpleQueue("foo", channel=chan)
self.assertIs(q2.channel, chan)
self.assertFalse(q2.channel_autoclose)
def test_SimpleBuffer(self):
conn = self.conn
q = conn.SimpleBuffer("foo")
self.assertTrue(q.channel)
self.assertTrue(q.channel_autoclose)
chan = conn.channel()
q2 = conn.SimpleBuffer("foo", channel=chan)