本文整理汇总了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
示例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'
示例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,
)
示例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
示例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,
)
示例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'
示例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
示例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'
示例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