def getClient(addr): transport = TSocket.TSocket(addr[0], addr[1]) transport = TTransport.TFramedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = SleepService.Client(protocol) transport.open() return client
def getClient(port): transport = TSocket.TSocket('127.0.0.1', port) transport = TTransport.TFramedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = SleepService.Client(protocol) transport.open() return client
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
def process(self, iprot, oprot, server_context=None): fname, type, seqid = iprot.readMessageBegin() self.assertTrue(iprot.trans.get_headers().get(b"hello") == b"world") result = SleepService.space_result() result.success = "h i" oprot.writeMessageBegin(fname, TMessageType.REPLY, seqid) result.write(oprot) oprot.writeMessageEnd() oprot.trans.flush()
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()
def setUp(self): super(TestServer, self).setUp() self.noop_event = threading.Event() processor = SleepService.Processor(SleepHandler(self.noop_event)) self.event_handler = SleepProcessorEventHandler() processor.setEventHandler(self.event_handler) self.server = TCppServer(processor) self.addCleanup(self.stopServer) # Let the kernel choose a port. self.server.setPort(0) self.server_thread = threading.Thread(target=self.server.serve) self.server_thread.start() for t in range(30): addr = self.server.getAddress() if addr: break time.sleep(0.1) self.assertTrue(addr) self.server_port = addr[1]
def getProcessor(self): processor = SleepService.Processor( SleepHandler(self.noop_event, self.shutdown_event)) self.event_handler = SleepProcessorEventHandler() processor.setEventHandler(self.event_handler) return processor