本文整理汇总了Python中tchannel.tornado.TChannel.request方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.request方法的具体用法?Python TChannel.request怎么用?Python TChannel.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tchannel.tornado.TChannel
的用法示例。
在下文中一共展示了TChannel.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zipkin_trace
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_zipkin_trace(trace_server):
endpoint = b'endpoint1'
zipkin_tracer = ZipkinTraceHook(dst=trace_buf)
tchannel = TChannel(name='test')
tchannel.hooks.register(zipkin_tracer)
hostport = 'localhost:%d' % trace_server.port
response = yield tchannel.request(hostport).send(InMemStream(endpoint),
InMemStream(hostport),
InMemStream(),
traceflag=True)
header = yield response.get_header()
body = yield response.get_body()
assert header == "from handler1"
assert body == "from handler2"
traces = []
for trace in trace_buf.getvalue().split("\n"):
if trace:
traces.append(json.loads(trace))
trace_id = traces[0][0][u'trace_id']
for trace in traces:
assert trace_id == trace[0][u'trace_id']
if trace[0][u'name'] == u'endpoint2':
parent_span_id = trace[0][u'parent_span_id']
else:
span_id = trace[0][u'span_id']
assert parent_span_id == span_id
示例2: test_request
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_request():
channel = TChannel(name="test")
hyperbahn.advertise(channel, "foo", ["127.0.0.1:23000"])
# Just want to make sure all the plumbing fits together.
with pytest.raises(NoAvailablePeerError):
yield channel.request(service="bar").send(arg1="baz", arg2="bam", arg3="boo", headers={"as": "qux"})
示例3: test_endpoint_not_found
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_endpoint_not_found(tchannel_server):
endpoint = b"tchanneltest"
tchannel_server.expect_call(endpoint).and_write(headers=endpoint, body="world")
tchannel = TChannel(name="test")
hostport = "localhost:%d" % (tchannel_server.port)
with pytest.raises(TChannelError):
yield tchannel.request(hostport).send(InMemStream(), InMemStream(), InMemStream())
示例4: send_stream
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def send_stream(arg1, arg2, arg3, host):
tchannel = TChannel()
response = yield tchannel.request(host).send(
arg1,
arg2,
arg3)
yield print_arg(response, 0)
yield print_arg(response, 1)
yield print_arg(response, 2)
示例5: send_stream
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def send_stream(arg1, arg2, arg3, host):
tchannel = TChannel(
name='stream-client',
)
yield tchannel.request(host).send(
arg1,
arg2,
arg3,
)
示例6: test_request
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_request():
channel = TChannel()
hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])
# Just want to make sure all the plumbing fits together.
with pytest.raises(ConnectionClosedError):
yield channel.request(service='bar').send(
arg1='baz',
arg2='bam',
arg3='boo',
headers={'as': 'qux'},
)
示例7: test_endpoint_not_found
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_endpoint_not_found(mock_server):
endpoint = b'tchanneltest'
mock_server.expect_call(endpoint).and_write(
headers=endpoint,
body='world'
)
tchannel = TChannel(name='test')
with pytest.raises(TChannelError):
yield tchannel.request(
mock_server.hostport
).send(InMemStream(), InMemStream(), InMemStream())
示例8: main
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def main():
args = get_args()
tchannel = TChannel(name="raw-client")
request = tchannel.request(hostport="%s:%s" % (args.host, args.port))
response = yield request.send("hi", None, None)
body = yield response.get_body()
print body
示例9: test_endpoint_not_found
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_endpoint_not_found(tchannel_server):
endpoint = b'tchanneltest'
tchannel_server.expect_call(endpoint).and_write(
headers=endpoint,
body='world'
)
tchannel = TChannel()
hostport = 'localhost:%d' % (tchannel_server.port)
with pytest.raises(TChannelError):
yield tchannel.request(hostport).send(InMemStream(),
InMemStream(),
InMemStream())
示例10: test_tchannel_call_request_fragment
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_tchannel_call_request_fragment(tchannel_server, arg2, arg3):
endpoint = b"tchannelpeertest"
tchannel_server.expect_call(endpoint).and_write(headers=endpoint, body=arg3)
tchannel = TChannel(name="test")
hostport = "localhost:%d" % (tchannel_server.port)
response = yield tchannel.request(hostport).send(InMemStream(endpoint), InMemStream(arg2), InMemStream(arg3))
header = yield response.get_header()
body = yield response.get_body()
assert header == endpoint
assert body == arg3
assert response.headers["as"] == "raw"
示例11: test_tchannel_call_request_fragment
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_tchannel_call_request_fragment(mock_server,
arg2, arg3):
endpoint = b'tchannelpeertest'
mock_server.expect_call(endpoint).and_write(
headers=endpoint, body=arg3
)
tchannel = TChannel(name='test')
response = yield tchannel.request(mock_server.hostport).send(
InMemStream(endpoint), InMemStream(arg2), InMemStream(arg3)
)
header = yield response.get_header()
body = yield response.get_body()
assert header == endpoint
assert body == arg3
assert response.headers['as'] == 'raw'
示例12: test_false_result
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_false_result(thrift_service):
# Verify that we aren't treating False as None.
app = TChannel(name='app')
@app.register(thrift_service)
def healthy(request, response):
return False
app.listen()
client = TChannel(name='client')
response = yield client.request(
hostport=app.hostport, arg_scheme='thrift'
).send('Service::healthy', '\x00\x00', '\x00')
body = yield response.get_body()
assert body == '\x02\x00\x00\x00\x00'
示例13: test_json_server
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_json_server(json_server, sample_json):
endpoint = "json_echo"
tchannel = TChannel(name='test')
hostport = 'localhost:%d' % json_server.port
client = tchannel.request(hostport)
header = sample_json
body = sample_json
resp = yield ArgSchemeBroker(JsonArgScheme()).send(
client,
endpoint,
header,
body,
)
# compare header's json
rheader = yield resp.get_header()
assert rheader == header
# compare body's json
rbody = yield resp.get_body()
assert rbody == body
示例14: test_json_server
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_json_server(json_server, sample_json):
endpoint = "json_echo"
tchannel = TChannel(name='test')
client = tchannel.request(json_server.hostport)
header = sample_json
body = sample_json
resp = yield ArgSchemeBroker(JsonArgScheme()).send(
client,
endpoint,
header,
body,
)
# check protocol header
assert resp.headers['as'] == 'json'
# compare header's json
rheader = yield resp.get_header()
assert rheader == header
# compare body's json
rbody = yield resp.get_body()
assert rbody == body
示例15: test_patching_as_context_manager
# 需要导入模块: from tchannel.tornado import TChannel [as 别名]
# 或者: from tchannel.tornado.TChannel import request [as 别名]
def test_patching_as_context_manager():
chan = TChannel('client')
with Patcher('localhost:4040'):
ops = chan.request(service='foo')
assert isinstance(ops, PatchedClientOperation)
assert ops.vcr_hostport == 'localhost:4040'