コード例 #1
0
ファイル: json.py プロジェクト: yarpc/yarpc-python
def json(respw, server, transport, **kwargs):
    rpc = RPC(service="client", outbounds={"yarpc-test": tr.factory(server, transport)})

    expected = {"token": rand.string(7)}

    request = Request(procedure="echo", body=expected, ttl=10000)
    client = JSONClient(rpc.channel("yarpc-test"))
    response = yield client.call(request)

    if response.body == expected:
        respw.success("Server said: %s" % response.body["token"])
    else:
        respw.fail("expected %s, got %s" % (expected, response.body))
コード例 #2
0
ファイル: conftest.py プロジェクト: yarpc/yarpc-python
def rpc(io_loop, inbound, outbound):
    rpc = RPC(
        service='test-service',
        inbounds=[inbound],
        outbounds={
            'test-service': outbound,
        },
    )

    try:
        rpc.start()
        yield rpc
    finally:
        rpc.stop()
コード例 #3
0
ファイル: raw.py プロジェクト: yarpc/yarpc-python
def raw(respw, server, transport, **kwargs):
    rpc = RPC(
        service='client',
        outbounds={
            'yarpc-test': tr.factory(server, transport),
        },
    )

    expected = rand.string(7)

    request = Request(procedure='echo/raw', body=expected, ttl=10000)
    client = RawClient(rpc.channel('yarpc-test'))
    response = yield client.call(request)

    if response.body == expected:
        respw.success("Server said: %s" % response.body)
    else:
        respw.fail("expected %s, got %s" % (expected, response.body))
コード例 #4
0
ファイル: thrift.py プロジェクト: yarpc/yarpc-python
def thrift(respw, server, transport, **kwargs):
    rpc = RPC(
        service='client',
        outbounds={
            'yarpc-test': tr.factory(server, transport),
        },
    )

    expected = rand.string(7)

    request = Request(
        body=service.Echo.echo(service.Ping(beep=expected)),
        ttl=10000,
    )
    client = ThriftClient(rpc.channel('yarpc-test'))
    response = yield client.call(request)

    if response.body.boop == expected:
        respw.success("Server said: %s" % response.body.boop)
    else:
        respw.fail("expected %s, got %s" % (expected, response.body))
コード例 #5
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
コード例 #6
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'
コード例 #7
0
ファイル: headers.py プロジェクト: yarpc/yarpc-python
def headers(respw, server, transport, encoding, **kwargs):
    rpc = RPC(
        service='client',
        outbounds={
            'yarpc-test': tr.factory(server, transport),
        },
    )
    caller = get_caller(encoding, rpc.channel('yarpc-test'))

    for test in tests:
        desc, give, want = test
        try:
            resp = yield caller.call(give)
        except Exception as e:
            respw.fail('%s: call failed, %s' % (desc, str(e)))
        else:
            got = resp.headers
            if want != got:
                respw.fail(
                    '%s: call failed, got %s, want %s' % (desc, got, want)
                )
            else:
                respw.success('%s: returns valid headers' % desc)
コード例 #8
0
ファイル: test_rpc.py プロジェクト: yarpc/yarpc-python
def test_no_outbound_for_service_error():
    rpc = RPC('')
    with pytest.raises(NoOutboundForServiceError):
        rpc.channel('doesntexist')
コード例 #9
0
ファイル: sync.py プロジェクト: yarpc/yarpc-python
# 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, division, print_function, unicode_literals
)

from yarpc import RPC, Response
from yarpc_sync.inbounds import HTTPInbound

rpc = RPC(
    service='test-service',
    inbounds=[HTTPInbound(port=8888)],
)


def test(request):
    # resp = rpc.json('billy', {'hello':'world'})
    return Response(body="test: %s" % request.body)


def test2(request):
    return Response(body="test2: %s" % request.body)


rpc.raw.register('test', test)
rpc.raw.register('test2', test2)
コード例 #10
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()