From 5f1c3f457eac0ac3185340e02106a79bcb3c9b26 Mon Sep 17 00:00:00 2001
From: Aaron Kimball <aaron@cloudera.com>
Date: Mon, 14 Sep 2009 17:47:31 -0700
Subject: [PATCH] MAPREDUCE-749: Make Sqoop unit tests more Hudson-friendly

---
 src/contrib/sqoop/build.xml                        |    8 +++
 src/contrib/sqoop/ivy.xml                          |    4 ++
 .../src/test/org/apache/hadoop/sqoop/AllTests.java |    7 +--
 .../org/apache/hadoop/sqoop/ThirdPartyTests.java   |   49 ++++++++++++++++++++
 4 files changed, 62 insertions(+), 6 deletions(-)
 create mode 100644 src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/ThirdPartyTests.java

diff --git a/src/contrib/sqoop/build.xml b/src/contrib/sqoop/build.xml
index 2ee8ba4..d9e7f4d 100644
--- a/src/contrib/sqoop/build.xml
+++ b/src/contrib/sqoop/build.xml
@@ -25,6 +25,7 @@ to call at top-level: ant deploy-contrib compile-core-test
 
   <import file="../build-contrib.xml"/>
   <property environment="env"/>
+  <property name="sqoop.thirdparty.lib.dir" value="" />
 
   <!-- ================================================================== -->
   <!-- Run unit tests                                                     -->
@@ -76,6 +77,11 @@ to call at top-level: ant deploy-contrib compile-core-test
       -->
       <sysproperty key="sqoop.src.dir" value="${build.test}/data"/>
 
+      <!-- Override standalone Hadoop's working dirs to allow parallel
+           execution of multiple Hudson builders
+      -->
+      <sysproperty key="hadoop.tmp.dir" value="${build.test}/hadoop"/>
+
       <sysproperty key="fs.default.name" value="${fs.default.name}"/>
       <sysproperty key="hadoop.test.localoutputfile" value="${hadoop.test.localoutputfile}"/>
       <sysproperty key="hadoop.log.dir" value="${hadoop.log.dir}"/>
@@ -91,6 +97,8 @@ to call at top-level: ant deploy-contrib compile-core-test
         <path refid="test.classpath"/>
         <path refid="contrib-classpath"/>
         <pathelement path="${env.JAVA_HOME}/lib/tools.jar" />
+        <fileset dir="${sqoop.thirdparty.lib.dir}"
+            includes="*.jar" />
       </classpath>
       <formatter type="${test.junit.output.format}" />
       <batchtest todir="${build.test}" unless="testcase">
diff --git a/src/contrib/sqoop/ivy.xml b/src/contrib/sqoop/ivy.xml
index 8fe13c4..160d49d 100644
--- a/src/contrib/sqoop/ivy.xml
+++ b/src/contrib/sqoop/ivy.xml
@@ -40,6 +40,10 @@
     <artifact conf="master"/>
   </publications>
   <dependencies>
+    <dependency org="commons-cli"
+      name="commons-cli"
+      rev="${commons-cli.version}"
+      conf="common->default"/>
     <dependency org="commons-logging"
       name="commons-logging"
       rev="${commons-logging.version}"
diff --git a/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/AllTests.java b/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/AllTests.java
index d60bb6f..d86ae10 100644
--- a/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/AllTests.java
+++ b/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/AllTests.java
@@ -21,9 +21,6 @@ package org.apache.hadoop.sqoop;
 import org.apache.hadoop.sqoop.hive.TestHiveImport;
 import org.apache.hadoop.sqoop.lib.TestFieldFormatter;
 import org.apache.hadoop.sqoop.lib.TestRecordParser;
-import org.apache.hadoop.sqoop.manager.LocalMySQLTest;
-import org.apache.hadoop.sqoop.manager.MySQLAuthTest;
-import org.apache.hadoop.sqoop.manager.OracleManagerTest;
 import org.apache.hadoop.sqoop.manager.TestHsqldbManager;
 import org.apache.hadoop.sqoop.manager.TestSqlManager;
 import org.apache.hadoop.sqoop.orm.TestClassWriter;
@@ -52,14 +49,12 @@ public final class AllTests  {
     suite.addTestSuite(TestMultiCols.class);
     suite.addTestSuite(TestOrderBy.class);
     suite.addTestSuite(TestWhere.class);
-    suite.addTestSuite(LocalMySQLTest.class);
-    suite.addTestSuite(MySQLAuthTest.class);
     suite.addTestSuite(TestHiveImport.class);
     suite.addTestSuite(TestRecordParser.class);
     suite.addTestSuite(TestFieldFormatter.class);
     suite.addTestSuite(TestImportOptions.class);
     suite.addTestSuite(TestParseMethods.class);
-    suite.addTestSuite(OracleManagerTest.class);
+    suite.addTest(ThirdPartyTests.suite());
 
     return suite;
   }
diff --git a/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/ThirdPartyTests.java b/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/ThirdPartyTests.java
new file mode 100644
index 0000000..5dd6447
--- /dev/null
+++ b/src/contrib/sqoop/src/test/org/apache/hadoop/sqoop/ThirdPartyTests.java
@@ -0,0 +1,49 @@
+/**
+ * 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.sqoop;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.hadoop.sqoop.manager.LocalMySQLTest;
+import org.apache.hadoop.sqoop.manager.MySQLAuthTest;
+import org.apache.hadoop.sqoop.manager.OracleManagerTest;
+
+/**
+ * Test battery including all tests of vendor-specific ConnManager implementations.
+ * These tests likely aren't run by Apache Hudson, because they require configuring
+ * and using Oracle, MySQL, etc., which may have incompatible licenses with Apache.
+ */
+public final class ThirdPartyTests extends TestCase {
+
+  private ThirdPartyTests() { }
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite("Tests vendor-specific ConnManager "
+      + "implementations in Sqoop");
+    suite.addTestSuite(LocalMySQLTest.class);
+    suite.addTestSuite(MySQLAuthTest.class);
+    suite.addTestSuite(OracleManagerTest.class);
+    
+    return suite;
+  }
+
+}
+
-- 
1.6.0.4

