Пример #1
0
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
Пример #2
0
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
Пример #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
Пример #4
0
 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()
Пример #5
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()
Пример #6
0
    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]
Пример #7
0
 def getProcessor(self):
     processor = SleepService.Processor(
             SleepHandler(self.noop_event, self.shutdown_event))
     self.event_handler = SleepProcessorEventHandler()
     processor.setEventHandler(self.event_handler)
     return processor