Repository: sqoop Updated Branches: refs/heads/sqoop2 185708672 -> a59d69f6c
SQOOP-1953: Sqoop2: Tomcat at beginning of Suite (Abraham Elmahrek via Jarek Jarcec Cecho) Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/a59d69f6 Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/a59d69f6 Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/a59d69f6 Branch: refs/heads/sqoop2 Commit: a59d69f6c45cd44c555b0f855fcce928874201a9 Parents: 1857086 Author: Jarek Jarcec Cecho <[email protected]> Authored: Sun Apr 26 14:59:16 2015 -0700 Committer: Jarek Jarcec Cecho <[email protected]> Committed: Sun Apr 26 14:59:16 2015 -0700 ---------------------------------------------------------------------- pom.xml | 2 +- test/pom.xml | 18 +++++ .../minicluster/TomcatSqoopMiniCluster.java | 13 +++- .../sqoop/test/testcases/TomcatTestCase.java | 78 ++++++++++++-------- .../upgrade/DerbyRepositoryUpgradeTest.java | 35 ++++++++- .../test/resources/integration-tests-suite.xml | 6 -- test/src/test/resources/upgrade-tests-suite.xml | 29 ++++++++ 7 files changed, 137 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index bc2bec7..6e5e038 100644 --- a/pom.xml +++ b/pom.xml @@ -656,7 +656,7 @@ limitations under the License. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.14</version> + <version>2.18.1</version> <configuration> <forkCount>1</forkCount> <reuseForks>false</reuseForks> http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/pom.xml ---------------------------------------------------------------------- diff --git a/test/pom.xml b/test/pom.xml index 98a60f6..a9502d2 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -196,6 +196,24 @@ limitations under the License. <suiteXmlFiles> <suiteXmlFile>src/test/resources/integration-tests-suite.xml</suiteXmlFile> </suiteXmlFiles> + <properties> + <suitename>integration-tests</suitename> + </properties> + </configuration> + </execution> + <execution> + <id>upgrade-test</id> + <goals> + <goal>test</goal> + </goals> + <phase>integration-test</phase> + <configuration> + <suiteXmlFiles> + <suiteXmlFile>src/test/resources/upgrade-tests-suite.xml</suiteXmlFile> + </suiteXmlFiles> + <properties> + <suitename>upgrade-tests</suitename> + </properties> </configuration> </execution> </executions> http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java b/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java index 4d27886..5a6773d 100644 --- a/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java +++ b/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java @@ -71,12 +71,18 @@ public class TomcatSqoopMiniCluster extends SqoopMiniCluster { prepareTemporaryPath(); + // Source: http://cargo.codehaus.org/Functional+testing + String tomcatPath = getTemporaryPath() + "/tomcat"; + String extractPath = tomcatPath + "/extract"; + String confPath = tomcatPath + "/conf"; + // TODO(jarcec): We should parametrize those paths, version, etc... // Source: http://cargo.codehaus.org/Functional+testing - Installer installer = new ZipURLInstaller(new URL("http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.zip")); + // Use null download path so that download path can be shared. + Installer installer = new ZipURLInstaller(new URL("http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.zip"), null, extractPath); installer.install(); - LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory().createConfiguration("tomcat6x", ContainerType.INSTALLED, ConfigurationType.STANDALONE); + LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory().createConfiguration("tomcat6x", ContainerType.INSTALLED, ConfigurationType.STANDALONE, confPath); container = (InstalledLocalContainer) new DefaultContainerFactory().createContainer("tomcat6x", ContainerType.INSTALLED, configuration); // Set home to our installed tomcat instance @@ -132,6 +138,9 @@ public class TomcatSqoopMiniCluster extends SqoopMiniCluster { configuration.setProperty(ServletPropertySet.PORT, port.toString()); // Start Sqoop server + LOG.info("Tomcat extract path: " + extractPath); + LOG.info("Tomcat home path: " + installer.getHome()); + LOG.info("Tomcat config home path: " + confPath); LOG.info("Starting tomcat server on port " + port); container.start(); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/src/main/java/org/apache/sqoop/test/testcases/TomcatTestCase.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/TomcatTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/TomcatTestCase.java index 6729cc7..666749b 100644 --- a/test/src/main/java/org/apache/sqoop/test/testcases/TomcatTestCase.java +++ b/test/src/main/java/org/apache/sqoop/test/testcases/TomcatTestCase.java @@ -34,7 +34,7 @@ import org.apache.sqoop.test.minicluster.SqoopMiniCluster; import org.apache.sqoop.test.minicluster.TomcatSqoopMiniCluster; import org.apache.sqoop.test.utils.HdfsUtils; import org.testng.ITest; -import org.testng.annotations.AfterMethod; +import org.testng.ITestContext; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; @@ -62,13 +62,11 @@ abstract public class TomcatTestCase implements ITest { /** * Temporary directory that will be used by the test. * - * We will take TMP_PATH_BASE and append two subdirectories. First will be named - * after fully qualified class name of current test class, second directory will - * be named after current test method name. For example: + * We will take TMP_PATH_BASE and append the test suite. For example: * - * TMP_PATH_BASE/org.apache.sqoop.TestClass/testMethod/ + * TMP_PATH_BASE/TestConnectorsSuite */ - private String tmpPath; + private static String tmpPath; /** * Hadoop cluster @@ -83,12 +81,12 @@ abstract public class TomcatTestCase implements ITest { /** * Tomcat based Sqoop mini cluster */ - private TomcatSqoopMiniCluster cluster; + private static TomcatSqoopMiniCluster cluster; /** * Sqoop client API. */ - private SqoopClient client; + private static SqoopClient client; /** * Use the method name as the test name @@ -97,11 +95,32 @@ abstract public class TomcatTestCase implements ITest { return methodName; } + @BeforeMethod(alwaysRun = true) + public void setMethodName(Method method) throws Exception { + methodName = method.getName(); + } + @BeforeSuite(alwaysRun = true) - public void startHadoop() throws Exception { + public void setupSuite(ITestContext context) throws Exception { + tmpPath = HdfsUtils.joinPathFragments(TMP_PATH_BASE, context.getSuite().getName()); + + LOG.debug("Temporary Directory: " + getTemporaryPath()); + FileUtils.deleteDirectory(new File(getTemporaryPath())); + + startHadoop(); + startSqoop(); + } + + @AfterSuite(alwaysRun = true) + public void tearDownSuite() throws Exception { + stopSqoop(); + stopHadoop(); + } + + protected void startHadoop() throws Exception { // Start Hadoop Clusters hadoopCluster = HadoopRunnerFactory.getHadoopCluster(System.getProperties(), HadoopMiniClusterRunner.class); - hadoopCluster.setTemporaryPath(TMP_PATH_BASE); + hadoopCluster.setTemporaryPath(getTemporaryPath()); hadoopCluster.setConfiguration(hadoopCluster.prepareConfiguration(new JobConf())); hadoopCluster.start(); @@ -110,16 +129,7 @@ abstract public class TomcatTestCase implements ITest { LOG.debug("HDFS Client: " + hdfsClient); } - @BeforeMethod(alwaysRun = true) - public void startServer(Method method) throws Exception { - methodName = method.getName(); - - // Get and set temporary path in hadoop cluster. - tmpPath = HdfsUtils.joinPathFragments(TMP_PATH_BASE, getClass().getName(), getTestName()); - FileUtils.deleteDirectory(new File(tmpPath)); - - LOG.debug("Temporary Directory: " + tmpPath); - + protected void startSqoop() throws Exception { // Start server cluster = createSqoopMiniCluster(); cluster.start(); @@ -128,21 +138,17 @@ abstract public class TomcatTestCase implements ITest { client = new SqoopClient(getServerUrl()); } - @AfterMethod(alwaysRun = true) - public void stopServer() throws Exception { + protected void stopSqoop() throws Exception { cluster.stop(); } - @AfterSuite(alwaysRun = true) - public static void stopHadoop() throws Exception { + protected void stopHadoop() throws Exception { hadoopCluster.stop(); } /** * Create Sqoop MiniCluster instance that should be used for this test. * - * This method will be executed only once prior each test execution. - * * @return New instance of test mini cluster */ public TomcatSqoopMiniCluster createSqoopMiniCluster() throws Exception { @@ -154,20 +160,28 @@ abstract public class TomcatTestCase implements ITest { * * @return */ - public SqoopClient getClient() { + public static SqoopClient getClient() { return client; } - public SqoopMiniCluster getCluster() { + public static void setClient(SqoopClient sqoopClient) { + client = sqoopClient; + } + + public static SqoopMiniCluster getCluster() { return cluster; } - public String getTemporaryPath() { + public static void setCluster(TomcatSqoopMiniCluster sqoopMiniClusterluster) { + cluster = sqoopMiniClusterluster; + } + + public static String getTemporaryPath() { return tmpPath; } - public String getSqoopMiniClusterTemporaryPath() { - return HdfsUtils.joinPathFragments(tmpPath, "sqoop-mini-cluster"); + public static String getSqoopMiniClusterTemporaryPath() { + return HdfsUtils.joinPathFragments(getTemporaryPath(), "sqoop-mini-cluster"); } /** @@ -175,7 +189,7 @@ abstract public class TomcatTestCase implements ITest { * * @return */ - public String getServerUrl() { + public static String getServerUrl() { return cluster.getServerUrl(); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/DerbyRepositoryUpgradeTest.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/DerbyRepositoryUpgradeTest.java b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/DerbyRepositoryUpgradeTest.java index a687c16..d305620 100644 --- a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/DerbyRepositoryUpgradeTest.java +++ b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/DerbyRepositoryUpgradeTest.java @@ -18,10 +18,14 @@ package org.apache.sqoop.integration.repository.derby.upgrade; import org.apache.hadoop.conf.Configuration; +import org.apache.sqoop.client.SqoopClient; import org.apache.sqoop.test.minicluster.TomcatSqoopMiniCluster; import org.apache.sqoop.test.testcases.TomcatTestCase; import org.apache.sqoop.test.utils.CompressionUtils; import org.apache.sqoop.test.utils.HdfsUtils; +import org.testng.ITestContext; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.apache.log4j.Logger; @@ -120,18 +124,43 @@ public abstract class DerbyRepositoryUpgradeTest extends TomcatTestCase { public abstract Integer[] getDeleteJobIds(); public String getRepositoryPath() { - return HdfsUtils.joinPathFragments(getTemporaryPath(), "repo"); + return HdfsUtils.joinPathFragments(getTemporaryTomcatPath(), "repo"); + } + + public String getTemporaryTomcatPath() { + return HdfsUtils.joinPathFragments(getTemporaryPath(), getClass().getCanonicalName(), getTestName()); + } + + @Override + public void startSqoop() throws Exception { + // Do nothing so that Sqoop isn't started before Suite. } @Override - public TomcatSqoopMiniCluster createSqoopMiniCluster() throws Exception { + public void stopSqoop() throws Exception { + // Do nothing so that Sqoop isn't stopped after Suite. + } + + @BeforeMethod + public void startSqoopMiniCluster(ITestContext context) throws Exception { // Prepare older repository structures InputStream tarballStream = getClass().getResourceAsStream(getPathToRepositoryTarball()); assertNotNull(tarballStream); CompressionUtils.untarStreamToDirectory(tarballStream, getRepositoryPath()); // And use them for new Derby repo instance - return new DerbySqoopMiniCluster(getRepositoryPath(), getSqoopMiniClusterTemporaryPath(), hadoopCluster.getConfiguration()); + setCluster(new DerbySqoopMiniCluster(getRepositoryPath(), getTemporaryTomcatPath() + "/sqoop-mini-cluster", hadoopCluster.getConfiguration())); + + // Start server + getCluster().start(); + + // Initialize Sqoop Client API + setClient(new SqoopClient(getServerUrl())); + } + + @AfterMethod + public void stopSqoopMiniCluster() throws Exception { + getCluster().stop(); } @Test http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/src/test/resources/integration-tests-suite.xml ---------------------------------------------------------------------- diff --git a/test/src/test/resources/integration-tests-suite.xml b/test/src/test/resources/integration-tests-suite.xml index 101b6ec..f0dd905 100644 --- a/test/src/test/resources/integration-tests-suite.xml +++ b/test/src/test/resources/integration-tests-suite.xml @@ -26,12 +26,6 @@ limitations under the License. </packages> </test> - <test name="RepositoryTests"> - <packages> - <package name="org.apache.sqoop.integration.repository.derby.upgrade"/> - </packages> - </test> - <test name="ServerTests"> <packages> <package name="org.apache.sqoop.integration.server"/> http://git-wip-us.apache.org/repos/asf/sqoop/blob/a59d69f6/test/src/test/resources/upgrade-tests-suite.xml ---------------------------------------------------------------------- diff --git a/test/src/test/resources/upgrade-tests-suite.xml b/test/src/test/resources/upgrade-tests-suite.xml new file mode 100644 index 0000000..2856556 --- /dev/null +++ b/test/src/test/resources/upgrade-tests-suite.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > + +<suite name="UpgradeTests" verbose="2" parallel="false"> + + <test name="RepositoryTests"> + <packages> + <package name="org.apache.sqoop.integration.repository.derby.upgrade"/> + </packages> + </test> + +</suite> \ No newline at end of file
