本文整理汇总了Python中tchannel.TChannel.listen方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.listen方法的具体用法?Python TChannel.listen怎么用?Python TChannel.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tchannel.TChannel
的用法示例。
在下文中一共展示了TChannel.listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enum
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_enum():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testEnum(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
x = ThriftTest.Numberz.FIVE
resp = yield tchannel.thrift(
service.testEnum(thing=x)
)
assert resp.headers == {}
assert resp.body == x
示例2: test_string_map
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_string_map():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testStringMap(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
x = {
'hello': 'there',
'my': 'name',
'is': 'shirly',
}
resp = yield tchannel.thrift(
service.testStringMap(thing=x)
)
assert resp.headers == {}
assert resp.body == x
示例3: test_void
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_void():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testVoid(request):
pass
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
resp = yield tchannel.thrift(service.testVoid())
assert resp.headers == {}
assert resp.body is None
示例4: test_struct
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_struct():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testStruct(request):
assert request.body.thing.string_thing == 'req string'
return ThriftTest.Xtruct(
string_thing="resp string"
)
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='service',
thrift_module=ThriftTest,
hostport=server.hostport
)
resp = yield tchannel.thrift(
service.testStruct(ThriftTest.Xtruct("req string"))
)
# verify response
assert isinstance(resp, Response)
assert resp.headers == {}
assert resp.body == ThriftTest.Xtruct("resp string")
示例5: test_map
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_map():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testMap(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
x = {
0: 1,
1: 2,
2: 3,
3: 4,
-1: -2,
}
resp = yield tchannel.thrift(
service.testMap(thing=x)
)
assert resp.headers == {}
assert resp.body == x
示例6: test_double
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_double():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testDouble(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
resp = yield tchannel.thrift(
service.testDouble(-5.235098235)
)
assert resp.headers == {}
assert resp.body == -5.235098235
示例7: test_binary
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_binary():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testBinary(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
resp = yield tchannel.thrift(
service.testBinary(
# this is ThriftTest.Xtruct(string_thing='hi')
'\x0c\x00\x00\x0b\x00\x01\x00\x00\x00\x0bhi\x00\x00'
)
)
assert resp.headers == {}
assert (
resp.body ==
'\x0c\x00\x00\x0b\x00\x01\x00\x00\x00\x0bhi\x00\x00'
)
示例8: test_i32
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_i32():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testI32(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
# case #1
resp = yield tchannel.thrift(
service.testI32(-1)
)
assert resp.headers == {}
assert resp.body == -1
# case #2
resp = yield tchannel.thrift(
service.testI32(1)
)
assert resp.headers == {}
assert resp.body == 1
示例9: test_client_for_with_sync_tchannel
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_client_for_with_sync_tchannel():
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testString(request):
return request.body.thing.encode('rot13')
server.listen()
tchannel = SyncTChannel(name='client')
client = sync_client_for('server', ThriftTest)(
tchannel=tchannel,
hostport=server.hostport,
)
future = client.testString(thing='foo')
assert not isinstance(future, concurrent.Future)
# Our server is sharing our IO loop so let it handle the
# request.
while not future.done():
yield gen.moment
resp = future.result()
assert resp == 'sbb'
示例10: test_value_expected_but_none_returned_should_error
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_value_expected_but_none_returned_should_error():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testString(request):
pass
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
with pytest.raises(ValueExpectedError):
yield tchannel.thrift(
service.testString('no return!?')
)
示例11: test_type_def
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_type_def():
# Given this test server:
server = TChannel(name='server')
@server.thrift.register(ThriftTest)
def testTypedef(request):
return request.body.thing
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
x = 0xffffffffffffff # 7 bytes of 0xff
resp = yield tchannel.thrift(
service.testTypedef(thing=x)
)
assert resp.headers == {}
assert resp.body == x
示例12: test_oneway
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def test_oneway():
# Given this test server:
server = TChannel(name='server')
# TODO - server should raise same exception as client
with pytest.raises(AssertionError):
@server.thrift.register(ThriftTest)
def testOneway(request):
pass
server.listen()
# Make a call:
tchannel = TChannel(name='client')
service = thrift_request_builder(
service='server',
thrift_module=ThriftTest,
hostport=server.hostport,
)
with pytest.raises(OneWayNotSupportedError):
yield tchannel.thrift(service.testOneway(1))
示例13: proxy_server
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [as 别名]
def proxy_server(keyvalue_server):
server = TChannel(name='keyvalue-proxy')
server.listen()
# The client that the proxy uses to make requests should be a different
# TChannel. That's because TChannel treats all peers (incoming and
# outgoing) as the same. So, if the server receives a request and then
# uses the same channel to make the request, there's a chance that it gets
# forwarded back to the peer that originally made the request.
#
# This is desirable behavior because we do want to treat all Hyperbahn
# nodes as equal.
proxy_server_client = TChannel(
name='proxy-client', known_peers=[keyvalue_server.hostport],
)
@server.register(TChannel.FALLBACK)
@gen.coroutine
def handler(request):
response = yield proxy_server_client.call(
scheme=request.transport.scheme,
service=request.service,
arg1=request.endpoint,
arg2=request.headers,
arg3=request.body,
timeout=request.timeout / 2,
retry_on=request.transport.retry_flags,
retry_limit=0,
shard_key=request.transport.shard_key,
routing_delegate=request.transport.routing_delegate,
)
raise gen.Return(response)
return server
示例14: test_headers_and_body_should_be_optional
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [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
示例15: test_endpoint_can_return_just_body
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import listen [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'