package org.apache.hadoop.hive.cli; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.io.*; import java.util.*; import org.apache.hadoop.hive.ql.QTestUtil; import org.apache.hadoop.hive.ql.exec.Task; import org.apache.hadoop.hive.ql.history.HiveHistoryViewer; import org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo; import org.apache.hadoop.hive.ql.history.HiveHistory.Keys; import org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo; import org.apache.hadoop.hive.ql.session.SessionState; import org.antlr.runtime.*; import org.antlr.runtime.tree.*; public class $className extends TestCase { private QTestUtil qt; public $className(String name) { super(name); qt = null; } @Override protected void setUp() { try { boolean miniMR = false; String hadoopVer; if ("$clusterMode".equals("miniMR")) miniMR = true; hadoopVer = "$hadoopVersion"; qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()", miniMR, hadoopVer); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception in setup"); } } @Override protected void tearDown() { try { qt.shutdown(); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception in tearDown"); } } public static Test suite() { TestSuite suite = new TestSuite(); #foreach ($qf in $qfiles) #set ($fname = $qf.getName()) #set ($eidx = $fname.length() - 2) #set ($tname = $fname.substring(0, $eidx)) suite.addTest(new $className("testCliDriver_$tname")); #end return suite; } static String debugHint = "\nSee build/ql/tmp/hive.log, " + "or try \"ant test ... -Dtest.silent=false\" to get more logs."; #foreach ($qf in $qfiles) #set ($fname = $qf.getName()) #set ($eidx = $fname.length() - 2) #set ($tname = $fname.substring(0, $eidx)) public void testCliDriver_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); qt.addFile("$qf.getCanonicalPath()"); if (qt.shouldBeSkipped("$fname")) { return; } qt.cliInit("$fname"); int ecode = qt.executeClient("$fname"); if (ecode != 0) { fail("Client Execution failed with error code = " + ecode + debugHint); } if (SessionState.get() != null) { HiveHistoryViewer hv = new HiveHistoryViewer(SessionState.get() .getHiveHistory().getHistFileName()); Map jobInfoMap = hv.getJobInfoMap(); Map taskInfoMap = hv.getTaskInfoMap(); if(jobInfoMap.size() != 0) { String cmd = (String)jobInfoMap.keySet().toArray()[0]; QueryInfo ji = jobInfoMap.get(cmd); if (!ji.hm.get(Keys.QUERY_RET_CODE.name()).equals("0")) { fail("Wrong return code in hive history" + debugHint); } } } ecode = qt.checkCliDriverResults("$fname"); if (ecode != 0) { fail("Client execution results failed with error code = " + ecode + debugHint); } } catch (Throwable e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception" + debugHint); } System.out.println("Done query: " + "$fname"); assertTrue("Test passed", true); } #end }