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
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'
def test_thriftrw_client_without_service_or_hostport_specified(): client = thrift.load( 'tests/data/idls/ThriftTest.thrift', ) with pytest.raises(ValueError): client.ThriftTest.testVoid()
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
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
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
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
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
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()
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)
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
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
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
def request_thrift(tchannel, hostport): ThriftTest = thrift.load( path='tests/data/idls/ThriftTest.thrift', service='server', ).SecondService return tchannel.thrift( ThriftTest.blahBlah(), hostport=hostport, )
def register_thrift(tchannel): ThriftTest = thrift.load( path='tests/data/idls/ThriftTest.thrift', service='server', ).SecondService @tchannel.thrift.register(ThriftTest) def hello(request): return
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')
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)
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')
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, )
def test_default_health(): server = TChannel("health_test_server") server.listen() client = TChannel("health_test_client") service = thrift.load( path='tchannel/health/meta.thrift', service='health_test_server', hostport=server.hostport, ) resp = yield client.thrift(service.Meta.health()) assert resp.body.ok is True assert resp.body.message is None
def test_routing_delegate_is_propagated_thrift(tmpdir): tmpdir.join('service.thrift').write('service Service { bool healthy() }') thrift_module = thrift.load(str(tmpdir.join('service.thrift')), service='service') server = TChannel('server') server.listen() @server.thrift.register(thrift_module.Service) def healthy(request): assert request.transport.routing_delegate == 'delegate' return True client = TChannel('client', known_peers=[server.hostport]) res = yield client.thrift(thrift_module.Service.healthy(), routing_delegate='delegate') assert res.body is True
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, )
def test_routing_delegate_is_propagated_thrift(tmpdir): tmpdir.join('service.thrift').write('service Service { bool healthy() }') thrift_module = thrift.load(str(tmpdir.join('service.thrift')), service='service') server = TChannel('server') server.listen() @server.thrift.register(thrift_module.Service) def healthy(request): assert request.transport.routing_delegate == 'delegate' return True client = TChannel('client', known_peers=[server.hostport]) res = yield client.thrift( thrift_module.Service.healthy(), routing_delegate='delegate' ) assert res.body is True
def test_user_health(): server = TChannel("health_test_server") @server.thrift.register(Meta, method="health") def user_health(request): return HealthStatus(ok=False, message="from me") server.listen() client = TChannel("health_test_client") service = thrift.load( path='tchannel/health/meta.thrift', service='health_test_server', hostport=server.hostport, ) resp = yield client.thrift(service.Meta.health()) assert resp.body.ok is False assert resp.body.message == "from me"
def real_call_downstream_tchannel(self, span, trace_request, trace_response, response_writer): def handle_response(f): response = f.result() trace_response.downstream = response.body response_writer.write(serializer.obj_to_json(trace_response)) response_writer.finish() downstream = trace_request.downstream # XXX cache these service = thrift.load(idl_path, service=downstream.serviceName) jtr = JoinTraceRequest(trace_request.serverRole, downstream.downstream) jtr = join_trace_request_to_thriftrw(service, jtr) # with context.RequestContext(span): with context.request_context(span): f = tchannel.thrift(service.TracedService.joinTrace(jtr), hostport="%s:%s" % (downstream.host, downstream.port)) tornado.ioloop.IOLoop.current().add_future(f, handle_response)
def test_req_body_is_wire_compat_with_tchannel(service): args = { 'string_thing': 'hi', 'byte_thing': 1, 'i32_thing': -1, 'i64_thing': -34359738368, } # serialize object using yarpc's thrift.load xtruct = service.Xtruct(**args) req_body = service.ThriftTest.testStruct(xtruct) wire = req_body.__thrift_module__.dumps(req_body) # non-enveloped # now serialize using tchannel's thrift.load tch_service = tch_thrift.load(idl, service='...', hostport='...') tch_xtruct = tch_service.Xtruct(**args) tch_req_body = tch_service.ThriftTest.testStruct(tch_xtruct) tch_serializer = tch_req_body.get_serializer() tch_wire = tch_serializer.serialize_body(tch_req_body.call_args) assert wire == tch_wire
def load_frontend(env=''): if env is None or env.lower().startswith('prod') or env.lower().startswith('dev'): env = '' if env in frontend_modules: return frontend_modules[env] service_name = default_service_name if env: service_name += '_' service_name += env frontend_modules[env] = thrift.load( path=os.path.join( os.path.dirname(__file__), thrift_file, ), service=service_name, ) return frontend_modules[env]
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import absolute_import import mock import tornado.gen import pytest from tchannel import TChannel, thrift from tchannel.tcurl import _catch_errors from tchannel.tcurl import main from tchannel.tcurl import parse_args import six service = thrift.load('tests/data/idls/ThriftTest.thrift') @pytest.mark.parametrize('input, expectations', [ ([ '-p', 'localhost:54496', '-s', 'larry', '--headers', '{"req": "header"}', '--body', '{"req": "body"}', '--endpoint', 'foo', ],
def test_load_backwards_compatibility(args, kwargs): """We initially required a ``service`` argument to always be provided.""" assert thrift.load(*args, **kwargs).ThriftTest
# in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import absolute_import import os import sys from tchannel import thrift sys.modules[__name__] = thrift.load( path=os.path.join( os.path.dirname(__file__), '../idl/cherami.thrift', ), service='cherami-outputhost', )
def test_forwarding(tmpdir): from tornado import gen path = tmpdir.join('keyvalue.thrift') path.write(''' exception ItemDoesNotExist { 1: optional string key } service KeyValue { string getItem(1: string key) throws (1: ItemDoesNotExist doesNotExist) } ''') kv = thrift.load(str(path), service='keyvalue') real_server = TChannel(name='real_server') real_server.listen() items = {} @real_server.thrift.register(kv.KeyValue) def getItem(request): assert request.service == 'keyvalue' key = request.body.key if key in items: assert request.headers == {'expect': 'success'} return items[key] else: assert request.headers == {'expect': 'failure'} raise kv.ItemDoesNotExist(key) @real_server.json.register('putItem') def json_put_item(request): assert request.service == 'keyvalue' assert request.timeout == 0.5 key = request.body['key'] value = request.body['value'] items[key] = value return {'success': True} proxy_server = TChannel(name='proxy_server') 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=[real_server.hostport], ) @proxy_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) client = TChannel(name='client', known_peers=[proxy_server.hostport]) with pytest.raises(kv.ItemDoesNotExist): response = yield client.thrift( kv.KeyValue.getItem('foo'), headers={'expect': 'failure'}, ) json_response = yield client.json('keyvalue', 'putItem', { 'key': 'hello', 'value': 'world', }, timeout=1.0) assert json_response.body == {'success': True} response = yield client.thrift( kv.KeyValue.getItem('hello'), headers={'expect': 'success'}, ) assert response.body == 'world'
def keyvalue(tmpdir, request): thrift_file = get_thrift_file(tmpdir) return thrift.load(request.node.name, str(thrift_file))
# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from tornado import ioloop, gen from tchannel import TChannel, thrift service = thrift.load( path='examples/guide/keyvalue/service.thrift', service='benchmark-server', ) def test_roundtrip(benchmark): loop = ioloop.IOLoop.current() server = TChannel('benchmark-server') server.listen() clients = [TChannel('benchmark-client') for _ in range(10)] @server.thrift.register(service.KeyValue) def getValue(request): return 'bar'
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import absolute_import from __future__ import print_function import json from tchannel import thrift from tchannel.sync import TChannel from six.moves import range tchannel = TChannel('thrift-client') service = thrift.load( path='tests/data/idls/ThriftTest.thrift', service='thrift-server', hostport='localhost:54498', ) def make_requests(): # Fan-out futures = [ tchannel.thrift( request=service.ThriftTest.testString(thing="req"), headers={ 'req': 'header', }, ) for _ in range(20) ]
DefaultClientPortHTTP = 8080 DefaultServerPortHTTP = 8081 DefaultServerPortTChannel = 8082 tchannel_supported = False # Tchannel initialization. class OpenTracingHook(event.EventHook): def before_send_request(self, request): print 'before_send_request: trace_id: %x, span_id: %x' % \ (request.tracing.trace_id, request.tracing.span_id) idl_path = 'idl/thrift/crossdock/tracetest.thrift' service = thrift.load(path=idl_path, service='python') tchannel = TChannel('python', hostport="0:%d" % DefaultServerPortTChannel, trace=True) tchannel.hooks.register(OpenTracingHook()) def serve(): '''main entry point''' print "Python Tornado Crossdock Server Running ..." tchannel.listen() app = make_app(Server()) app.listen(DefaultClientPortHTTP) app.listen(DefaultServerPortHTTP) tornado.ioloop.IOLoop.current().start() # Tornado Stuff
def get_thrift_service(service_name): if service_name in thrift_services: return thrift_services[service_name] thrift_service = thrift.load(path=idl_path, service=service_name) thrift_services[service_name] = thrift_service return thrift_service
# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import absolute_import from tornado import gen, ioloop from tchannel import TChannel, Response, thrift tchannel = TChannel("thrift-server", hostport="localhost:54497") service = thrift.load("tests/data/idls/ThriftTest.thrift") @tchannel.thrift.register(service.ThriftTest) @gen.coroutine def testString(request): assert request.headers == {"req": "header"} assert request.body.thing == "req" return Response("resp", headers={"resp": "header"}) tchannel.listen() print tchannel.hostport
# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from tornado import gen, ioloop from tchannel import TChannel, thrift tchannel = TChannel('keyvalue-consumer') service = thrift.load( path='examples/guide/keyvalue/service.thrift', service='keyvalue-server', hostport='localhost:8889', ) @gen.coroutine def run(): yield tchannel.thrift(service.KeyValue.setValue("foo", "Hello, world!"), ) response = yield tchannel.thrift(service.KeyValue.getValue("foo"), ) print response.body if __name__ == '__main__':
# in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import absolute_import, unicode_literals, print_function import os import sys from tchannel import thrift tcollector = thrift.load( os.path.join(os.path.dirname(__file__), 'tcollector.thrift'), service='tcollector', ) # Replace this module with the generated module. sys.modules[__name__] = tcollector
# all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from tornado import ioloop, gen from tchannel import TChannel, thrift service = thrift.load( path='examples/guide/keyvalue/service.thrift', service='benchmark-server', ) def test_roundtrip(benchmark): loop = ioloop.IOLoop.current() server = TChannel('benchmark-server') server.listen() clients = [TChannel('benchmark-client') for _ in range(10)] @server.thrift.register(service.KeyValue) def getValue(request): return 'bar'
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import json from tornado import gen from tornado import ioloop from tchannel import TChannel, thrift tchannel = TChannel('thrift-client') service = thrift.load( path='tests/data/idls/ThriftTest.thrift', service='thrift-server', hostport='localhost:54497', ) @gen.coroutine def make_request(): resp = yield tchannel.thrift( request=service.ThriftTest.testString(thing="req"), headers={ 'req': 'header', }, ) raise gen.Return(resp)
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import sys import threading from tornado import gen, ioloop from tchannel import TChannel, thrift tchannel = TChannel('thrift-benchmark-client') service = thrift.load( path='examples/guide/keyvalue/service.thrift', service='thrift-benchmark', hostport='localhost:12345', ) local = threading.local() local.requests = 0 def report_work(): print local.requests sys.stdout.flush() local.requests = 0 @gen.coroutine def do_work():
# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from tornado import ioloop from tchannel import TChannel, thrift tchannel = TChannel('keyvalue-server', hostport='localhost:12345') service = thrift.load('examples/guide/keyvalue/service.thrift') values = {'hello': 'world'} @tchannel.thrift.register(service.KeyValue) def getValue(request): key = request.body.key value = values.get(key) if value is None: raise service.NotFoundError(key) return value