当前位置: 首页>>代码示例>>Python>>正文


Python TChannel.advertise方法代码示例

本文整理汇总了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
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:32,代码来源:test_tchannel.py

示例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')
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:10,代码来源:test_tchannel.py

示例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
开发者ID:uber,项目名称:tchannel-python,代码行数:18,代码来源:test_hyperbahn_blackhole.py

示例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)
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:22,代码来源:test_tchannel.py

示例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
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:23,代码来源:test_tchannel.py

示例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)
开发者ID:cc13ny,项目名称:tchannel-python,代码行数:26,代码来源:test_tchannel.py


注:本文中的tchannel.TChannel.advertise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。