diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java index bb37c59604b..7235372bfcc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java @@ -1276,6 +1276,14 @@ public void testBalancerCliParseWithWrongParams() { } catch (IllegalArgumentException e) { } + + parameters = new String[] {"-source"}; + try { + Balancer.Cli.parse(parameters); + fail(reason + " for -source parameter"); + } catch (IllegalArgumentException ignored) { + // expected + } } @Test @@ -1783,11 +1791,12 @@ public void testMinBlockSizeAndSourceNodes() throws Exception { final Collection namenodes = DFSUtil.getInternalNsRpcUris(conf); { // run Balancer with min-block-size=50 - BalancerParameters.Builder b = - new BalancerParameters.Builder(); - b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE); - b.setThreshold(1); - final BalancerParameters p = b.build(); + final BalancerParameters p = Balancer.Cli.parse(new String[] { + "-policy", BalancingPolicy.Node.INSTANCE.getName(), + "-threshold", "1" + }); + assertEquals(p.getBalancingPolicy(), BalancingPolicy.Node.INSTANCE); + assertEquals(p.getThreshold(), 1.0, 0.001); conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 50); final int r = Balancer.run(namenodes, p, conf); @@ -1802,12 +1811,14 @@ public void testMinBlockSizeAndSourceNodes() throws Exception { for(int i = capacities.length; i < datanodes.size(); i++) { sourceNodes.add(datanodes.get(i).getDisplayName()); } - BalancerParameters.Builder b = - new BalancerParameters.Builder(); - b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE); - b.setThreshold(1); - b.setSourceNodes(sourceNodes); - final BalancerParameters p = b.build(); + final BalancerParameters p = Balancer.Cli.parse(new String[] { + "-policy", BalancingPolicy.Node.INSTANCE.getName(), + "-threshold", "1", + "-source", StringUtils.join(sourceNodes, ',') + }); + assertEquals(p.getBalancingPolicy(), BalancingPolicy.Node.INSTANCE); + assertEquals(p.getThreshold(), 1.0, 0.001); + assertEquals(p.getSourceNodes(), sourceNodes); conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 50); final int r = Balancer.run(namenodes, p, conf); @@ -1818,12 +1829,14 @@ public void testMinBlockSizeAndSourceNodes() throws Exception { final Set sourceNodes = new HashSet<>(); final List datanodes = cluster.getDataNodes(); sourceNodes.add(datanodes.get(0).getDisplayName()); - BalancerParameters.Builder b = - new BalancerParameters.Builder(); - b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE); - b.setThreshold(1); - b.setSourceNodes(sourceNodes); - final BalancerParameters p = b.build(); + final BalancerParameters p = Balancer.Cli.parse(new String[] { + "-policy", BalancingPolicy.Node.INSTANCE.getName(), + "-threshold", "1", + "-source", StringUtils.join(sourceNodes, ',') + }); + assertEquals(p.getBalancingPolicy(), BalancingPolicy.Node.INSTANCE); + assertEquals(p.getThreshold(), 1.0, 0.001); + assertEquals(p.getSourceNodes(), sourceNodes); conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 1); final int r = Balancer.run(namenodes, p, conf); @@ -1836,12 +1849,14 @@ public void testMinBlockSizeAndSourceNodes() throws Exception { for(int i = 0; i < capacities.length; i++) { sourceNodes.add(datanodes.get(i).getDisplayName()); } - BalancerParameters.Builder b = - new BalancerParameters.Builder(); - b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE); - b.setThreshold(1); - b.setSourceNodes(sourceNodes); - final BalancerParameters p = b.build(); + final BalancerParameters p = Balancer.Cli.parse(new String[] { + "-policy", BalancingPolicy.Node.INSTANCE.getName(), + "-threshold", "1", + "-source", StringUtils.join(sourceNodes, ',') + }); + assertEquals(p.getBalancingPolicy(), BalancingPolicy.Node.INSTANCE); + assertEquals(p.getThreshold(), 1.0, 0.001); + assertEquals(p.getSourceNodes(), sourceNodes); conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 1); final int r = Balancer.run(namenodes, p, conf);