package org.apache.hadoop.hive.ql.parse; 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; public class $className extends TestCase { private static QTestUtil qt; static { try { boolean miniMR = false; if ("$clusterMode".equals("miniMR")) miniMR = true; String 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 static initialization"); } } public $className(String name) { super(name); } @Override protected void tearDown() { try { qt.clearPostTestEffects(); if (getName().equals("testParse_shutdown")) 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.indexOf('.')) #set ($tname = $fname.substring(0, $eidx)) suite.addTest(new $className("testParse_$tname")); #end suite.addTest(new $className("testParse_shutdown")); return suite; } /** * Dummy last test. This is only meant to shutdown qt */ public void testParse_shutdown() { System.out.println ("Cleaning up " + "$className"); } 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.indexOf('.')) #set ($tname = $fname.substring(0, $eidx)) 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); if (ecode != 0) { fail("Parse has unexpected out with error code = " + ecode + debugHint); } List> tasks = qt.analyzeAST(tree); ecode = qt.checkPlan("$fname", tasks); if (ecode != 0) { fail("Semantic Analysis has unexpected output with error code = " + ecode + debugHint); } System.out.println("Done query: " + "$fname"); } catch (Throwable e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception" + debugHint); } assertTrue("Test passed", true); } #end }