HDFS-11933. Arguments check for ErasureCodingPolicy->composePolicyName. 
Contributed by Lu Fei


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

Branch: refs/heads/HADOOP-13345
Commit: a010b330e7797d2ecb5b01ec69ea40438579602f
Parents: 1a59847
Author: Kai Zheng <[email protected]>
Authored: Wed Jun 21 13:46:18 2017 +0800
Committer: Kai Zheng <[email protected]>
Committed: Wed Jun 21 13:46:18 2017 +0800

----------------------------------------------------------------------
 .../hdfs/protocol/ErasureCodingPolicy.java      |  2 ++
 .../hdfs/protocol/TestErasureCodingPolicy.java  | 22 ++++++++++++++++++++
 2 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a010b330/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java
index b63d2c0..368a2f2 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ErasureCodingPolicy.java
@@ -58,6 +58,8 @@ public final class ErasureCodingPolicy {
   }
 
   public static String composePolicyName(ECSchema schema, int cellSize) {
+    Preconditions.checkNotNull(schema);
+    Preconditions.checkArgument(cellSize > 0, "cellSize must be positive");
     Preconditions.checkArgument(cellSize % 1024 == 0,
         "cellSize must be 1024 aligned");
     return schema.getCodecName().toUpperCase() + "-" +

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a010b330/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java
index 17fb01c..f1674af 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestErasureCodingPolicy.java
@@ -51,6 +51,28 @@ public class TestErasureCodingPolicy {
     } catch (IllegalArgumentException e) {
       GenericTestUtils.assertExceptionContains("cellSize", e);
     }
+    try {
+      new ErasureCodingPolicy(null, 1024, (byte) -1);
+      fail("Instantiated invalid ErasureCodingPolicy");
+    } catch (NullPointerException e) {
+    }
+    try {
+      new ErasureCodingPolicy(SCHEMA_1, -1, (byte) -1);
+      fail("Instantiated invalid ErasureCodingPolicy");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains("cellSize", e);
+    }
+    try {
+      new ErasureCodingPolicy(null, 1024);
+      fail("Instantiated invalid ErasureCodingPolicy");
+    } catch (NullPointerException e) {
+    }
+    try {
+      new ErasureCodingPolicy(SCHEMA_1, -1);
+      fail("Instantiated invalid ErasureCodingPolicy");
+    } catch (IllegalArgumentException e) {
+      GenericTestUtils.assertExceptionContains("cellSize", e);
+    }
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to