SQOOP-3362: Fix toString() methods of OraOopOracleDataChunk
authorSzabolcs Vasas <vasas@apache.org>
Thu, 16 Aug 2018 09:58:31 +0000 (11:58 +0200)
committerSzabolcs Vasas <vasas@apache.org>
Thu, 16 Aug 2018 09:58:31 +0000 (11:58 +0200)
(Nguyen Truong via Szabolcs Vasas)

src/java/org/apache/sqoop/manager/oracle/OraOopDBInputSplit.java
src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunk.java
src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkExtent.java
src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkPartition.java
src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java [new file with mode: 0644]

index 948bdbb..d3675b2 100644 (file)
@@ -167,8 +167,9 @@ class OraOopDBInputSplit extends DBInputFormat.DBInputSplit {
           "Split[%s] does not contain any Oracle data-chunks.", this.splitId));
     } else {
       result.append(String.format(
-          "Split[%s] includes the Oracle data-chunks:\n", this.splitId));
+          "Split[%s] includes the Oracle data-chunks:", this.splitId));
       for (OraOopOracleDataChunk dataChunk : getDataChunks()) {
+        result.append("\n\t Data chunk info:");
         result.append(dataChunk.toString());
       }
     }
index eb67fd2..f65e883 100644 (file)
@@ -18,8 +18,6 @@
 
 package org.apache.sqoop.manager.oracle;
 
-import java.lang.reflect.Field;
-
 import org.apache.hadoop.io.Writable;
 
 /**
@@ -39,24 +37,6 @@ public abstract class OraOopOracleDataChunk implements Writable {
     return "";
   }
 
-  @Override
-  public String toString() {
-
-    String result = super.toString();
-    for (Field field : this.getClass().getDeclaredFields()) {
-      try {
-        Object fieldValue = field.get(this);
-        result +=
-            String.format("\n\t%s = %s", field.getName(),
-                (fieldValue == null ? "null" : fieldValue.toString()));
-      } catch (IllegalAccessException ex) {
-        // Ignore this exception.
-      }
-    }
-
-    return result;
-  }
-
   public String getId() {
     return id;
   }
index 20b39ee..9591742 100644 (file)
@@ -90,4 +90,13 @@ public class OraOopOracleDataChunkExtent extends OraOopOracleDataChunk {
     }
   }
 
+  public String toString(){
+    StringBuilder result = new StringBuilder();
+    result.append("\n\t\t id = ").append(getId());
+    result.append("\n\t\t oracleDataObjectId = ").append(oracleDataObjectId);
+    result.append("\n\t\t relativeDatafileNumber = ").append(relativeDatafileNumber);
+    result.append("\n\t\t startBlockNumber = ").append(startBlockNumber);
+    result.append("\n\t\t finishBlockNumber = ").append(finishBlockNumber);
+    return result.toString();
+  }
 }
index 59889b8..ea1a388 100644 (file)
@@ -75,4 +75,11 @@ public class OraOopOracleDataChunkPartition extends OraOopOracleDataChunk {
     return sb.toString();
   }
 
+  public String toString(){
+    StringBuilder result = new StringBuilder();
+    result.append("\n\t\t id = ").append(getId());
+    result.append("\n\t\t isSubPartition = ").append(isSubPartition);
+    result.append("\n\t\t blocks = ").append(blocks);
+    return result.toString();
+  }
 }
diff --git a/src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java b/src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java
new file mode 100644 (file)
index 0000000..6f33ad3
--- /dev/null
@@ -0,0 +1,104 @@
+/**
+ * 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.sqoop.manager.oracle;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestOraOopDBInputSplitGetDebugDetails {
+    private OraOopDBInputSplit firstSplit;
+    private OraOopDBInputSplit secondSplit;
+    private String firstSplitResult;
+
+    @Before
+    public void initialize() {
+        List<OraOopOracleDataChunk> dataChunkList = new ArrayList<>();
+        OraOopOracleDataChunkExtent firstDataChunkExtent = new OraOopOracleDataChunkExtent("firstExtent",
+                666,1, 10500, 10507);
+        OraOopOracleDataChunkExtent secondDataChunkExtent = new OraOopOracleDataChunkExtent("secondExtent",
+                666,1, 10508, 10515);
+        OraOopOracleDataChunkExtent thirdDataChunkExtent = new OraOopOracleDataChunkExtent("thirdExtent",
+                666,1, 10516, 10523);
+        OraOopOracleDataChunkExtent fourthDataChunkExtent = new OraOopOracleDataChunkExtent("fourthExtent",
+                787,2, 11434, 11450);
+        OraOopOracleDataChunkPartition firstDataChunkPartition = new OraOopOracleDataChunkPartition("firstPartition",
+                true, 14);
+        OraOopOracleDataChunkPartition secondDataChunkPartition = new OraOopOracleDataChunkPartition("secondPartition",
+                false, 4);
+        OraOopOracleDataChunkPartition thirdDataChunkPartition = new OraOopOracleDataChunkPartition("thirdPartition",
+                false, 43);
+        dataChunkList.addAll(Arrays.asList(firstDataChunkExtent, secondDataChunkExtent, thirdDataChunkExtent,
+                fourthDataChunkExtent, firstDataChunkPartition, secondDataChunkPartition, thirdDataChunkPartition));
+        firstSplit = new OraOopDBInputSplit(dataChunkList);
+        secondSplit = new OraOopDBInputSplit();
+        firstSplitResult = "Split[0] includes the Oracle data-chunks:" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = firstExtent" +
+                "\n\t\t oracleDataObjectId = 666" +
+                "\n\t\t relativeDatafileNumber = 1" +
+                "\n\t\t startBlockNumber = 10500" +
+                "\n\t\t finishBlockNumber = 10507" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = secondExtent" +
+                "\n\t\t oracleDataObjectId = 666" +
+                "\n\t\t relativeDatafileNumber = 1" +
+                "\n\t\t startBlockNumber = 10508" +
+                "\n\t\t finishBlockNumber = 10515" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = thirdExtent" +
+                "\n\t\t oracleDataObjectId = 666" +
+                "\n\t\t relativeDatafileNumber = 1" +
+                "\n\t\t startBlockNumber = 10516" +
+                "\n\t\t finishBlockNumber = 10523" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = fourthExtent" +
+                "\n\t\t oracleDataObjectId = 787" +
+                "\n\t\t relativeDatafileNumber = 2" +
+                "\n\t\t startBlockNumber = 11434" +
+                "\n\t\t finishBlockNumber = 11450" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = firstPartition" +
+                "\n\t\t isSubPartition = true" +
+                "\n\t\t blocks = 14" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = secondPartition" +
+                "\n\t\t isSubPartition = false" +
+                "\n\t\t blocks = 4" +
+                "\n\t Data chunk info:" +
+                "\n\t\t id = thirdPartition" +
+                "\n\t\t isSubPartition = false" +
+                "\n\t\t blocks = 43";
+    }
+
+    @Test
+    public void testGetDebugDetails() {
+        assertEquals(firstSplitResult, firstSplit.getDebugDetails());
+    }
+
+    @Test
+    public void testEmptySplitDebugDetails(){
+        assertEquals("Split[-1] does not contain any Oracle data-chunks.", secondSplit.getDebugDetails());
+    }
+}