sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1308: Database export with the Generic-JDBC-Connector loses rows
Date Thu, 08 May 2014 15:07:32 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 8e978c042 -> dccaf0b25


SQOOP-1308: Database export with the Generic-JDBC-Connector loses rows

(Kristian Kottke 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/dccaf0b2
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/dccaf0b2
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/dccaf0b2

Branch: refs/heads/sqoop2
Commit: dccaf0b25845f381eefa93991a954dd4c25f32b3
Parents: 8e978c0
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Thu May 8 08:05:59 2014 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Thu May 8 08:05:59 2014 -0700

----------------------------------------------------------------------
 .../connector/jdbc/GenericJdbcExportLoader.java |  2 +-
 .../sqoop/connector/jdbc/TestExportLoader.java  | 40 +++++++++++++++-----
 2 files changed, 31 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/dccaf0b2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExportLoader.java
----------------------------------------------------------------------
diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExportLoader.java
b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExportLoader.java
index f62339f..15e7101 100644
--- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExportLoader.java
+++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExportLoader.java
@@ -61,7 +61,7 @@ public class GenericJdbcExportLoader extends Loader<ConnectionConfiguration,
Exp
         }
       }
 
-      if (numberOfRows != 0) {
+      if (numberOfRows != 0 || numberOfBatches != 0) {
         // execute and commit the remaining rows
         executor.executeBatch(true);
       }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/dccaf0b2/connector/connector-generic-jdbc/src/test/java/org/apache/sqoop/connector/jdbc/TestExportLoader.java
----------------------------------------------------------------------
diff --git a/connector/connector-generic-jdbc/src/test/java/org/apache/sqoop/connector/jdbc/TestExportLoader.java
b/connector/connector-generic-jdbc/src/test/java/org/apache/sqoop/connector/jdbc/TestExportLoader.java
index aa1c4ff..d4c4565 100644
--- a/connector/connector-generic-jdbc/src/test/java/org/apache/sqoop/connector/jdbc/TestExportLoader.java
+++ b/connector/connector-generic-jdbc/src/test/java/org/apache/sqoop/connector/jdbc/TestExportLoader.java
@@ -17,32 +17,49 @@
  */
 package org.apache.sqoop.connector.jdbc;
 
-import java.sql.ResultSet;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
-import junit.framework.TestCase;
+import java.sql.ResultSet;
+import java.util.Arrays;
+import java.util.Collection;
 
 import org.apache.sqoop.common.MutableContext;
 import org.apache.sqoop.common.MutableMapContext;
 import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration;
 import org.apache.sqoop.connector.jdbc.configuration.ExportJobConfiguration;
+import org.apache.sqoop.etl.io.DataReader;
 import org.apache.sqoop.job.etl.Loader;
 import org.apache.sqoop.job.etl.LoaderContext;
-import org.apache.sqoop.etl.io.DataReader;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
-public class TestExportLoader extends TestCase {
+@RunWith(Parameterized.class)
+public class TestExportLoader {
 
   private final String tableName;
 
   private GenericJdbcExecutor executor;
 
   private static final int START = -50;
-  private static final int NUMBER_OF_ROWS = 101;
+  
+  private int numberOfRows;
+
+  @Parameters
+  public static Collection<Object[]> data() {
+    return Arrays.asList(new Object[][] {{50}, {100}, {101}, {150}, {200}});
+  }
 
-  public TestExportLoader() {
+  public TestExportLoader(int numberOfRows) {
+    this.numberOfRows = numberOfRows;
     tableName = getClass().getSimpleName().toUpperCase();
   }
 
-  @Override
+  @Before
   public void setUp() {
     executor = new GenericJdbcExecutor(GenericJdbcTestConstants.DRIVER,
         GenericJdbcTestConstants.URL, null, null);
@@ -51,14 +68,17 @@ public class TestExportLoader extends TestCase {
       executor.executeUpdate("CREATE TABLE "
           + executor.delimitIdentifier(tableName)
           + "(ICOL INTEGER PRIMARY KEY, DCOL DOUBLE, VCOL VARCHAR(20))");
+    } else {
+      executor.deleteTableData(tableName);
     }
   }
 
-  @Override
+  @After
   public void tearDown() {
     executor.close();
   }
 
+  @Test
   public void testInsert() throws Exception {
     MutableContext context = new MutableMapContext();
 
@@ -86,7 +106,7 @@ public class TestExportLoader extends TestCase {
       assertEquals(String.valueOf(index), rs.getObject(3));
       index++;
     }
-    assertEquals(NUMBER_OF_ROWS, index-START);
+    assertEquals(numberOfRows, index-START);
   }
 
   public class DummyReader extends DataReader {
@@ -99,7 +119,7 @@ public class TestExportLoader extends TestCase {
 
     @Override
     public Object[] readArrayRecord() {
-      if (index < NUMBER_OF_ROWS) {
+      if (index < numberOfRows) {
         Object[] array = new Object[] {
             START + index,
             (double) (START + index),


Mime
View raw message