本文整理汇总了Python中tchannel.thrift.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inherited_method_names
def test_inherited_method_names(tmpdir):
thrift_file = tmpdir.join('service.thrift')
thrift_file.write('''
service Base { string hello() }
service Foo extends Base {}
service Bar extends Base {}
''')
service = thrift.load(str(thrift_file), 'myservice')
server = TChannel('server')
@server.thrift.register(service.Foo, method='hello')
def foo_hello(request):
return 'foo'
@server.thrift.register(service.Bar, method='hello')
def bar_hello(request):
return 'bar'
server.listen()
client = TChannel('client')
res = yield client.thrift(service.Foo.hello(), hostport=server.hostport)
assert res.body == 'foo'
res = yield client.thrift(service.Bar.hello(), hostport=server.hostport)
assert res.body == 'bar'
示例2: test_service_inheritance
def test_service_inheritance(tmpdir):
path = tmpdir.join('myservice.thrift')
path.write('''
service Base { bool healthy() }
service MyService extends Base {
i32 getValue()
}
''')
service = thrift.load(str(path), service='myservice')
server = TChannel('server')
server.listen()
@server.thrift.register(service.MyService)
def getValue(request):
return 42
@server.thrift.register(service.MyService)
def healthy(request):
return True
client = TChannel('client', known_peers=[server.hostport])
response = yield client.thrift(service.MyService.getValue())
assert response.body == 42
response = yield client.thrift(service.MyService.healthy())
assert response.body is True
示例3: test_thriftrw_client_without_service_or_hostport_specified
def test_thriftrw_client_without_service_or_hostport_specified():
client = thrift.load(
'tests/data/idls/ThriftTest.thrift',
)
with pytest.raises(ValueError):
client.ThriftTest.testVoid()
示例4: test_service_inheritance_with_import
def test_service_inheritance_with_import(tmpdir):
tmpdir.join('shared/base.thrift').write(
'service Base { bool healthy() }', ensure=True
)
inherited = tmpdir.join('myservice.thrift')
inherited.write('''
include "./shared/base.thrift"
service MyService extends base.Base {
i32 getValue()
}
''')
service = thrift.load(str(inherited), service='myservice')
server = TChannel('server')
@server.thrift.register(service.MyService)
def getValue(request):
return 42
@server.thrift.register(service.MyService)
def healthy(request):
return True
server.listen()
client = TChannel('client', known_peers=[server.hostport])
response = yield client.thrift(service.MyService.getValue())
assert response.body == 42
response = yield client.thrift(service.MyService.healthy())
assert response.body is True
示例5: test_thriftrw_client_with_service_or_hostport_specified
def test_thriftrw_client_with_service_or_hostport_specified(hostport, service):
client = thrift.load(
'tests/data/idls/ThriftTest.thrift',
hostport=hostport,
service=service,
)
assert client.ThriftTest.testVoid()
示例6: thrift_module
def thrift_module(tmpdir, request):
thrift_file = tmpdir.join('service.thrift')
thrift_file.write('''
service Service {
bool healthy()
}
''')
return thrift.load(str(thrift_file), request.node.name)
示例7: client_ttypes
def client_ttypes(use_thriftrw_client):
"""Provides access to generated types for the server."""
if use_thriftrw_client:
return thrift.load(
path='tests/data/idls/ThriftTest.thrift',
)
else:
return _ttypes
示例8: ThriftTest
def ThriftTest(use_thriftrw_server):
"""Used by servers to register endpoints for ThriftTest."""
if use_thriftrw_server:
return thrift.load(
'tests/data/idls/ThriftTest.thrift',
).ThriftTest
else:
return _ThriftTest
示例9: SecondService
def SecondService(use_thriftrw_server):
"""Used by servers to register endpoints for SecondService."""
if use_thriftrw_server:
return thrift.load(
'tests/data/idls/ThriftTest.thrift',
).SecondService
else:
return _SecondService
示例10: request_thrift
def request_thrift(tchannel, hostport):
ThriftTest = thrift.load(
path='tests/data/idls/ThriftTest.thrift',
service='server',
).SecondService
return tchannel.thrift(
ThriftTest.blahBlah(),
hostport=hostport,
)
示例11: register_thrift
def register_thrift(tchannel):
ThriftTest = thrift.load(
path='tests/data/idls/ThriftTest.thrift',
service='server',
).SecondService
@tchannel.thrift.register(ThriftTest)
def hello(request):
return
示例12: test_default_checksum_type
def test_default_checksum_type():
server = TChannel("server")
server.listen()
with mock.patch("tchannel.messages.common.compute_checksum", autospec=True) as mock_compute_checksum:
client = TChannel("client")
service = thrift.load(
path="tchannel/health/meta.thrift", service="health_test_server", hostport=server.hostport
)
with pytest.raises(FatalProtocolError):
yield client.thrift(service.Meta.health())
mock_compute_checksum.assert_called_with(ChecksumType.crc32c, mock.ANY, mock.ANY)
示例13: thrift_service
def thrift_service(tmpdir):
thrift_file = tmpdir.join('service.thrift')
thrift_file.write('''
service X {
string thrift1(1: string hostport), // calls thrift2()
string thrift2(),
string thrift3(1: string hostport) // calls http
string thrift4(1: string hostport) // calls raw
}
''')
return thrift.load(str(thrift_file), 'test-service')
示例14: keyvalue
def keyvalue(tmpdir):
path = tmpdir.join('keyvalue.thrift')
path.write('''
exception ItemDoesNotExist {
1: optional string key
}
service KeyValue {
string getItem(1: string key)
throws (1: ItemDoesNotExist doesNotExist)
}
''')
return thrift.load(str(path), service='keyvalue')
示例15: second_service
def second_service(server, use_thriftrw_client):
"""Used by clients to build requests to SecondService."""
if use_thriftrw_client:
return thrift.load(
path='tests/data/idls/ThriftTest.thrift',
service='server',
hostport=server.hostport,
).SecondService
else:
return thrift_request_builder(
service='server',
thrift_module=_SecondService,
hostport=server.hostport,
)