diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index 50c912e..b1b1d8f 100644 --- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -192,11 +192,20 @@ protected BufferedReader loadFile(String fileName) throws IOException { protected int processCmd(String cmd) { int rc = 0; String cmd_trimed = cmd.trim(); + OperationHandle opHandle = null; try { - executeStatementInternal(cmd_trimed, null, false); + //execute in sync mode + opHandle = executeStatementInternal(cmd_trimed, null, false); } catch (HiveSQLException e) { - rc = -1; - LOG.warn("Failed to execute HQL command in global .hiverc file.", e); + LOG.warn("Failed to execute command in global .hiverc file.", e); + return -1; + } + if (opHandle != null) { + try { + closeOperation(opHandle); + } catch (HiveSQLException e) { + LOG.warn("Failed to close operation for command in .hiverc file.", e); + } } return rc; } diff --git a/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java b/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java index 840a551..55a325d 100644 --- a/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java +++ b/service/src/test/org/apache/hive/service/cli/session/TestSessionGlobalInitFile.java @@ -22,19 +22,19 @@ import java.util.HashMap; import java.util.Map; -import junit.framework.Assert; import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hive.service.cli.CLIService; -import org.apache.hive.service.cli.ICLIService; import org.apache.hive.service.cli.OperationHandle; import org.apache.hive.service.cli.RowSet; import org.apache.hive.service.cli.SessionHandle; +import org.apache.hive.service.cli.operation.OperationManager; import org.apache.hive.service.cli.thrift.ThriftBinaryCLIService; import org.apache.hive.service.cli.thrift.ThriftCLIServiceClient; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -58,7 +58,7 @@ public FakeEmbeddedThriftBinaryCLIService(HiveConf hiveConf) { cliService.start(); } - public ICLIService getService() { + public CLIService getService() { return cliService; } } @@ -123,8 +123,15 @@ public void testSessionGlobalInitDir() throws Exception { * setting property. */ private void doTestSessionGlobalInitFile() throws Exception { + + OperationManager operationManager = service.getService().getSessionManager() + .getOperationManager(); SessionHandle sessionHandle = client.openSession(null, null, null); + // ensure there is no operation related object leak + Assert.assertEquals("Verifying all operations used for init file are closed", + 0, operationManager.getOperations().size()); + verifyInitProperty("a", "1", sessionHandle); verifyInitProperty("b", "1", sessionHandle); verifyInitProperty("c", "1", sessionHandle); @@ -137,7 +144,10 @@ private void doTestSessionGlobalInitFile() throws Exception { */ // Assert.assertEquals("expected uri", api.getAddedResource("jar")); + Assert.assertEquals("Verifying all operations used for checks are closed", + 0, operationManager.getOperations().size()); client.closeSession(sessionHandle); + } @Test @@ -175,5 +185,6 @@ private void verifyInitProperty(String key, String value, Assert.assertEquals(1, rowSet.numRows()); // we know rowSet has only one element Assert.assertEquals(key + "=" + value, rowSet.iterator().next()[0]); + client.closeOperation(operationHandle); } }