From a59d69f6c45cd44c555b0f855fcce928874201a9 Mon Sep 17 00:00:00 2001 From: Jarek Jarcec Cecho Date: Sun, 26 Apr 2015 14:59:16 -0700 Subject: [PATCH] SQOOP-1953: Sqoop2: Tomcat at beginning of Suite (Abraham Elmahrek via Jarek Jarcec Cecho) --- pom.xml | 2 +- test/pom.xml | 18 +++++ .../minicluster/TomcatSqoopMiniCluster.java | 13 +++- .../sqoop/test/testcases/TomcatTestCase.java | 78 +++++++++++-------- .../upgrade/DerbyRepositoryUpgradeTest.java | 35 ++++++++- .../resources/integration-tests-suite.xml | 6 -- .../test/resources/upgrade-tests-suite.xml | 29 +++++++ 7 files changed, 137 insertions(+), 44 deletions(-) create mode 100644 test/src/test/resources/upgrade-tests-suite.xml diff --git a/pom.xml b/pom.xml index bc2bec70..6e5e038e 100644 --- a/pom.xml +++ b/pom.xml @@ -656,7 +656,7 @@ limitations under the License. org.apache.maven.plugins maven-surefire-plugin - 2.14 + 2.18.1 1 false diff --git a/test/pom.xml b/test/pom.xml index 98a60f66..a9502d29 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -196,6 +196,24 @@ limitations under the License. src/test/resources/integration-tests-suite.xml + + integration-tests + + + + + upgrade-test + + test + + integration-test + + + src/test/resources/upgrade-tests-suite.xml + + + upgrade-tests + 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 4d27886d..5a6773dc 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 void start() throws Exception { 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 void start() throws Exception { 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(); } 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 6729cc70..666749bb 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.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 @@ public String getTestName() { 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 @@ public void startHadoop() throws Exception { 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 @@ public void startServer(Method method) throws Exception { 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 @@ public TomcatSqoopMiniCluster createSqoopMiniCluster() throws Exception { * * @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 @@ public String getSqoopMiniClusterTemporaryPath() { * * @return */ - public String getServerUrl() { + public static String getServerUrl() { return cluster.getServerUrl(); } 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 a687c168..d3056206 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 @@ protected Map getRepositoryConfiguration() { 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 TomcatSqoopMiniCluster createSqoopMiniCluster() throws Exception { + public void startSqoop() throws Exception { + // Do nothing so that Sqoop isn't started before Suite. + } + + @Override + 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 diff --git a/test/src/test/resources/integration-tests-suite.xml b/test/src/test/resources/integration-tests-suite.xml index 101b6ec6..f0dd905b 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. - - - - - - 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 00000000..2856556b --- /dev/null +++ b/test/src/test/resources/upgrade-tests-suite.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file