def _perform_rpc(self, server, val):
     host, port = server.addr()
     with TSocket.TSocket(host=host, port=port) as sock:
         transport = THeaderTransport.THeaderTransport(sock)
         protocol = THeaderProtocol.THeaderProtocol(transport)
         client = SlotsThrowingService.Client(protocol, protocol)
         return client.getDataById(val)
    def test_throw_populates_headers(self):
        handler = self.Handler({7: "hello"})
        processor = TestService.Processor(handler)
        server = TCppServerTestManager.make_server(processor)
        with TCppServerTestManager(server) as server:
            host, port = server.addr()
            with TSocket.TSocket(host=host, port=port) as sock:
                transport = THeaderTransport.THeaderTransport(sock)
                protocol = THeaderProtocol.THeaderProtocol(transport)
                client = TestService.Client(protocol, protocol)

                try:
                    client.throwUserException()
                    self.fail("Expect to throw UserException2")
                except UserException2:
                    pass

                self.assertEquals(b"UserException2",
                                  transport.get_headers()[b"uex"])
                self.assertIn(b"Some message",
                              transport.get_headers()[b"uexw"])

                try:
                    client.throwUncaughtException("a message!")
                    self.fail("Expect to throw TApplicationException")
                except TApplicationException:
                    pass

                self.assertEquals(b"TApplicationException",
                                  transport.get_headers()[b"uex"])
                self.assertIn(b"a message!", transport.get_headers()[b"uexw"])
Example #3
0
def getHeaderClient(addr, sock_cls=TSocket.TSocket):
    transport = sock_cls(addr[0], addr[1])
    transport = THeaderTransport.THeaderTransport(transport)
    transport.set_header("hello", "world")
    protocol = THeaderProtocol.THeaderProtocol(transport)
    client = SleepService.Client(protocol)
    transport.open()
    return client
Example #4
0
 def __init__(self,
              host: str,
              port: int = consts.Consts.CTRL_PORT,
              timeout_ms: int = 5000) -> None:
     socket = TSocket.TSocket(host=host, port=port)
     socket.setTimeout(timeout_ms)
     OpenrCtrlClient.__init__(self, host,
                              THeaderTransport.THeaderTransport(socket))
 def _expiring_rpc(self, server, service, method, tm, *args, **kwargs):
     host, port = server.addr()
     with TSocket.TSocket(host=host, port=port) as sock:
         sock.setTimeout(tm)
         transport = THeaderTransport.THeaderTransport(sock)
         protocol = THeaderProtocol.THeaderProtocol(transport)
         client = service.Client(protocol, protocol)
         return getattr(client, method)(*args, **kwargs)
Example #6
0
    def testHeader(self):
        transport = TSocket.TSocket(self.server_addr[0], self.server_addr[1])
        transport = THeaderTransport.THeaderTransport(transport)
        transport.set_header("hello", "world")
        protocol = THeaderProtocol.THeaderProtocol(transport)
        client = SleepService.Client(protocol)
        transport.open()

        self.assertEquals(client.space("hi"), "h i")
        self.stopServer()
Example #7
0
    def get_thrift_client(self, use_ssl):
        socket = (
            TSSLSocket.TSSLSocket(
                host=self.cli_opts.host,
                port=self.cli_opts.openr_ctrl_port,
                # verify server
                cert_reqs=ssl.CERT_REQUIRED,
                ca_certs=self.cli_opts.ca_file,
                certfile=self.cli_opts.cert_file,
                keyfile=self.cli_opts.key_file,
                verify_name=self.cli_opts.acceptable_peer_name,
            ) if use_ssl else TSocket.TSocket(
                host=self.cli_opts.host, port=self.cli_opts.openr_ctrl_port))
        socket.setTimeout(self.cli_opts.timeout)
        transport = THeaderTransport.THeaderTransport(socket)
        protocol = THeaderProtocol.THeaderProtocol(transport)

        transport.open()
        return OpenrCtrl.Client(protocol)
Example #8
0
 def __init__(
     self,
     host: str,
     ca_file: str,
     cert_file: str,
     key_file: str,
     acceptable_peer_name: str,
     port: int = consts.Consts.CTRL_PORT,
     timeout_ms: int = 5000,
 ) -> None:
     socket = TSSLSocket.TSSLSocket(
         host=host,
         port=port,
         cert_reqs=ssl.CERT_REQUIRED,
         ca_certs=ca_file,
         certfile=cert_file,
         keyfile=key_file,
         verify_name=acceptable_peer_name,
     )
     socket.setTimeout(timeout_ms)
     OpenrCtrlClient.__init__(self, host, THeaderTransport.THeaderTransport(socket))