PageRenderTime 34ms CodeModel.GetById 14ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
text | 115 lines | 97 code | 18 blank | 0 comment | 0 complexity | 69e70bfc899a4b52d01479d85b5ac984 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()",
 24                         miniMR, hadoopVer);
 25    } catch (Exception e) {
 26      System.out.println("Exception: " + e.getMessage());
 27      e.printStackTrace();
 28      System.out.flush();
 29      fail("Unexpected exception in static initialization");
 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("testParseNegative_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  /**
 53   * Dummy last test. This is only meant to shutdown qt
 54   */
 55  public void testParseNegative_shutdown() {
 56    System.out.println ("Cleaning up " + "$className");
 57  }
 58
 59  public static Test suite() {
 60    TestSuite suite = new TestSuite();
 61
 62#foreach ($qf in $qfiles)
 63  #set ($fname = $qf.getName())
 64  #set ($eidx = $fname.indexOf('.'))
 65  #set ($tname = $fname.substring(0, $eidx))
 66    suite.addTest(new $className("testParseNegative_$tname"));
 67#end
 68    suite.addTest(new $className("testParseNegative_shutdown"));
 69    return suite;
 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 testParseNegative_$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      List<Task<? extends Serializable>> tasks = qt.analyzeAST(tree);
 88      fail("Unexpected success for query: " + "$fname" + debugHint);
 89    }
 90    catch (ParseException pe) {
 91      int ecode = qt.checkNegativeResults("$fname", pe);
 92      if (ecode != 0) {
 93        fail("failed with error code = " + ecode + debugHint);
 94      }
 95    }
 96    catch (SemanticException se) {
 97      int ecode = qt.checkNegativeResults("$fname", se);
 98      if (ecode != 0) {
 99        fail("failed with error code = " + ecode + debugHint);
100      }
101    }
102    catch (Throwable e) {
103      System.out.println("Exception: " + e.getMessage());
104      e.printStackTrace();
105      System.out.flush();
106      fail("Unexpected exception" + debugHint);
107    }
108
109    System.out.println("Done query: " + "$fname");
110    assertTrue("Test passed", true);
111  }
112
113#end
114}
115