HDFS-17056. EC: Fix verifyClusterSetup output in case of an invalid param. (#6379). Contributed by huangzhaobo99.

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
huangzhaobo 2023-12-26 01:47:25 +08:00 committed by GitHub
parent 415e9bdfbd
commit 630ffb280d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -642,6 +642,10 @@ public int run(Configuration conf, List<String> args) throws IOException {
throw e;
}
} else {
if (args.size() > 0) {
System.err.println(getName() + ": Too many arguments");
return 1;
}
result = dfs.getECTopologyResultForPolicies();
}
System.out.println(result.getResultMessage());

View File

@ -260,6 +260,37 @@ public void testVerifyClusterSetupWithGivenPolicies() throws Exception {
"expected 1 but got 0"));
}
@Test
public void testVerifyClusterSetupSpecifiedPolicies() throws Exception {
final int numDataNodes = 5;
final int numRacks = 3;
cluster = DFSTestUtil.setupCluster(conf, numDataNodes, numRacks, 0);
cluster.getFileSystem().enableErasureCodingPolicy(XOR_2_1);
int ret = runCommandWithParams("-verifyClusterSetup", XOR_2_1);
assertEquals("Return value of the command is not successful", 1, ret);
assertTrue("Error message should be logged", err.toString().contains("Too many arguments"));
resetOutputs();
ret = runCommandWithParams("-verifyClusterSetup", "-policy");
assertEquals("Return value of the command is not successful", -1, ret);
assertTrue("Error message should be logged", err.toString()
.contains("NotEnoughArgumentsException: Not enough arguments: " + "expected 1 but got 0"));
resetOutputs();
ret = runCommandWithParams("-verifyClusterSetup", "-policy", XOR_2_1);
assertEquals("Return value of the command is successful", 0, ret);
assertTrue("Result of cluster topology verify " + "should be logged correctly",
out.toString().contains("The cluster setup can support EC policies: " + XOR_2_1));
assertTrue("Error output should be empty", err.toString().isEmpty());
resetOutputs();
ret = runCommandWithParams("-verifyClusterSetup", "-policy", RS_6_3);
assertEquals("Return value of the command is not successful", 2, ret);
assertNotEnoughDataNodesMessage(RS_6_3, numDataNodes, 9);
}
private void resetOutputs() {
out.reset();
err.reset();