示例#1
0
def run():
    app = TChannel(name='thrift-client')

    client = client_for('hello', HelloService)(app, 'localhost:8888')

    response = yield client.hello("world")

    print response
def test_client_for(ClientTChannel, server, ThriftTest):
    @server.thrift.register(ThriftTest)
    def testString(request):
        return request.body.thing.encode('rot13')

    tchannel = ClientTChannel(name='client')

    client = client_for('server', _ThriftTest)(
        tchannel=tchannel,
        hostport=server.hostport,
    )

    resp = yield client.testString(thing='foo')
    assert resp == 'sbb'
示例#3
0
def test_client_for(ClientTChannel, server, ThriftTest):

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

    tchannel = ClientTChannel(name='client')

    client = client_for('server', _ThriftTest)(
        tchannel=tchannel,
        hostport=server.hostport,
    )

    resp = yield client.testString(thing='foo')
    assert resp == 'sbb'
示例#4
0
def thrift_client(thrift_service, mock_server, use_old_api):
    if use_old_api:
        from tchannel.tornado import TChannel

        return client_for('myservice', thrift_service)(
            tchannel=TChannel('thrift-client'),
            hostport=mock_server.hostport,
        )
    else:
        from tchannel import TChannel
        from tchannel.thrift import thrift_request_builder

        myservice = thrift_request_builder('myservice',
                                           thrift_service,
                                           hostport=mock_server.hostport)
        return mk_fake_client(TChannel('thrift-client'), myservice)
示例#5
0
def thrift_client(thrift_service, mock_server, use_old_api):
    if use_old_api:
        from tchannel.tornado import TChannel

        return client_for('myservice', thrift_service)(
            tchannel=TChannel('thrift-client'),
            hostport=mock_server.hostport,
        )
    else:
        from tchannel import TChannel
        from tchannel.thrift import thrift_request_builder

        myservice = thrift_request_builder(
            'myservice', thrift_service, hostport=mock_server.hostport
        )
        return mk_fake_client(
            TChannel('thrift-client'),
            myservice
        )
示例#6
0
def client(vcr_service):
    return client_for('vcr', VCRProxy)(
        TChannel('proxy-client'), hostport=vcr_service.hostport
    )
示例#7
0
def thrift_client(thrift_service, mock_server):
    return client_for('myservice', thrift_service)(
        tchannel=TChannel('thrift-client'),
        hostport=mock_server.hostport,
    )
示例#8
0
def run():
    tchannel = TChannel(name='thrift-client')
    client = client_for('hello', HelloService)(tchannel, 'localhost:4040')
    response = yield client.hello("world")
    print response
示例#9
0
def thrift_client(thrift_service, mock_server):
    return client_for('myservice', thrift_service)(
        tchannel=TChannel('thrift-client'),
        hostport=mock_server.hostport,
    )
示例#10
0
def thrift_client(thrift_service, mock_server):
    return client_for("myservice", thrift_service)(tchannel=TChannel("thrift-client"), hostport=mock_server.hostport)
示例#11
0
from __future__ import absolute_import

import contextlib2
import inspect
import wrapt
import sys

from tchannel.tornado import TChannel
from tchannel.thrift import client_for

from .cassette import Cassette
from .patch import Patcher, force_reset
from .server import VCRProxyService, VCRProxy


VCRProxyClient = client_for('vcr', VCRProxy)


class _CassetteContext(object):
    """Lets use_cassette be used as a context manager and a decorator."""

    def __init__(self, path, record_mode, inject):
        self.path = path
        self.record_mode = record_mode
        self.inject = inject

        self._exit_stack = contextlib2.ExitStack()

    def __enter__(self):
        cassette = self._exit_stack.enter_context(
            Cassette(path=self.path, record_mode=self.record_mode)
示例#12
0
def client(vcr_service):
    return client_for("vcr", VCRProxy)(TChannel("proxy-client"), hostport=vcr_service.hostport)
示例#13
0
def client(vcr_service):
    return client_for('vcr', VCRProxy)(TChannel('proxy-client'),
                                       hostport=vcr_service.hostport)