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 8fbefd8d..c300b331 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 static void startInfrastructureProviders(ITestContext context) { * @param * @return */ - private static T startInfrastructureProvider(Class providerClass, Configuration hadoopConfiguration, KdcRunner kdc) { + protected static T startInfrastructureProvider(Class providerClass, Configuration hadoopConfiguration, KdcRunner kdc) { T providerObject; try { @@ -354,17 +354,7 @@ public DelegationTokenAuthenticatedURL.Token getAuthToken() { @BeforeMethod public void init() throws Exception { - String serverUrl = getSqoopServerUrl(); - - if (serverUrl != null) { - client = new SqoopClient(serverUrl); - - KdcInfrastructureProvider kdcProvider = getInfrastructureProvider(KdcInfrastructureProvider.class); - if (kdcProvider != null) { - kdcProvider.getInstance().authenticateWithSqoopServer(client); - kdcProvider.getInstance().authenticateWithSqoopServer(new URL(serverUrl), authToken); - } - } + initSqoopClient(getSqoopServerUrl()); if (getInfrastructureProvider(HadoopInfrastructureProvider.class) != null) { hdfsClient = FileSystem.get(getInfrastructureProvider(HadoopInfrastructureProvider.class).getHadoopConfiguration()); @@ -376,6 +366,18 @@ public void init() throws Exception { } } + protected void initSqoopClient(String serverUrl) throws Exception { + if (serverUrl != null) { + client = new SqoopClient(serverUrl); + + KdcInfrastructureProvider kdcProvider = getInfrastructureProvider(KdcInfrastructureProvider.class); + if (kdcProvider != null) { + kdcProvider.getInstance().authenticateWithSqoopServer(client); + kdcProvider.getInstance().authenticateWithSqoopServer(new URL(serverUrl), authToken); + } + } + } + /** * Create link with asserts to make sure that it was created correctly. * @@ -638,4 +640,14 @@ protected String getTemporaryPath() { 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; + } } 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 cbc243ca..44f4a5bc 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.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 @@ * 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 jobIdToNameMap; protected Map linkIdToNameMap; + private SqoopMiniCluster sqoopMiniCluster; + /** * Custom Sqoop mini cluster that points derby repository to real on-disk structures. */ @@ -131,17 +134,7 @@ public String getTemporaryJettyPath() { 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 void startSqoopMiniCluster(ITestContext context) throws Exception { 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(); for(MJob job : getClient().getJobs()) { @@ -170,7 +163,7 @@ public void startSqoopMiniCluster(ITestContext context) throws Exception { @AfterMethod public void stopSqoopMiniCluster() throws Exception { - getCluster().stop(); + sqoopMiniCluster.stop(); } @Test