当前位置: 首页>>代码示例>>Python>>正文


Python TChannel.thrift方法代码示例

本文整理汇总了Python中tchannel.TChannel.thrift方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.thrift方法的具体用法?Python TChannel.thrift怎么用?Python TChannel.thrift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tchannel.TChannel的用法示例。


在下文中一共展示了TChannel.thrift方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_inherited_method_names

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
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'
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:31,代码来源:test_multiple_services.py

示例2: test_service_inheritance

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
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
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:31,代码来源:test_rw.py

示例3: test_i32

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [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
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:37,代码来源:test_thrift.py

示例4: test_i32

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_i32(server, service, ThriftTest):

    # Given this test server:

    @server.thrift.register(ThriftTest)
    def testI32(request):
        return request.body.thing

    # Make a call:

    tchannel = TChannel(name='client')

    # 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
开发者ID:encrylife,项目名称:tchannel-python,代码行数:27,代码来源:test_thrift.py

示例5: test_second_service_blah_blah

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_second_service_blah_blah(
    server, service, second_service, ThriftTest, SecondService
):

    # Given this test server:

    @server.thrift.register(ThriftTest)
    def testString(request):
        return request.body.thing

    @server.thrift.register(SecondService)
    def blahBlah(request):
        pass

    # Make a call:

    tchannel = TChannel(name='client')

    resp = yield tchannel.thrift(service.testString('thing'))

    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body == 'thing'

    resp = yield tchannel.thrift(second_service.blahBlah())

    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body is None
开发者ID:encrylife,项目名称:tchannel-python,代码行数:31,代码来源:test_thrift.py

示例6: test_service_inheritance_with_import

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
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
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:37,代码来源:test_rw.py

示例7: test_second_service_second_test_string

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_second_service_second_test_string():

    # Given this test server:

    server = TChannel(name='server')

    @server.thrift.register(ThriftTest)
    def testString(request):
        return request.body.thing

    @server.thrift.register(SecondService)
    @gen.coroutine
    def secondtestString(request):

        service = thrift_request_builder(
            service='server',
            thrift_module=ThriftTest,
            hostport=server.hostport,
        )
        resp = yield tchannel.thrift(
            service.testString(request.body.thing),
        )

        raise gen.Return(resp)

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    service = thrift_request_builder(
        service='server',
        thrift_module=ThriftTest,
        hostport=server.hostport
    )

    second_service = thrift_request_builder(
        service='server',
        thrift_module=SecondService,
        hostport=server.hostport,
    )

    resp = yield tchannel.thrift(service.testString('thing'))

    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body == 'thing'

    resp = yield tchannel.thrift(
        second_service.secondtestString('second_string')
    )

    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body == 'second_string'
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:58,代码来源:test_thrift.py

示例8: test_multi_exception

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_multi_exception():

    # Given this test server:

    server = TChannel(name='server')

    @server.thrift.register(ThriftTest)
    def testMultiException(request):

        if request.body.arg0 == 'Xception':
            raise ThriftTest.Xception(
                errorCode=1001,
                message='This is an Xception',
            )
        elif request.body.arg0 == 'Xception2':
            raise ThriftTest.Xception2(
                errorCode=2002
            )

        return ThriftTest.Xtruct(string_thing=request.body.arg1)

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    service = thrift_request_builder(
        service='service',
        thrift_module=ThriftTest,
        hostport=server.hostport
    )

    # case #1
    with pytest.raises(ThriftTest.Xception) as e:
        yield tchannel.thrift(
            service.testMultiException(arg0='Xception', arg1='thingy')
        )
        assert e.value.errorCode == 1001
        assert e.value.message == 'This is an Xception'

    # case #2
    with pytest.raises(ThriftTest.Xception2) as e:
        yield tchannel.thrift(
            service.testMultiException(arg0='Xception2', arg1='thingy')
        )
        assert e.value.errorCode == 2002

    # case #3
    resp = yield tchannel.thrift(
        service.testMultiException(arg0='something else', arg1='thingy')
    )
    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body == ThriftTest.Xtruct('thingy')
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:57,代码来源:test_thrift.py

示例9: run

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def run():
    app_name = "keyvalue-client"

    tchannel = TChannel(app_name)

    KeyValueClient.setValue("foo", "Hello, world!"),

    yield tchannel.thrift(KeyValueClient.setValue("foo", "Hello, world!"))

    response = yield tchannel.thrift(KeyValueClient.getValue("foo"))

    print response.body
开发者ID:jokaye,项目名称:tchannel-python,代码行数:14,代码来源:client.py

示例10: test_exception

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_exception():

    # Given this test server:

    server = TChannel(name='server')

    @server.thrift.register(ThriftTest)
    def testException(request):

        if request.body.arg == 'Xception':
            raise ThriftTest.Xception(
                errorCode=1001,
                message=request.body.arg
            )
        elif request.body.arg == 'TException':
            # TODO - what to raise here? We dont want dep on Thrift
            # so we don't have thrift.TException available to us...
            raise Exception()

    server.listen()

    # Make a call:

    tchannel = TChannel(name='client')

    service = thrift_request_builder(
        service='service',
        thrift_module=ThriftTest,
        hostport=server.hostport
    )

    # case #1
    with pytest.raises(ThriftTest.Xception) as e:
        yield tchannel.thrift(
            service.testException(arg='Xception')
        )
        assert e.value.errorCode == 1001
        assert e.value.message == 'Xception'

    # case #2
    with pytest.raises(UnexpectedError):
        yield tchannel.thrift(
            service.testException(arg='TException')
        )

    # case #3
    resp = yield tchannel.thrift(
        service.testException(arg='something else')
    )
    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body is None
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:54,代码来源:test_thrift.py

示例11: test_exception

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_exception(server, service, ThriftTest, server_ttypes, client_ttypes):

    # Given this test server:

    class MyCoolError(Exception):
        pass

    @server.thrift.register(ThriftTest)
    def testException(request):

        if request.body.arg == 'Xception':
            raise server_ttypes.Xception(
                errorCode=1001,
                message=request.body.arg
            )
        elif request.body.arg == 'TException':
            # TODO - what to raise here? We dont want dep on Thrift
            # so we don't have thrift.TException available to us...
            raise MyCoolError("hi")

    # Make a call:

    tchannel = TChannel(name='client')

    # case #1
    with pytest.raises(client_ttypes.Xception) as e:
        yield tchannel.thrift(
            service.testException(arg='Xception')
        )
    assert e.value.errorCode == 1001
    assert e.value.message == 'Xception'

    # case #2
    with pytest.raises(UnexpectedError) as e:
        yield tchannel.thrift(
            service.testException(arg='TException')
        )
    assert 'MyCoolError' in str(e)
    assert 'ThriftTest::testException' in str(e)
    assert 'test_thrift.py' in str(e)

    # case #3
    resp = yield tchannel.thrift(
        service.testException(arg='something else')
    )
    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body is None
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:50,代码来源:test_thrift.py

示例12: test_value_expected_but_none_returned_should_error

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [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!?')
        )
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:28,代码来源:test_thrift.py

示例13: test_double

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [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
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:30,代码来源:test_thrift.py

示例14: test_value_expected_but_none_returned_should_error

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [as 别名]
def test_value_expected_but_none_returned_should_error(
    server, service, ThriftTest, use_thriftrw_server
):

    # Given this test server:

    @server.thrift.register(ThriftTest)
    def testString(request):
        pass

    # Make a call:

    tchannel = TChannel(name='client')

    if use_thriftrw_server:
        # With thirftrw the client only sees an unexpected error because
        # thriftrw always disallows None results for functions that return
        # values.
        exc = UnexpectedError
    else:
        exc = ValueExpectedError

    with pytest.raises(exc) as exc_info:
        yield tchannel.thrift(
            service.testString('no return!?')
        )

    if not use_thriftrw_server:
        assert 'Expected a value to be returned' in str(exc_info)
        assert 'ThriftTest::testString' in str(exc_info)
开发者ID:gjtrowbridge,项目名称:tchannel-python,代码行数:32,代码来源:test_thrift.py

示例15: test_string_map

# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import thrift [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
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:35,代码来源:test_thrift.py


注:本文中的tchannel.TChannel.thrift方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。