Search in sources :

Example 1 with Service

use of org.apache.hive.service.Service in project hive by apache.

the class TestRetryingThriftCLIServiceClient method testSessionLifeAfterTransportClose.

@Test
public void testSessionLifeAfterTransportClose() throws InterruptedException, HiveSQLException {
    try {
        startHiveServer();
        CLIService service = null;
        for (Service s : server.getServices()) {
            if (s instanceof CLIService) {
                service = (CLIService) s;
            }
        }
        if (service == null) {
            service = new CLIService(server);
        }
        RetryingThriftCLIServiceClient.CLIServiceClientWrapper client = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
        Map<String, String> conf = new HashMap<>();
        conf.put(HiveConf.ConfVars.HIVE_SERVER2_CLOSE_SESSION_ON_DISCONNECT.varname, "false");
        SessionHandle sessionHandle = client.openSession("anonymous", "anonymous", conf);
        assertNotNull(sessionHandle);
        HiveSession session = service.getSessionManager().getSession(sessionHandle);
        OperationHandle op1 = session.executeStatementAsync("show databases", null);
        assertNotNull(op1);
        client.closeTransport();
        // Verify that session wasn't closed on transport close.
        assertEquals(session, service.getSessionManager().getSession(sessionHandle));
        // Should be able to execute without failure in the session whose transport has been closed.
        OperationHandle op2 = session.executeStatementAsync("show databases", null);
        assertNotNull(op2);
        // Make new client, since transport was closed for the last one.
        client = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
        client.closeSession(sessionHandle);
        // operations will be lost once owning session is closed.
        for (OperationHandle op : new OperationHandle[] { op1, op2 }) {
            try {
                client.getOperationStatus(op, false);
                fail("Should have failed.");
            } catch (HiveSQLException ignored) {
            }
        }
    } finally {
        stopHiveServer();
    }
}
Also used : RetryingThriftCLIServiceClient(org.apache.hive.service.cli.thrift.RetryingThriftCLIServiceClient) HashMap(java.util.HashMap) ThriftCLIService(org.apache.hive.service.cli.thrift.ThriftCLIService) Service(org.apache.hive.service.Service) HiveSession(org.apache.hive.service.cli.session.HiveSession) ThriftCLIService(org.apache.hive.service.cli.thrift.ThriftCLIService) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Service (org.apache.hive.service.Service)1 HiveSession (org.apache.hive.service.cli.session.HiveSession)1 RetryingThriftCLIServiceClient (org.apache.hive.service.cli.thrift.RetryingThriftCLIServiceClient)1 ThriftCLIService (org.apache.hive.service.cli.thrift.ThriftCLIService)1 Test (org.junit.Test)1