Index: ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java (revision 911546) +++ ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java (working copy) @@ -234,6 +234,8 @@ qsb.append(dis.readLine() + "\n"); } qMap.put(qf.getName(), qsb.toString()); + + dis.close(); } public void cleanUp() throws Exception { @@ -447,7 +449,10 @@ ss.out = new PrintStream(fo, true, "UTF-8"); ss.err = ss.out; ss.setIsSilent(true); - SessionState.start(ss); + SessionState oldSs = SessionState.start(ss); + if (oldSs != null) { + oldSs.out.close(); + } cliDriver = new CliDriver(); } Index: ql/src/test/templates/TestCliDriver.vm =================================================================== --- ql/src/test/templates/TestCliDriver.vm (revision 911546) +++ ql/src/test/templates/TestCliDriver.vm (working copy) @@ -38,9 +38,6 @@ qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()", miniMR); -#foreach ($qf in $qfiles) - qt.addFile("$qf.getCanonicalPath()"); -#end } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); @@ -81,6 +78,9 @@ public void testCliDriver_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); + + qt.addFile("$qf.getCanonicalPath()"); + qt.cliInit("$fname"); int ecode = qt.executeClient("$fname"); if (ecode != 0) { Index: ql/src/test/templates/TestNegativeCliDriver.vm =================================================================== --- ql/src/test/templates/TestNegativeCliDriver.vm (revision 911546) +++ ql/src/test/templates/TestNegativeCliDriver.vm (working copy) @@ -27,9 +27,6 @@ try { qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()"); -#foreach ($qf in $qfiles) - qt.addFile("$qf.getCanonicalPath()"); -#end } catch (Throwable e) { e.printStackTrace(); @@ -56,6 +53,9 @@ public void testNegativeCliDriver_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); + + qt.addFile("$qf.getCanonicalPath()"); + qt.cliInit("$fname"); int ecode = qt.executeClient("$fname"); if (ecode == 0) { Index: ql/src/test/templates/TestParse.vm =================================================================== --- ql/src/test/templates/TestParse.vm (revision 911546) +++ ql/src/test/templates/TestParse.vm (working copy) @@ -23,10 +23,6 @@ protected void setUp() { try { qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()"); - -#foreach ($qf in $qfiles) - qt.addFile("$qf.getCanonicalPath()"); -#end } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); @@ -54,6 +50,9 @@ public void testParse_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); + + qt.addFile("$qf.getCanonicalPath()"); + qt.init("$fname"); ASTNode tree = qt.parseQuery("$fname"); int ecode = qt.checkParseResults("$fname", tree); Index: ql/src/test/templates/TestParseNegative.vm =================================================================== --- ql/src/test/templates/TestParseNegative.vm (revision 911546) +++ ql/src/test/templates/TestParseNegative.vm (working copy) @@ -23,10 +23,6 @@ protected void setUp() { try { qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()"); - -#foreach ($qf in $qfiles) - qt.addFile("$qf.getCanonicalPath()"); -#end } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); @@ -54,6 +50,9 @@ public void testParseNegative_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); + + qt.addFile("$qf.getCanonicalPath()"); + qt.init("$fname"); ASTNode tree = qt.parseQuery("$fname"); List> tasks = qt.analyzeAST(tree); Index: ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java (revision 911546) +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java (working copy) @@ -132,9 +132,13 @@ * set current session to existing session object * if a thread is running multiple sessions - it must call this method with the new * session object when switching from one session to another + * + * @return The old session associated with this thread, or null if not set. */ public static SessionState start(SessionState startSs) { + SessionState oldSessionState = tss.get(); + tss.set(startSs); if(StringUtils.isEmpty(startSs.getConf().getVar(HiveConf.ConfVars.HIVESESSIONID))) { startSs.getConf().setVar(HiveConf.ConfVars.HIVESESSIONID, makeSessionId()); @@ -143,7 +147,7 @@ if (startSs.hiveHist == null){ startSs.hiveHist = new HiveHistory(startSs); } - return startSs; + return oldSessionState; } /**