コード例 #1
0
def test_request_transport_integration():
    handler = ReadOnlySchedulerHandler()
    processor = ReadOnlyScheduler.Processor(handler)
    pfactory = TJSONProtocol.TJSONProtocolFactory()
    server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
    server_thread = Thread(target=server.serve)
    server_thread.start()
    _, server_port = server.httpd.socket.getsockname()

    response = None

    try:
        transport = TRequestsTransport('http://localhost:%d' % server_port)
        protocol = TJSONProtocol.TJSONProtocol(transport)
        client = ReadOnlyScheduler.Client(protocol)
        response = client.getRoleSummary()
    finally:
        server.httpd.shutdown()

    assert response is not None
    assert response.responseCode == ResponseCode.OK
    assert response.serverInfo.clusterName == 'west'
    assert response.serverInfo.thriftAPIVersion == 3

    transport.close()
コード例 #2
0
def test_requests_transport_session_reuse():
    handler = ReadOnlySchedulerHandler()
    processor = ReadOnlyScheduler.Processor(handler)
    pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
    server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
    server_thread = Thread(target=server.serve)
    server_thread.start()
    _, server_port = server.httpd.socket.getsockname()

    try:
        transport = TRequestsTransport('http://localhost:%d' % server_port)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        client = ReadOnlyScheduler.Client(protocol)
        client.getRoleSummary()
        old_session = transport._session
        client.getRoleSummary()
    finally:
        server.httpd.shutdown()

    assert old_session == transport._session

    transport.close()