PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 1ms 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
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()",
  18. miniMR, hadoopVer);
  19. } catch (Exception e) {
  20. System.out.println("Exception: " + e.getMessage());
  21. e.printStackTrace();
  22. System.out.flush();
  23. fail("Unexpected exception in static initialization");
  24. }
  25. }
  26. public $className(String name) {
  27. super(name);
  28. }
  29. @Override
  30. protected void tearDown() {
  31. try {
  32. qt.clearPostTestEffects();
  33. if (getName().equals("testParseNegative_shutdown"))
  34. qt.shutdown();
  35. }
  36. catch (Exception e) {
  37. System.out.println("Exception: " + e.getMessage());
  38. e.printStackTrace();
  39. System.out.flush();
  40. fail("Unexpected exception in tearDown");
  41. }
  42. }
  43. /**
  44. * Dummy last test. This is only meant to shutdown qt
  45. */
  46. public void testParseNegative_shutdown() {
  47. System.out.println ("Cleaning up " + "$className");
  48. }
  49. public static Test suite() {
  50. TestSuite suite = new TestSuite();
  51. #foreach ($qf in $qfiles)
  52. #set ($fname = $qf.getName())
  53. #set ($eidx = $fname.indexOf('.'))
  54. #set ($tname = $fname.substring(0, $eidx))
  55. suite.addTest(new $className("testParseNegative_$tname"));
  56. #end
  57. suite.addTest(new $className("testParseNegative_shutdown"));
  58. return suite;
  59. }
  60. static String debugHint = "\nSee build/ql/tmp/hive.log, "
  61. + "or try \"ant test ... -Dtest.silent=false\" to get more logs.";
  62. #foreach ($qf in $qfiles)
  63. #set ($fname = $qf.getName())
  64. #set ($eidx = $fname.indexOf('.'))
  65. #set ($tname = $fname.substring(0, $eidx))
  66. public void testParseNegative_$tname() throws Exception {
  67. try {
  68. System.out.println("Begin query: " + "$fname");
  69. qt.addFile("$qf.getCanonicalPath()");
  70. qt.init("$fname");
  71. ASTNode tree = qt.parseQuery("$fname");
  72. List<Task<? extends Serializable>> tasks = qt.analyzeAST(tree);
  73. fail("Unexpected success for query: " + "$fname" + debugHint);
  74. }
  75. catch (ParseException pe) {
  76. int ecode = qt.checkNegativeResults("$fname", pe);
  77. if (ecode != 0) {
  78. fail("failed with error code = " + ecode + debugHint);
  79. }
  80. }
  81. catch (SemanticException se) {
  82. int ecode = qt.checkNegativeResults("$fname", se);
  83. if (ecode != 0) {
  84. fail("failed with error code = " + ecode + debugHint);
  85. }
  86. }
  87. catch (Throwable e) {
  88. System.out.println("Exception: " + e.getMessage());
  89. e.printStackTrace();
  90. System.out.flush();
  91. fail("Unexpected exception" + debugHint);
  92. }
  93. System.out.println("Done query: " + "$fname");
  94. assertTrue("Test passed", true);
  95. }
  96. #end
  97. }