Browse Source

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

Kai Zheng 7 years ago
parent
commit
a010b330e7

+ 2 - 0
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() + "-" +

+ 22 - 0
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