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


Python tchannel.TChannel类代码示例

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


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

示例1: test_binary

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

示例2: test_headers_and_body_should_be_optional

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

示例3: keyvalue_server

def keyvalue_server(io_loop, keyvalue, keyvalue_data):
    server = TChannel(name='keyvalue')
    server.listen()

    @server.thrift.register(keyvalue.KeyValue)
    def getItem(request):
        assert request.service == 'keyvalue'
        key = request.body.key
        if key in keyvalue_data:
            assert request.headers == {'expect': 'success'}
            return keyvalue_data[key]
        else:
            assert request.headers == {'expect': 'failure'}
            raise keyvalue.ItemDoesNotExist(key)

    @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']
        keyvalue_data[key] = value
        return {'success': True}

    return server
开发者ID:dnathe4th,项目名称:tchannel-python,代码行数:25,代码来源:test_forwarding.py

示例4: test_call_response_should_contain_transport_headers

def test_call_response_should_contain_transport_headers(
    server, service, ThriftTest
):

    # Given this test server:

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

    # Make a call:

    tchannel = TChannel(name='client')

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

    # verify response
    assert isinstance(resp, Response)
    assert resp.headers == {}
    assert resp.body == 'hi'

    # verify response transport headers
    assert isinstance(resp.transport, TransportHeaders)
    assert resp.transport.scheme == schemes.THRIFT
    assert resp.transport.failure_domain is None
开发者ID:encrylife,项目名称:tchannel-python,代码行数:25,代码来源:test_thrift.py

示例5: test_client_connection_change_callback

def test_client_connection_change_callback():
    server = TChannel('server')
    server.listen()

    @server.raw.register
    def hello(request):
        return 'hi'

    client = TChannel('client')
    count = [0]

    def test_cb(peer):
        count[0] += 1

    client._dep_tchannel.peers.get(
        server.hostport)._on_conn_change_cb = test_cb
    yield client.raw(
        hostport=server.hostport,
        body='work',
        endpoint='hello',
        service='server'
    )

    # 1: connection built, 1: sending request, 1: finish sending request
    assert count[0] == 3
开发者ID:uber,项目名称:tchannel-python,代码行数:25,代码来源:test_connection.py

示例6: test_nest

def test_nest(server, service, ThriftTest, client_ttypes):

    # Given this test server:

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

    # Make a call:

    tchannel = TChannel(name='client')

    xstruct = client_ttypes.Xtruct(
        string_thing='hi',
        byte_thing=1,
        i32_thing=-1,
        i64_thing=-34359738368,
    )
    xstruct2 = client_ttypes.Xtruct2(
        byte_thing=1,
        struct_thing=xstruct,
        i32_thing=1,
    )

    resp = yield tchannel.thrift(
        service.testNest(thing=xstruct2)
    )

    assert resp.headers == {}
    assert resp.body == xstruct2
开发者ID:encrylife,项目名称:tchannel-python,代码行数:30,代码来源:test_thrift.py

示例7: test_map_map

def test_map_map(server, service, ThriftTest):

    # Given this test server:

    map_map = {
        -4: {
            -4: -4,
            -3: -3,
            -2: -2,
            -1: -1,
        },
        4: {
            1: 1,
            2: 2,
            3: 3,
            4: 4,
        },
    }

    @server.thrift.register(ThriftTest)
    def testMapMap(request):
        return map_map

    # Make a call:

    tchannel = TChannel(name='client')

    resp = yield tchannel.thrift(
        service.testMapMap(1)
    )

    assert resp.headers == {}
    assert resp.body == map_map
开发者ID:encrylife,项目名称:tchannel-python,代码行数:33,代码来源:test_thrift.py

示例8: test_type_def

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

示例9: test_void_with_headers

def test_void_with_headers():

    # Given this test server:

    server = TChannel(name='server')

    @server.thrift.register(ThriftTest)
    def testVoid(request):
        assert request.headers == {'req': 'header'}
        return Response(headers={'resp': 'header'})

    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(),
        headers={'req': 'header'},
    )

    assert resp.headers == {
        'resp': 'header'
    }
    assert resp.body is None
开发者ID:MadanThangavelu,项目名称:tchannel-python,代码行数:32,代码来源:test_thrift.py

示例10: test_void

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

示例11: test_enum

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

示例12: test_string_map

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,代码行数:33,代码来源:test_thrift.py

示例13: test_map

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

示例14: test_struct

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

示例15: test_i32

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,代码行数:25,代码来源:test_thrift.py


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