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();
}
}
Aggregations