Beispiel #1
0
 def bg_thrift_context(sync=False, **kwargs):
     with client_context(bg_utils.bg_thrift.BartenderBackend,
                         host=config.backend.host,
                         port=config.backend.port,
                         socket_timeout=config.backend.socket_timeout,
                         **kwargs) as client:
         yield client if sync else BgClient(client)
Beispiel #2
0
def main():
    with client_context(tutorial_thrift.Calculator,
                        '127.0.0.1', 6000) as client:
        client.ping()
        print("ping()")

        total = client.add(1, 1)
        print('1+1=%d' % (total))

        work = tutorial_thrift.Work()
        work.op = tutorial_thrift.Operation.DIVIDE
        work.num1 = 1
        work.num2 = 0

        try:
            client.calculate(1, work)
            print('Whoa? You know how to divide by zero?')
        except tutorial_thrift.InvalidOperation as io:
            print('InvalidOperation: %r' % io)

        work.op = tutorial_thrift.Operation.SUBTRACT
        work.num1 = 15
        work.num2 = 10

        diff = client.calculate(1, work)
        print('15-10=%d' % (diff))

        log = client.getStruct(1)
        print('Check log: %s' % (log.value))
Beispiel #3
0
def ssl_client_with_url(timeout=3000):
    return client_context(
        addressbook.AddressBookService,
        url="thrift://localhost:{port}".format(port=SSL_PORT),
        timeout=timeout,
        cafile="ssl/CA.pem",
        certfile="ssl/client.crt",
        keyfile="ssl/client.key")
Beispiel #4
0
def ssl_client(timeout=3000):
    return client_context(addressbook.AddressBookService,
                          host='localhost',
                          port=SSL_PORT,
                          timeout=timeout,
                          cafile="ssl/CA.pem",
                          certfile="ssl/client.crt",
                          keyfile="ssl/client.key")
def client_two(timeout=3000):
    binary_factory = TBinaryProtocolFactory()
    multiplexing_factory = TMultiplexedProtocolFactory(binary_factory,
                                                       "ThingTwoService")
    return client_context(mux.ThingTwoService,
                          unix_socket=sock_path,
                          timeout=timeout,
                          proto_factory=multiplexing_factory)
Beispiel #6
0
def main():
    with client_context(
            sc_thrift.SCService,
            '127.0.0.1',
            6000,
            proto_factory=TCyBinaryProtocolFactory(),
            trans_factory=TCyBufferedTransportFactory()) as context:
        client = Client(context)
        client.play()
def main():
    binary_factory = TBinaryProtocolFactory()
    dd_factory = TMultiplexedProtocolFactory(binary_factory, DD_SERVICE_NAME)
    with client_context(dd_thrift.DingService,
                        '127.0.0.1',
                        9090,
                        proto_factory=dd_factory) as c:
        # ring that doorbell
        dong = c.ding()
        print(dong)

    pp_factory = TMultiplexedProtocolFactory(binary_factory, PP_SERVICE_NAME)
    with client_context(pp_thrift.PingService,
                        '127.0.0.1',
                        9090,
                        proto_factory=pp_factory) as c:
        # play table tennis like a champ
        pong = c.ping()
        print(pong)
def main():
    with client_context(calc_thrift.Calculator, '127.0.0.1', 6000) as cal:
        a = cal.mult(5, 2)
        b = cal.sub(7, 3)
        c = cal.sub(6, 4)
        d = cal.mult(b, 10.0)
        e = cal.add(a, d)
        f = cal.div(e, c)
        g = cal.glist(20)
        user = cal.guser(101)
        print(user)
Beispiel #9
0
def main():
    with client_context(calc_thrift.Calculator,
                        '127.0.0.1',
                        6000,
                        proto_factory=TCyBinaryProtocolFactory(),
                        trans_factory=TCyBufferedTransportFactory()) as cal:
        a = cal.mult(5, 2)
        b = cal.sub(7, 3)
        c = cal.sub(6, 4)
        d = cal.mult(b, 10)
        e = cal.add(a, d)
        f = cal.div(e, c)
        print(f)
Beispiel #10
0
def test_client_connect_timeout():
    with pytest.raises(TTransportException):
        with client_context(addressbook.AddressBookService,
                            unix_socket='/tmp/test.sock',
                            connect_timeout=1000) as c:
            c.hello('test')
Beispiel #11
0
def test_client_socket_timeout():
    with pytest.raises(socket.timeout):
        with client_context(addressbook.AddressBookService,
                            unix_socket=unix_sock,
                            socket_timeout=500) as c:
            c.sleep(1000)
Beispiel #12
0
def client(timeout=3000):
    return client_context(addressbook.AddressBookService,
                          unix_socket=unix_sock, timeout=timeout)
Beispiel #13
0
 def client_cntxt(self):
     return client_context(self.ARTICLEMETA_THRIFT.ArticleMeta,
                           self._address,
                           self._port,
                           socket_timeout=self._timeout,
                           connect_timeout=self._timeout)
Beispiel #14
0
def main():
    with client_context(pp_thrift.PingService, '127.0.0.1', 6000) as c:
        pong = c.ping()
        print(pong)
Beispiel #15
0
def main():
    with client_context(pingpong.PingService, '127.0.0.1', 8000) as c:
        pong = c.ping()
        print(pong)