sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2541: Sqoop2: Provide test infrastructure base class for upgrade tests
Date Tue, 05 Jan 2016 03:03:54 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 23781db25 -> 073da06dd


SQOOP-2541: Sqoop2: Provide test infrastructure base class for upgrade tests

(Dian Fu 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/073da06d
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/073da06d
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/073da06d

Branch: refs/heads/sqoop2
Commit: 073da06dd424473758eb070f15759ba2525ec30e
Parents: 23781db
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Jan 4 19:03:02 2016 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Jan 4 19:03:38 2016 -0800

----------------------------------------------------------------------
 .../test/infrastructure/SqoopTestCase.java      | 34 +++++++++++++-------
 .../upgrade/DerbyRepositoryUpgradeTest.java     | 33 ++++++++-----------
 2 files changed, 36 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/073da06d/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
index 8fbefd8..c300b33 100644
--- a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
+++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
@@ -208,7 +208,7 @@ public class SqoopTestCase implements ITest {
    * @param <T>
    * @return
    */
-  private static <T extends InfrastructureProvider> T startInfrastructureProvider(Class<T>
providerClass, Configuration hadoopConfiguration, KdcRunner kdc) {
+  protected static <T extends InfrastructureProvider> T startInfrastructureProvider(Class<T>
providerClass, Configuration hadoopConfiguration, KdcRunner kdc) {
     T providerObject;
 
     try {
@@ -354,8 +354,19 @@ public class SqoopTestCase implements ITest {
 
   @BeforeMethod
   public void init() throws Exception {
-    String serverUrl = getSqoopServerUrl();
+    initSqoopClient(getSqoopServerUrl());
 
+    if (getInfrastructureProvider(HadoopInfrastructureProvider.class) != null) {
+      hdfsClient = FileSystem.get(getInfrastructureProvider(HadoopInfrastructureProvider.class).getHadoopConfiguration());
+      hdfsClient.delete(new Path(getMapreduceDirectory()), true);
+    }
+
+    if (getInfrastructureProvider(DatabaseInfrastructureProvider.class) != null) {
+      provider = getInfrastructureProvider(DatabaseInfrastructureProvider.class).getInstance();
+    }
+  }
+
+  protected void initSqoopClient(String serverUrl) throws Exception {
     if (serverUrl != null) {
       client = new SqoopClient(serverUrl);
 
@@ -365,15 +376,6 @@ public class SqoopTestCase implements ITest {
         kdcProvider.getInstance().authenticateWithSqoopServer(new URL(serverUrl), authToken);
       }
     }
-
-    if (getInfrastructureProvider(HadoopInfrastructureProvider.class) != null) {
-      hdfsClient = FileSystem.get(getInfrastructureProvider(HadoopInfrastructureProvider.class).getHadoopConfiguration());
-      hdfsClient.delete(new Path(getMapreduceDirectory()), true);
-    }
-
-    if (getInfrastructureProvider(DatabaseInfrastructureProvider.class) != null) {
-      provider = getInfrastructureProvider(DatabaseInfrastructureProvider.class).getInstance();
-    }
   }
 
   /**
@@ -638,4 +640,14 @@ public class SqoopTestCase implements ITest {
   protected String getSqoopMiniClusterTemporaryPath() {
     return getInfrastructureProvider(SqoopInfrastructureProvider.class).getRootPath();
   }
+
+  protected Configuration getHadoopConf() {
+    Configuration hadoopConf = null;
+    if (getInfrastructureProvider(HadoopInfrastructureProvider.class) != null) {
+      hadoopConf = getInfrastructureProvider(HadoopInfrastructureProvider.class).getHadoopConfiguration();
+    } else {
+      hadoopConf = new Configuration();
+    }
+    return hadoopConf;
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/073da06d/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 cbc243c..44f4a5b 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,11 +18,13 @@
 package org.apache.sqoop.integration.repository.derby.upgrade;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.sqoop.client.SqoopClient;
 import org.apache.sqoop.model.MJob;
 import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.SqoopTestCase;
+import org.apache.sqoop.test.infrastructure.providers.KdcInfrastructureProvider;
 import org.apache.sqoop.test.minicluster.JettySqoopMiniCluster;
-import org.apache.sqoop.test.testcases.JettyTestCase;
+import org.apache.sqoop.test.minicluster.SqoopMiniCluster;
 import org.apache.sqoop.test.utils.CompressionUtils;
 import org.apache.sqoop.test.utils.HdfsUtils;
 import org.testng.ITestContext;
@@ -30,7 +32,6 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import org.apache.log4j.Logger;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -53,12 +54,14 @@ import static org.testng.Assert.assertNotNull;
  * methods describing content of the repository (what links/jobs it have, ...).
  *
  */
-public abstract class DerbyRepositoryUpgradeTest extends JettyTestCase {
+@Infrastructure(dependencies = {KdcInfrastructureProvider.class})
+public abstract class DerbyRepositoryUpgradeTest extends SqoopTestCase {
 
-  private static final Logger LOG = Logger.getLogger(DerbyRepositoryUpgradeTest.class);
   protected Map<Long, String> jobIdToNameMap;
   protected Map<Long, String> linkIdToNameMap;
 
+  private SqoopMiniCluster sqoopMiniCluster;
+
   /**
    * Custom Sqoop mini cluster that points derby repository to real on-disk structures.
    */
@@ -131,17 +134,7 @@ public abstract class DerbyRepositoryUpgradeTest extends JettyTestCase
{
     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 void stopSqoop() throws Exception {
-    // Do nothing so that Sqoop isn't stopped after Suite.
-  }
-
-  @BeforeMethod
+  @BeforeMethod(dependsOnMethods = { "init" })
   public void startSqoopMiniCluster(ITestContext context) throws Exception {
     // Prepare older repository structures
     InputStream tarballStream = getClass().getResourceAsStream(getPathToRepositoryTarball());
@@ -149,13 +142,13 @@ public abstract class DerbyRepositoryUpgradeTest extends JettyTestCase
{
     CompressionUtils.untarStreamToDirectory(tarballStream, getRepositoryPath());
 
     // And use them for new Derby repo instance
-    setCluster(new DerbySqoopMiniCluster(getRepositoryPath(), getTemporaryJettyPath() + "/sqoop-mini-cluster",
hadoopCluster.getConfiguration()));
+    sqoopMiniCluster  = new DerbySqoopMiniCluster(getRepositoryPath(), getTemporaryJettyPath()
+ "/sqoop-mini-cluster", getHadoopConf());
 
     // Start server
-    getCluster().start();
+    sqoopMiniCluster.start();
 
     // Initialize Sqoop Client API
-    setClient(new SqoopClient(getServerUrl()));
+    initSqoopClient(sqoopMiniCluster.getServerUrl());
 
     jobIdToNameMap = new HashMap<Long, String>();
     for(MJob job : getClient().getJobs()) {
@@ -170,7 +163,7 @@ public abstract class DerbyRepositoryUpgradeTest extends JettyTestCase
{
 
   @AfterMethod
   public void stopSqoopMiniCluster() throws Exception {
-    getCluster().stop();
+    sqoopMiniCluster.stop();
   }
 
   @Test


Mime
View raw message