| /** |
| * 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.cli; |
| |
| import junit.framework.Test; |
| import junit.framework.TestCase; |
| import junit.framework.TestSuite; |
| |
| import java.io.*; |
| import java.util.*; |
| |
| import org.apache.hadoop.hive.hbase.HBaseQTestUtil; |
| import org.apache.hadoop.hive.hbase.HBaseTestSetup; |
| import org.apache.hadoop.hive.ql.session.SessionState; |
| |
| public class $className extends TestCase { |
| |
| private static final String HIVE_ROOT = HBaseQTestUtil.ensurePathEndsInSlash(System.getProperty("hive.root")); |
| private HBaseQTestUtil qt; |
| private HBaseTestSetup setup; |
| |
| public $className(String name, HBaseTestSetup setup) { |
| super(name); |
| qt = null; |
| this.setup = setup; |
| } |
| |
| @Override |
| protected void setUp() { |
| try { |
| boolean miniMR = "$clusterMode".equals("miniMR"); |
| qt = new HBaseQTestUtil((HIVE_ROOT + "$resultsDir"), (HIVE_ROOT + "$logDir"), miniMR, setup); |
| |
| } catch (Exception e) { |
| System.err.println("Exception: " + e.getMessage()); |
| e.printStackTrace(); |
| System.err.flush(); |
| fail("Unexpected exception in setup"); |
| } |
| } |
| |
| @Override |
| protected void tearDown() { |
| try { |
| qt.shutdown(); |
| } |
| catch (Exception e) { |
| System.err.println("Exception: " + e.getMessage()); |
| e.printStackTrace(); |
| System.err.flush(); |
| fail("Unexpected exception in tearDown"); |
| } |
| } |
| |
| 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(); |
| HBaseTestSetup setup = new HBaseTestSetup(suite); |
| #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("testCliDriver_$tname", setup)); |
| } |
| #end |
| return setup; |
| } |
| |
| #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 testCliDriver_$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); |
| |
| if (qt.shouldBeSkipped(fname)) { |
| System.err.println("Test " + fname + " skipped"); |
| return; |
| } |
| |
| qt.cliInit(fname); |
| qt.clearTestSideEffects(); |
| int ecode = qt.executeClient(fname); |
| if (ecode != 0) { |
| fail("Client Execution failed with error code = " + ecode); |
| } |
| |
| ecode = qt.checkCliDriverResults(fname); |
| if (ecode != 0) { |
| fail("Client execution results failed with error code = " + ecode); |
| } |
| qt.clearPostTestEffects(); |
| |
| } catch (Throwable e) { |
| System.err.println("Exception: " + e.getMessage()); |
| e.printStackTrace(); |
| System.err.println("Failed query: " + fname); |
| System.err.flush(); |
| fail("Unexpected exception"); |
| } |
| |
| long elapsedTime = System.currentTimeMillis() - startTime; |
| System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime/1000 + "s"); |
| assertTrue("Test passed", true); |
| } |
| } |
| |