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


Python TChannel.call方法代码示例

本文整理汇总了Python中tchannel.TChannel.call方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.call方法的具体用法?Python TChannel.call怎么用?Python TChannel.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tchannel.TChannel的用法示例。


在下文中一共展示了TChannel.call方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_headers_and_body_should_be_optional

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_headers_and_body_should_be_optional():

    # Given this test server:

    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    def endpoint(request):
        # assert request.headers is None  # TODO uncomment
        # assert request.body is None  # TODO uncomment
        pass

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    resp = yield tchannel.call(
        scheme=schemes.RAW,
        service='server',
        arg1='endpoint',
        hostport=server.hostport,
    )

    # verify response
    assert isinstance(resp, Response)
    assert resp.headers == ''  # TODO should be None to match server
    assert resp.body == ''  # TODO should be None to match server
开发者ID:Willyham,项目名称:tchannel-python,代码行数:31,代码来源:test_tchannel.py

示例2: test_endpoint_can_return_just_body

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_endpoint_can_return_just_body():

    # Given this test server:

    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    def endpoint(request):
        return 'resp body'

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    resp = yield tchannel.call(
        scheme=schemes.RAW,
        service='server',
        arg1='endpoint',
        hostport=server.hostport,
    )

    # verify response
    assert isinstance(resp, Response)
    assert resp.headers == ''  # TODO should be is None to match server
    assert resp.body == 'resp body'
开发者ID:Willyham,项目名称:tchannel-python,代码行数:29,代码来源:test_tchannel.py

示例3: test_timeout_should_raise_timeout_error

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_timeout_should_raise_timeout_error():

    # Given this test server:

    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    @gen.coroutine
    def endpoint(request):
        yield gen.sleep(0.05)
        raise gen.Return('hello')

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    # timeout is less than server, should timeout
    with pytest.raises(TimeoutError):
        yield tchannel.call(
            scheme=schemes.RAW,
            service='server',
            arg1='endpoint',
            hostport=server.hostport,
            timeout=0.02,
        )

    # timeout is more than server, should not timeout
    yield tchannel.raw(
        service='server',
        endpoint='endpoint',
        hostport=server.hostport,
        timeout=0.1,
    )
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:37,代码来源:test_tchannel.py

示例4: test_error_trace

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_error_trace():
    tchannel = TChannel('test')

    class ErrorEventHook(EventHook):
        def __init__(self):
            self.request_trace = None
            self.error_trace = None

        def before_receive_request(self, request):
            self.request_trace = request.tracing

        def after_send_error(self, error):
            self.error_trace = error.tracing

    hook = ErrorEventHook()
    tchannel.hooks.register(hook)

    tchannel.listen()

    with pytest.raises(BadRequestError):
        yield tchannel.call(
            scheme=schemes.RAW,
            service='test',
            arg1='endpoint',
            hostport=tchannel.hostport,
            timeout=0.02,
        )

    assert hook.error_trace
    assert hook.request_trace
    assert hook.error_trace == hook.request_trace
开发者ID:encrylife,项目名称:tchannel-python,代码行数:33,代码来源:test_trace.py

示例5: test_after_send_error_event_called

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_after_send_error_event_called():
    tchannel = TChannel('test')
    tchannel.listen()
    with mock.patch(
        'tchannel.event.EventEmitter.fire', autospec=True,
    ) as mock_fire:
        mock_fire.return_value = None
        with pytest.raises(BadRequestError):
            yield tchannel.call(
                scheme=schemes.RAW,
                service='test',
                arg1='endpoint',
                hostport=tchannel.hostport,
                timeout=0.3,
            )
        mock_fire.assert_any_call(
            mock.ANY, EventType.after_send_error, mock.ANY,
        )
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:20,代码来源:test_event.py

示例6: test_endpoint_can_be_called_as_a_pure_func

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_endpoint_can_be_called_as_a_pure_func():

    # Given this test server:

    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    def endpoint(request):

        assert isinstance(request, Request)
        assert request.body == 'req body'
        assert request.headers == 'req headers'

        return Response('resp body', headers='resp headers')

    server.listen()

    # Able to call over TChannel

    tchannel = TChannel(name='client')

    resp = yield tchannel.call(
        scheme=schemes.RAW,
        service='server',
        arg1='endpoint',
        arg2='req headers',
        arg3='req body',
        hostport=server.hostport,
    )

    assert isinstance(resp, Response)
    assert resp.headers == 'resp headers'
    assert resp.body == 'resp body'

    # Able to call as function

    resp = endpoint(Request('req body', headers='req headers'))

    assert isinstance(resp, Response)
    assert resp.headers == 'resp headers'
    assert resp.body == 'resp body'
开发者ID:Willyham,项目名称:tchannel-python,代码行数:43,代码来源:test_tchannel.py

示例7: test_response_status_is_copied

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_response_status_is_copied():
    server = TChannel(name='server')
    server.listen()

    @server.register(TChannel.FALLBACK)
    def handler(request):
        return Response(
            status=1,
            headers=b'\x00\x00',
            body=b'\x00',
        )

    client = TChannel(name='client', known_peers=[server.hostport])
    response = yield client.call(
        scheme='thrift',
        service='server',
        arg1='hello',
        arg2=b'\x00\x00',
        arg3=b'\x00',
    )
    assert 1 == response.status
开发者ID:uber,项目名称:tchannel-python,代码行数:23,代码来源:test_tchannel.py

示例8: test_context_should_carry_tracing_info

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_context_should_carry_tracing_info():
    context = [None, None]
    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    @gen.coroutine
    def endpoint1(request):
        yield server.call(
            scheme=schemes.RAW,
            service='server',
            arg1='endpoint2',
            arg2='req headers',
            arg3='req body',
            hostport=server.hostport,
        )
        context[0] = get_current_context()
        raise gen.Return(Response('resp body', 'resp headers'))

    @server.register(scheme=schemes.RAW)
    def endpoint2(request):
        context[1] = get_current_context()
        return Response('resp body', 'resp headers')

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    yield tchannel.call(
        scheme=schemes.RAW,
        service='server',
        arg1='endpoint1',
        arg2='req headers',
        arg3='req body',
        hostport=server.hostport,
    )

    assert context[0].parent_tracing.name == 'endpoint1'
    assert context[1].parent_tracing.name == 'endpoint2'
开发者ID:kumikoda,项目名称:tchannel-python,代码行数:42,代码来源:test_context.py

示例9: test_call_should_get_response

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import call [as 别名]
def test_call_should_get_response():

    # Given this test server:

    server = TChannel(name='server')

    @server.register(scheme=schemes.RAW)
    def endpoint(request):

        assert isinstance(request, Request)
        assert request.headers == 'req headers'
        assert request.body == 'req body'

        return Response('resp body', 'resp headers')

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    resp = yield tchannel.call(
        scheme=schemes.RAW,
        service='server',
        arg1='endpoint',
        arg2='req headers',
        arg3='req body',
        hostport=server.hostport,
    )

    # verify response
    assert isinstance(resp, Response)
    assert resp.headers == 'resp headers'
    assert resp.body == 'resp body'

    # verify response transport headers
    assert isinstance(resp.transport, TransportHeaders)
    assert resp.transport.scheme == schemes.RAW
    assert resp.transport.failure_domain is None
开发者ID:Willyham,项目名称:tchannel-python,代码行数:41,代码来源:test_tchannel.py


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