sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2170: MySQL specific tests are not properly cleaning up created tables
Date Thu, 05 Mar 2015 02:02:46 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk d40825208 -> 3a475c969


SQOOP-2170: MySQL specific tests are not properly cleaning up created tables

(Jarek Jarcec Cecho via Abraham Elmahrek)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/3a475c96
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/3a475c96
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/3a475c96

Branch: refs/heads/trunk
Commit: 3a475c9694e208fd64e81441a8942ad8381de522
Parents: d408252
Author: Abraham Elmahrek <abe@apache.org>
Authored: Wed Mar 4 16:33:08 2015 -0800
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Wed Mar 4 16:33:08 2015 -0800

----------------------------------------------------------------------
 src/test/com/cloudera/sqoop/TestAllTables.java  | 13 +++++
 .../sqoop/manager/DirectMySQLExportTest.java    | 17 +++---
 .../cloudera/sqoop/manager/DirectMySQLTest.java | 61 +++++++++-----------
 .../sqoop/manager/JdbcMySQLExportTest.java      | 19 +++---
 .../manager/mysql/MySqlCallExportTest.java      | 12 ++++
 5 files changed, 68 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/3a475c96/src/test/com/cloudera/sqoop/TestAllTables.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/TestAllTables.java b/src/test/com/cloudera/sqoop/TestAllTables.java
index d2c7b16..39e8941 100644
--- a/src/test/com/cloudera/sqoop/TestAllTables.java
+++ b/src/test/com/cloudera/sqoop/TestAllTables.java
@@ -29,6 +29,7 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.IOUtils;
 import org.junit.Before;
+import org.junit.After;
 
 import com.cloudera.sqoop.testutil.CommonArgs;
 import com.cloudera.sqoop.testutil.ImportJobTestCase;
@@ -110,6 +111,18 @@ public class TestAllTables extends ImportJobTestCase {
     }
   }
 
+  @After
+  public void tearDown() {
+    try {
+      for (String table : tableNames) {
+        dropTableIfExists(table);
+      }
+    } catch(SQLException e) {
+      LOG.error("Can't clean up the database:", e);
+    }
+    super.tearDown();
+  }
+
   public void testMultiTableImport() throws IOException {
     String [] argv = getArgv(true, null);
     runImport(new ImportAllTablesTool(), argv);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/3a475c96/src/test/com/cloudera/sqoop/manager/DirectMySQLExportTest.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/manager/DirectMySQLExportTest.java b/src/test/com/cloudera/sqoop/manager/DirectMySQLExportTest.java
index eac7836..986dc86 100644
--- a/src/test/com/cloudera/sqoop/manager/DirectMySQLExportTest.java
+++ b/src/test/com/cloudera/sqoop/manager/DirectMySQLExportTest.java
@@ -98,6 +98,13 @@ public class DirectMySQLExportTest extends TestExport {
 
   @After
   public void tearDown() {
+    try {
+      Statement stmt = conn.createStatement();
+      stmt.execute(getDropTableStatement(getTableName()));
+    } catch(SQLException e) {
+      LOG.error("Can't clean up the database:", e);
+    }
+
     super.tearDown();
 
     if (null != this.conn) {
@@ -107,16 +114,6 @@ public class DirectMySQLExportTest extends TestExport {
         LOG.error("Got SQLException closing conn: " + sqlE.toString());
       }
     }
-
-    if (null != manager) {
-      try {
-        manager.close();
-        manager = null;
-      } catch (SQLException sqlE) {
-        LOG.error("Got SQLException: " + sqlE.toString());
-        fail("Got SQLException: " + sqlE.toString());
-      }
-    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/3a475c96/src/test/com/cloudera/sqoop/manager/DirectMySQLTest.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/manager/DirectMySQLTest.java b/src/test/com/cloudera/sqoop/manager/DirectMySQLTest.java
index b7d6284..d0f0c50 100644
--- a/src/test/com/cloudera/sqoop/manager/DirectMySQLTest.java
+++ b/src/test/com/cloudera/sqoop/manager/DirectMySQLTest.java
@@ -119,34 +119,19 @@ public class DirectMySQLTest extends ImportJobTestCase {
       LOG.error("Encountered SQL Exception: " + sqlE);
       sqlE.printStackTrace();
       fail("SQLException when running test setUp(): " + sqlE);
-    } finally {
-      try {
-        if (null != st) {
-          st.close();
-        }
-
-        if (null != connection) {
-          connection.close();
-        }
-      } catch (SQLException sqlE) {
-        LOG.warn("Got SQLException when closing connection: " + sqlE);
-      }
     }
   }
 
   @After
   public void tearDown() {
-    super.tearDown();
-
-    if (null != manager) {
-      try {
-        manager.close();
-        manager = null;
-      } catch (SQLException sqlE) {
-        LOG.error("Got SQLException: " + sqlE.toString());
-        fail("Got SQLException: " + sqlE.toString());
-      }
+    try {
+      Statement stmt = manager.getConnection().createStatement();
+      stmt.execute("DROP TABLE " + getTableName());
+    } catch(SQLException e) {
+      LOG.error("Can't clean up the database:", e);
     }
+
+    super.tearDown();
   }
 
   private String [] getArgv(boolean mysqlOutputDelims, boolean isDirect,
@@ -342,7 +327,17 @@ public class DirectMySQLTest extends ImportJobTestCase {
 
       st.executeUpdate("INSERT INTO `" + RESERVED_TABLE_NAME + "` VALUES("
           + "2,'Aaron','2009-05-14',1000000.00,'engineering')");
+      st.close();
       connection.commit();
+
+      String [] expectedResults = {
+          "2,Aaron,2009-05-14,1000000.0,engineering",
+      };
+
+      doImport(false, false, RESERVED_TABLE_NAME, expectedResults, null);
+
+      st = connection.createStatement();
+      st.execute("DROP TABLE `" + RESERVED_TABLE_NAME + "`");
     } finally {
       if (null != st) {
         st.close();
@@ -353,11 +348,6 @@ public class DirectMySQLTest extends ImportJobTestCase {
       }
     }
 
-    String [] expectedResults = {
-        "2,Aaron,2009-05-14,1000000.0,engineering",
-    };
-
-    doImport(false, false, RESERVED_TABLE_NAME, expectedResults, null);
   }
 
   @Test
@@ -365,7 +355,6 @@ public class DirectMySQLTest extends ImportJobTestCase {
     // Test a JDBC-based import of a table with a column whose name is
     // a reserved sql keyword (and is thus `quoted`).
     final String TABLE_NAME = "mysql_escaped_col_table";
-    setCurTableName(TABLE_NAME);
     SqoopOptions options = new SqoopOptions(MySQLTestUtils.CONNECT_STRING,
         TABLE_NAME);
     options.setUsername(MySQLTestUtils.getCurrentUser());
@@ -390,7 +379,17 @@ public class DirectMySQLTest extends ImportJobTestCase {
 
       st.executeUpdate("INSERT INTO " + TABLE_NAME + " VALUES("
           + "2,'Aaron','2009-05-14',1000000.00,'engineering')");
+      st.close();
       connection.commit();
+
+      String [] expectedResults = {
+          "2,Aaron,2009-05-14,1000000.0,engineering",
+      };
+
+      doImport(false, false, TABLE_NAME, expectedResults, null);
+
+      st = connection.createStatement();
+      st.execute("DROP TABLE " + TABLE_NAME);
     } finally {
       if (null != st) {
         st.close();
@@ -400,11 +399,5 @@ public class DirectMySQLTest extends ImportJobTestCase {
         connection.close();
       }
     }
-
-    String [] expectedResults = {
-        "2,Aaron,2009-05-14,1000000.0,engineering",
-    };
-
-    doImport(false, false, TABLE_NAME, expectedResults, null);
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/3a475c96/src/test/com/cloudera/sqoop/manager/JdbcMySQLExportTest.java
----------------------------------------------------------------------
diff --git a/src/test/com/cloudera/sqoop/manager/JdbcMySQLExportTest.java b/src/test/com/cloudera/sqoop/manager/JdbcMySQLExportTest.java
index f7cc297..86b9aab 100644
--- a/src/test/com/cloudera/sqoop/manager/JdbcMySQLExportTest.java
+++ b/src/test/com/cloudera/sqoop/manager/JdbcMySQLExportTest.java
@@ -21,6 +21,7 @@ package com.cloudera.sqoop.manager;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.sql.Statement;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -97,6 +98,14 @@ public class JdbcMySQLExportTest extends TestExport {
 
   @After
   public void tearDown() {
+    try {
+      Statement stmt = conn.createStatement();
+      stmt.execute(getDropTableStatement(getTableName()));
+      stmt.execute(getDropTableStatement(getStagingTableName()));
+    } catch(SQLException e) {
+      LOG.error("Can't clean up the database:", e);
+    }
+
     super.tearDown();
 
     if (null != this.conn) {
@@ -106,16 +115,6 @@ public class JdbcMySQLExportTest extends TestExport {
         LOG.error("Got SQLException closing conn: " + sqlE.toString());
       }
     }
-
-    if (null != manager) {
-      try {
-        manager.close();
-        manager = null;
-      } catch (SQLException sqlE) {
-        LOG.error("Got SQLException: " + sqlE.toString());
-        fail("Got SQLException: " + sqlE.toString());
-      }
-    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/3a475c96/src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java b/src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java
index 3be447e..6bf939b 100644
--- a/src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java
+++ b/src/test/org/apache/sqoop/manager/mysql/MySqlCallExportTest.java
@@ -56,6 +56,18 @@ public class MySqlCallExportTest extends ExportJobTestCase {
     createObjects();
   }
 
+  @Override
+  public void tearDown() {
+    try {
+      Statement stmt = getManager().getConnection().createStatement();
+      stmt.execute("DROP TABLE " + getTableName());
+    } catch(SQLException e) {
+      LOG.error("Can't clean up the database:", e);
+    }
+
+    super.tearDown();
+  }
+
   private String[] getArgv(String... extraArgs) {
     ArrayList<String> args = new ArrayList<String>();
 


Mime
View raw message