blob: 1aec083e7161396c51c68d6442867c1ae118493d [file]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 final String HIVE_ROOT = QTestUtil.ensurePathEndsInSlash(System.getProperty("hive.root"));
private static QTestUtil qt;
static {
try {
boolean miniMR = "$clusterMode".equals("miniMR");
String hadoopVer = "$hadoopVersion";
qt = new QTestUtil((HIVE_ROOT + "$resultsDir"), (HIVE_ROOT + "$logDir"), miniMR, hadoopVer);
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
e.printStackTrace();
System.err.flush();
fail("Unexpected exception in static initialization");
}
}
public $className(String name) {
super(name);
}
@Override
protected void tearDown() {
try {
qt.clearPostTestEffects();
if (getName().equals("testParseNegative_shutdown"))
qt.shutdown();
}
catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
e.printStackTrace();
System.err.flush();
fail("Unexpected exception in tearDown");
}
}
/**
* Dummy last test. This is only meant to shutdown qt
*/
public void testParseNegative_shutdown() {
System.err.println ("Cleaning up " + "$className");
}
public static Test suite() {
Set<String> qFilesToExecute = new HashSet<String>();
String qFiles = System.getProperty("qfile", "").trim();
if(!qFiles.isEmpty()) {
for(String qFile : qFiles.split(",")) {
qFile = qFile.trim();
if(!qFile.isEmpty()) {
qFilesToExecute.add(qFile);
}
}
}
TestSuite suite = new TestSuite();
#foreach ($qf in $qfiles)
#set ($fname = $qf.getName())
#set ($eidx = $fname.indexOf('.'))
#set ($tname = $fname.substring(0, $eidx))
if(qFilesToExecute.isEmpty() || qFilesToExecute.contains("$fname")) {
suite.addTest(new $className("testParseNegative_$tname"));
}
#end
suite.addTest(new $className("testParseNegative_shutdown"));
return suite;
}
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))
#set ($fpath = $qfilesMap.get($fname))
public void testParseNegative_$tname() throws Exception {
runTest("$tname", "$fname", (HIVE_ROOT + "$fpath"));
}
#end
private void runTest(String tname, String fname, String fpath) throws Exception {
long startTime = System.currentTimeMillis();
try {
System.err.println("Begin query: " + fname);
qt.addFile(fpath);
qt.init(fname);
ASTNode tree = qt.parseQuery(fname);
List<Task<? extends Serializable>> tasks = qt.analyzeAST(tree);
fail("Unexpected success for query: " + fname + debugHint);
}
catch (ParseException pe) {
int ecode = qt.checkNegativeResults(fname, pe);
if (ecode != 0) {
fail("failed with error code = " + ecode + debugHint);
}
}
catch (SemanticException se) {
int ecode = qt.checkNegativeResults(fname, se);
if (ecode != 0) {
fail("failed with error code = " + ecode + debugHint);
}
}
catch (Throwable e) {
System.err.println("Exception: " + e.getMessage());
e.printStackTrace();
System.err.println("Failed query: " + fname);
System.err.flush();
fail("Unexpected exception" + debugHint);
}
long elapsedTime = System.currentTimeMillis() - startTime;
System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime/1000 + "s");
assertTrue("Test passed", true);
}
}