Repository: hive Updated Branches: refs/heads/master ce7b353ca -> 86510f773
HIVE-14460 : AccumuloCliDriver migration to junit4 (Zoltan Haindrich via Ashutosh Chauhan) Signed-off-by: Ashutosh Chauhan <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/86510f77 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/86510f77 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/86510f77 Branch: refs/heads/master Commit: 86510f7735144390e969b47d678d58f23b05dccf Parents: ce7b353 Author: Zoltan Haindrich <[email protected]> Authored: Sat Aug 13 11:15:15 2016 -0700 Committer: Ashutosh Chauhan <[email protected]> Committed: Sat Aug 13 11:15:15 2016 -0700 ---------------------------------------------------------------------- .../src/test/templates/TestAccumuloCliDriver.vm | 147 ------------------- .../hadoop/hive/cli/TestAccumuloCliDriver.java | 62 ++++++++ .../hadoop/hive/accumulo/AccumuloTestSetup.java | 8 +- .../hadoop/hive/cli/control/CliConfigs.java | 4 +- .../hive/cli/control/CoreAccumuloCliDriver.java | 111 ++++++++++++++ 5 files changed, 177 insertions(+), 155 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/86510f77/accumulo-handler/src/test/templates/TestAccumuloCliDriver.vm ---------------------------------------------------------------------- diff --git a/accumulo-handler/src/test/templates/TestAccumuloCliDriver.vm b/accumulo-handler/src/test/templates/TestAccumuloCliDriver.vm deleted file mode 100644 index 9872291..0000000 --- a/accumulo-handler/src/test/templates/TestAccumuloCliDriver.vm +++ /dev/null @@ -1,147 +0,0 @@ -/** - * 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.accumulo.AccumuloQTestUtil; -import org.apache.hadoop.hive.accumulo.AccumuloTestSetup; -import org.apache.hadoop.hive.ql.QTestUtil; -import org.apache.hadoop.hive.ql.QTestUtil.MiniClusterType; -import org.apache.hadoop.hive.ql.session.SessionState; - -public class $className extends TestCase { - - private static final String HIVE_ROOT = AccumuloQTestUtil.ensurePathEndsInSlash(System.getProperty("hive.root")); - private AccumuloQTestUtil qt; - private AccumuloTestSetup setup; - - public static class TestAccumuloCliDriverAddTestFromQFiles implements QTestUtil.SuiteAddTestFunctor { - public void addTestToSuite(TestSuite suite, Object setup, String tName) { - suite.addTest(new $className("testCliDriver_"+tName, (AccumuloTestSetup)setup)); - } - } - - public $className(String name, AccumuloTestSetup setup) { - super(name); - qt = null; - this.setup = setup; - } - - @Override - protected void setUp() { - - MiniClusterType miniMR = MiniClusterType.valueForString("$clusterMode"); - String initScript = "$initScript"; - String cleanupScript = "$cleanupScript"; - - try { - qt = new AccumuloQTestUtil((HIVE_ROOT + "$resultsDir"), (HIVE_ROOT + "$logDir"), miniMR, - setup, initScript, cleanupScript); - } catch (Exception e) { - System.err.println("Exception: " + e.getMessage()); - e.printStackTrace(); - System.err.flush(); - fail("Unexpected exception in setup: " + e); - } - } - - @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(); - AccumuloTestSetup setup = new AccumuloTestSetup(suite); - - QTestUtil.addTestsToSuiteFromQfileNames("$qFileNamesFile", qFilesToExecute, - suite, setup, new TestAccumuloCliDriverAddTestFromQFiles()); - 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) { - qt.failed(ecode, fname, null); - } - - ecode = qt.checkCliDriverResults(fname); - if (ecode != 0) { - qt.failedDiff(ecode, fname, null); - } - qt.clearPostTestEffects(); - - } catch (Throwable e) { - qt.failed(e, fname, null); - } - - long elapsedTime = System.currentTimeMillis() - startTime; - System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime/1000 + "s"); - assertTrue("Test passed", true); - } -} - http://git-wip-us.apache.org/repos/asf/hive/blob/86510f77/itests/qtest-accumulo/src/test/java/org/apache/hadoop/hive/cli/TestAccumuloCliDriver.java ---------------------------------------------------------------------- diff --git a/itests/qtest-accumulo/src/test/java/org/apache/hadoop/hive/cli/TestAccumuloCliDriver.java b/itests/qtest-accumulo/src/test/java/org/apache/hadoop/hive/cli/TestAccumuloCliDriver.java new file mode 100644 index 0000000..bf50f16 --- /dev/null +++ b/itests/qtest-accumulo/src/test/java/org/apache/hadoop/hive/cli/TestAccumuloCliDriver.java @@ -0,0 +1,62 @@ +/** + * 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 java.io.File; +import java.util.List; + +import org.apache.hadoop.hive.cli.control.CliAdapter; +import org.apache.hadoop.hive.cli.control.CliConfigs; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class TestAccumuloCliDriver { + + static CliAdapter adapter = new CliConfigs.AccumuloCliConfig().getCliAdapter(); + + @Parameters(name = "{0}") + public static List<Object[]> getParameters() throws Exception { + return adapter.getParameters(); + } + + @ClassRule + public static TestRule cliClassRule = adapter.buildClassRule(); + + @Rule + public TestRule cliTestRule = adapter.buildTestRule(); + + private String name; + private File qfile; + + public TestAccumuloCliDriver(String name, File qfile) { + this.name = name; + this.qfile = qfile; + } + + @Test + public void testCliDriver() throws Exception { + adapter.runTest(name, qfile); + } + +} http://git-wip-us.apache.org/repos/asf/hive/blob/86510f77/itests/util/src/main/java/org/apache/hadoop/hive/accumulo/AccumuloTestSetup.java ---------------------------------------------------------------------- diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/accumulo/AccumuloTestSetup.java b/itests/util/src/main/java/org/apache/hadoop/hive/accumulo/AccumuloTestSetup.java index 132e8c8..73d5f15 100644 --- a/itests/util/src/main/java/org/apache/hadoop/hive/accumulo/AccumuloTestSetup.java +++ b/itests/util/src/main/java/org/apache/hadoop/hive/accumulo/AccumuloTestSetup.java @@ -40,14 +40,13 @@ import org.apache.hadoop.hive.conf.HiveConf; /** * Start and stop an AccumuloMiniCluster for testing purposes */ -public class AccumuloTestSetup extends TestSetup { +public class AccumuloTestSetup { public static final String PASSWORD = "password"; public static final String TABLE_NAME = "accumuloHiveTable"; protected MiniAccumuloCluster miniCluster; - public AccumuloTestSetup(Test test) { - super(test); + public AccumuloTestSetup() { } protected void setupWithHiveConf(HiveConf conf) throws Exception { @@ -117,8 +116,7 @@ public class AccumuloTestSetup extends TestSetup { } } - @Override - protected void tearDown() throws Exception { + public void tearDown() throws Exception { if (null != miniCluster) { miniCluster.stop(); miniCluster = null; http://git-wip-us.apache.org/repos/asf/hive/blob/86510f77/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java ---------------------------------------------------------------------- diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java b/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java index e7af372..2c82e99 100644 --- a/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java +++ b/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CliConfigs.java @@ -411,11 +411,9 @@ public class CliConfigs { } } - // XXX: pending merge of ACC ; and upgrade of executor public static class AccumuloCliConfig extends AbstractCliConfig { public AccumuloCliConfig() { - super(null); - // super(CoreAccumuloCliDriver.class); + super(CoreAccumuloCliDriver.class); try { setQueryDir("accumulo-handler/src/test/queries/positive"); http://git-wip-us.apache.org/repos/asf/hive/blob/86510f77/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CoreAccumuloCliDriver.java ---------------------------------------------------------------------- diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CoreAccumuloCliDriver.java b/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CoreAccumuloCliDriver.java new file mode 100644 index 0000000..a5d2711 --- /dev/null +++ b/itests/util/src/main/java/org/apache/hadoop/hive/cli/control/CoreAccumuloCliDriver.java @@ -0,0 +1,111 @@ +/** + * 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.control; + +import static org.junit.Assert.assertTrue; +import org.apache.hadoop.hive.accumulo.AccumuloQTestUtil; +import org.apache.hadoop.hive.accumulo.AccumuloTestSetup; +import org.apache.hadoop.hive.ql.QTestUtil.MiniClusterType; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +public class CoreAccumuloCliDriver extends CliAdapter { + + private AccumuloQTestUtil qt; + private static AccumuloTestSetup setup; + + public CoreAccumuloCliDriver(AbstractCliConfig cliConfig) { + super(cliConfig); + } + + @Override + @BeforeClass + public void beforeClass() { + setup = new AccumuloTestSetup(); + } + @Override + @AfterClass + public void shutdown() throws Exception { + // FIXME: possibly missing + // setup.tearDown(); + } + @Override + @Before + public void setUp() { + + MiniClusterType miniMR = cliConfig.getClusterType(); + String initScript = cliConfig.getInitScript(); + String cleanupScript = cliConfig.getCleanupScript(); + + try { + qt = new AccumuloQTestUtil(cliConfig.getResultsDir(), cliConfig.getLogDir(), miniMR, + setup, initScript, cleanupScript); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception in setUp",e); + } + } + + @Override + @After + public void tearDown() { + try { + qt.shutdown(); + } + catch (Exception e) { + throw new RuntimeException("Unexpected exception in tearDown",e); + } + } + + @Override + public 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) { + qt.failed(ecode, fname, null); + } + + ecode = qt.checkCliDriverResults(fname); + if (ecode != 0) { + qt.failedDiff(ecode, fname, null); + } + qt.clearPostTestEffects(); + + } catch (Throwable e) { + qt.failed(e, fname, null); + } + + long elapsedTime = System.currentTimeMillis() - startTime; + System.err.println("Done query: " + fname + " elapsedTime=" + elapsedTime/1000 + "s"); + assertTrue("Test passed", true); + } +} +
