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

This commit is contained in:
Kai Zheng 2017-06-21 13:46:18 +08:00
parent 1a598479a9
commit a010b330e7
2 changed files with 24 additions and 0 deletions

View File

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

View File

@ -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