コード例 #1
0
ファイル: test_rpc.py プロジェクト: yarpc/yarpc-python
def test_should_call_procedure(inbound, outbound):
    rpc = RPC(
        service='test-service',
        inbounds=[inbound],
        outbounds={
            'test-service': outbound,
        },
    )

    def hi(request):
        assert isinstance(request, Request)
        assert request.encoding == 'raw'
        assert request.procedure == 'hi'
        assert request.body == 'hello'
        return Response(body="%s" % request.body)

    rpc.register(Procedure('hi', hi))
    rpc.start()

    req = Request(
        encoding='raw',
        procedure='hi',
        body='hello',
        ttl=10000,
    )

    resp = hi(req)
    assert isinstance(resp, Response)
    assert resp.body == 'hello'

    resp = yield rpc.channel('test-service').call(req)
    assert isinstance(resp, Response)
    assert resp.body == 'hello'
コード例 #2
0
ファイル: test_rpc.py プロジェクト: yarpc/yarpc-python
def test_should_roundtrip_headers(inbound, outbound):
    rpc = RPC(
        service='test-service',
        inbounds=[inbound],
        outbounds={
            'test-service': outbound,
        },
    )

    def hi(request):
        return Response(
            body=request.body,
            headers=request.headers,
        )

    rpc.register(Procedure('hi', hi))
    rpc.start()

    headers = {
        'hello': 'world',
        'mynameis': 'bob',
    }
    req = Request(
        encoding='raw',
        procedure='hi',
        headers=headers,
        ttl=10000,
    )
    resp = yield rpc.channel('test-service').call(req)
    assert headers == resp.headers
コード例 #3
0
ファイル: server.py プロジェクト: yarpc/yarpc-python
def start():
    rpc = RPC(
        service='yarpc-test',
        inbounds=[
            http.HTTPInbound(transport.HTTP_PORT),
            tchannel.TChannelInbound(
                TChannel(
                    name='yarpc-test',  # TODO shouldnt rpc set this somehow?
                    hostport="0.0.0.0:%s" % transport.TCHANNEL_PORT
                ),
            )
        ],
    )

    rpc.register(procedure.raw)
    rpc.register(procedure.json)
    rpc.register(procedure.thrift)

    rpc.register(procedure.phone)
    rpc.register(procedure.unexpected)
    rpc.register(procedure.bad)

    rpc.start()