PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/release-0.2.0-rc0/hive/external/ql/src/test/templates/TestParse.vm

#
text | 110 lines | 92 code | 18 blank | 0 comment | 0 complexity | f834fe9d0539cdf866ccac3fbcee2258 MD5 | raw file
  1package org.apache.hadoop.hive.ql.parse;
  2
  3import junit.framework.Test;
  4import junit.framework.TestCase;
  5import junit.framework.TestSuite;
  6
  7import java.io.*;
  8import java.util.*;
  9
 10import org.apache.hadoop.hive.ql.QTestUtil;
 11import org.apache.hadoop.hive.ql.exec.Task;
 12
 13public class $className extends TestCase {
 14
 15  private static QTestUtil qt;
 16
 17  static {
 18    try {
 19      boolean miniMR = false;
 20      if ("$clusterMode".equals("miniMR"))
 21        miniMR = true;
 22      String hadoopVer = "$hadoopVersion";
 23      qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()", miniMR, hadoopVer);
 24    } catch (Exception e) {
 25      System.out.println("Exception: " + e.getMessage());
 26      e.printStackTrace();
 27      System.out.flush();
 28      fail("Unexpected exception in static initialization");
 29    }
 30  }
 31
 32
 33  public $className(String name) {
 34    super(name);
 35  }
 36
 37  @Override
 38  protected void tearDown() {
 39    try {
 40      qt.clearPostTestEffects();
 41      if (getName().equals("testParse_shutdown"))
 42        qt.shutdown();
 43    }
 44    catch (Exception e) {
 45      System.out.println("Exception: " + e.getMessage());
 46      e.printStackTrace();
 47      System.out.flush();
 48      fail("Unexpected exception in tearDown");
 49    }
 50  }
 51
 52  public static Test suite() {
 53    TestSuite suite = new TestSuite();
 54
 55#foreach ($qf in $qfiles)
 56  #set ($fname = $qf.getName())
 57  #set ($eidx = $fname.indexOf('.'))
 58  #set ($tname = $fname.substring(0, $eidx))
 59    suite.addTest(new $className("testParse_$tname"));
 60#end
 61    suite.addTest(new $className("testParse_shutdown"));
 62    return suite;
 63  }
 64
 65  /**
 66   * Dummy last test. This is only meant to shutdown qt
 67   */
 68  public void testParse_shutdown() {
 69    System.out.println ("Cleaning up " + "$className");
 70  }
 71
 72  static String debugHint = "\nSee build/ql/tmp/hive.log, "
 73     + "or try \"ant test ... -Dtest.silent=false\" to get more logs.";
 74
 75#foreach ($qf in $qfiles)
 76  #set ($fname = $qf.getName())
 77  #set ($eidx = $fname.indexOf('.'))
 78  #set ($tname = $fname.substring(0, $eidx))
 79  public void testParse_$tname() throws Exception {
 80    try {
 81      System.out.println("Begin query: " + "$fname");
 82
 83      qt.addFile("$qf.getCanonicalPath()");
 84
 85      qt.init("$fname");
 86      ASTNode tree = qt.parseQuery("$fname");
 87      int ecode = qt.checkParseResults("$fname", tree);
 88      if (ecode != 0) {
 89        fail("Parse has unexpected out with error code = " + ecode + debugHint);
 90      }
 91      List<Task<? extends Serializable>> tasks = qt.analyzeAST(tree);
 92      ecode = qt.checkPlan("$fname", tasks);
 93      if (ecode != 0) {
 94        fail("Semantic Analysis has unexpected output with error code = " + ecode
 95            + debugHint);
 96      }
 97      System.out.println("Done query: " + "$fname");
 98    }
 99    catch (Throwable e) {
100      System.out.println("Exception: " + e.getMessage());
101      e.printStackTrace();
102      System.out.flush();
103      fail("Unexpected exception" + debugHint);
104    }
105
106    assertTrue("Test passed", true);
107  }
108
109#end
110}