public class TestHiveSession {
@Test
public void checkOperationClosing() throws Exception {
OperationManager opMgr = new OperationManager();
HiveSession session = new HiveSessionImpl("user", "passw", null);
session.setOperationManager(opMgr);
OperationHandle opHandle1 = session.executeStatement("use default", null);
assertNotNull(opHandle1);
assertEquals(OperationState.FINISHED, opMgr.getOperationState(opHandle1));
OperationHandle opHandle2 = session.executeStatement("show databases", null);
assertNotNull(opHandle2);
assertEquals(OperationState.FINISHED, opMgr.getOperationState(opHandle2));
session.closeOperation(opHandle1); // Don't close directly from opMgr!
try {
opMgr.getOperationState(opHandle1);
fail("Shouldn't work!");
} catch (Exception e) {
assertTrue(e instanceof HiveSQLException);
}
session.close(); // Close all remaining associated operations
try {
opMgr.getOperationState(opHandle2);
fail("Shouldn't work this way now that it's fixed (HIVE-4398)!");
} catch (Exception e) {
assertTrue(e instanceof HiveSQLException);
}
}