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