本文整理汇总了Python中tchannel.TChannel.advertise方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.advertise方法的具体用法?Python TChannel.advertise怎么用?Python TChannel.advertise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tchannel.TChannel
的用法示例。
在下文中一共展示了TChannel.advertise方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_advertise_is_retryable
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_advertise_is_retryable(router_file):
from tchannel.tornado.response import Response as TornadoResponse
def new_advertise(*args, **kwargs):
f = gen.Future()
f.set_result(TornadoResponse(
argstreams=[closed_stream(b'{}') for i in range(3)],
))
return f
tchannel = TChannel(name='client')
with patch(
'tchannel.tornado.TChannel.advertise', autospec=True
) as mock_advertise:
f = gen.Future()
f.set_exception(Exception('great sadness'))
mock_advertise.return_value = f
with pytest.raises(Exception) as e:
yield tchannel.advertise(router_file=router_file)
assert 'great sadness' in str(e)
assert mock_advertise.call_count == 1
mock_advertise.side_effect = new_advertise
yield tchannel.advertise(router_file=router_file)
yield tchannel.advertise(router_file=router_file)
yield tchannel.advertise(router_file=router_file)
yield tchannel.advertise(router_file=router_file)
assert mock_advertise.call_count == 2
示例2: test_advertise_should_raise_on_invalid_router_file
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_advertise_should_raise_on_invalid_router_file():
tchannel = TChannel(name='client')
with pytest.raises(IOError):
yield tchannel.advertise(router_file='?~~lala')
with pytest.raises(ValueError):
yield tchannel.advertise(routers='lala', router_file='?~~lala')
示例3: test_ad_blackhole
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_ad_blackhole(blackhole, monkeypatch):
# start new ad requests more frequently
monkeypatch.setattr(hyperbahn, 'DELAY', 100) # milliseconds
monkeypatch.setattr(hyperbahn, 'PER_ATTEMPT_TIMEOUT', 5) # seconds
# No jitter
monkeypatch.setattr(hyperbahn, 'DEFAULT_INTERVAL_MAX_JITTER_SECS', 0.0)
# verify that we don't go crazy if Hyperbahn starts blackholing requests.
client = TChannel('client')
client.advertise(routers=blackhole.peers)
yield gen.sleep(0.5)
# The second ad request is still ongoing so no other ads should have been
# made.
assert 2 == blackhole.ad_count
示例4: test_advertise_should_take_a_router_file
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_advertise_should_take_a_router_file(router_file):
from tchannel.tornado.response import Response as TornadoResponse
tchannel = TChannel(name='client')
with open(router_file, 'r') as json_data:
routers = json.load(json_data)
with (
patch(
'tchannel.tornado.TChannel.advertise',
autospec=True,
)
) as mock_advertise:
f = gen.Future()
mock_advertise.return_value = f
f.set_result(TornadoResponse())
tchannel.advertise(router_file=router_file)
mock_advertise.assert_called_once_with(ANY, routers=routers,
name=ANY, timeout=ANY)
示例5: test_advertise_is_idempotent
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_advertise_is_idempotent(router_file):
from tchannel.tornado.response import Response as TornadoResponse
def new_advertise(*args, **kwargs):
f = gen.Future()
f.set_result(TornadoResponse(
argstreams=[closed_stream(b'{}') for i in range(3)],
))
return f
tchannel = TChannel(name='client')
with patch(
'tchannel.tornado.TChannel.advertise', autospec=True
) as mock_advertise:
mock_advertise.side_effect = new_advertise
yield tchannel.advertise(router_file=router_file)
yield tchannel.advertise(router_file=router_file)
yield tchannel.advertise(router_file=router_file)
assert mock_advertise.call_count == 1
示例6: test_advertise_should_take_a_router_file
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import advertise [as 别名]
def test_advertise_should_take_a_router_file():
host_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'data/hosts.json',
)
tchannel = TChannel(name='client')
with open(host_path, 'r') as json_data:
routers = json.load(json_data)
with (
patch(
'tchannel.tornado.TChannel.advertise',
autospec=True,
)
) as mock_advertise:
f = gen.Future()
mock_advertise.return_value = f
f.set_result(Response())
tchannel.advertise(router_file=host_path)
mock_advertise.assert_called_once_with(ANY, routers=routers,
name=ANY, timeout=ANY)