HDFS-11008. Change unit test for testing parsing "-source" parameter in Balancer CLI. Contributed by Mingliang Liu
(cherry picked from commit 76cc84e6d4
)
This commit is contained in:
parent
8d1fbf786b
commit
15b1d522ee
|
@ -1276,6 +1276,14 @@ public class TestBalancer {
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parameters = new String[] {"-source"};
|
||||||
|
try {
|
||||||
|
Balancer.Cli.parse(parameters);
|
||||||
|
fail(reason + " for -source parameter");
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1783,11 +1791,12 @@ public class TestBalancer {
|
||||||
final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
|
final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
|
||||||
|
|
||||||
{ // run Balancer with min-block-size=50
|
{ // run Balancer with min-block-size=50
|
||||||
BalancerParameters.Builder b =
|
final BalancerParameters p = Balancer.Cli.parse(new String[] {
|
||||||
new BalancerParameters.Builder();
|
"-policy", BalancingPolicy.Node.INSTANCE.getName(),
|
||||||
b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE);
|
"-threshold", "1"
|
||||||
b.setThreshold(1);
|
});
|
||||||
final BalancerParameters p = b.build();
|
assertEquals(p.getBalancingPolicy(), BalancingPolicy.Node.INSTANCE);
|
||||||
|
assertEquals(p.getThreshold(), 1.0, 0.001);
|
||||||
|
|
||||||
conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 50);
|
conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 50);
|
||||||
final int r = Balancer.run(namenodes, p, conf);
|
final int r = Balancer.run(namenodes, p, conf);
|
||||||
|
@ -1802,12 +1811,14 @@ public class TestBalancer {
|
||||||
for(int i = capacities.length; i < datanodes.size(); i++) {
|
for(int i = capacities.length; i < datanodes.size(); i++) {
|
||||||
sourceNodes.add(datanodes.get(i).getDisplayName());
|
sourceNodes.add(datanodes.get(i).getDisplayName());
|
||||||
}
|
}
|
||||||
BalancerParameters.Builder b =
|
final BalancerParameters p = Balancer.Cli.parse(new String[] {
|
||||||
new BalancerParameters.Builder();
|
"-policy", BalancingPolicy.Node.INSTANCE.getName(),
|
||||||
b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE);
|
"-threshold", "1",
|
||||||
b.setThreshold(1);
|
"-source", StringUtils.join(sourceNodes, ',')
|
||||||
b.setSourceNodes(sourceNodes);
|
});
|
||||||
final BalancerParameters p = b.build();
|
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);
|
conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 50);
|
||||||
final int r = Balancer.run(namenodes, p, conf);
|
final int r = Balancer.run(namenodes, p, conf);
|
||||||
|
@ -1818,12 +1829,14 @@ public class TestBalancer {
|
||||||
final Set<String> sourceNodes = new HashSet<>();
|
final Set<String> sourceNodes = new HashSet<>();
|
||||||
final List<DataNode> datanodes = cluster.getDataNodes();
|
final List<DataNode> datanodes = cluster.getDataNodes();
|
||||||
sourceNodes.add(datanodes.get(0).getDisplayName());
|
sourceNodes.add(datanodes.get(0).getDisplayName());
|
||||||
BalancerParameters.Builder b =
|
final BalancerParameters p = Balancer.Cli.parse(new String[] {
|
||||||
new BalancerParameters.Builder();
|
"-policy", BalancingPolicy.Node.INSTANCE.getName(),
|
||||||
b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE);
|
"-threshold", "1",
|
||||||
b.setThreshold(1);
|
"-source", StringUtils.join(sourceNodes, ',')
|
||||||
b.setSourceNodes(sourceNodes);
|
});
|
||||||
final BalancerParameters p = b.build();
|
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);
|
conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 1);
|
||||||
final int r = Balancer.run(namenodes, p, conf);
|
final int r = Balancer.run(namenodes, p, conf);
|
||||||
|
@ -1836,12 +1849,14 @@ public class TestBalancer {
|
||||||
for(int i = 0; i < capacities.length; i++) {
|
for(int i = 0; i < capacities.length; i++) {
|
||||||
sourceNodes.add(datanodes.get(i).getDisplayName());
|
sourceNodes.add(datanodes.get(i).getDisplayName());
|
||||||
}
|
}
|
||||||
BalancerParameters.Builder b =
|
final BalancerParameters p = Balancer.Cli.parse(new String[] {
|
||||||
new BalancerParameters.Builder();
|
"-policy", BalancingPolicy.Node.INSTANCE.getName(),
|
||||||
b.setBalancingPolicy(BalancingPolicy.Node.INSTANCE);
|
"-threshold", "1",
|
||||||
b.setThreshold(1);
|
"-source", StringUtils.join(sourceNodes, ',')
|
||||||
b.setSourceNodes(sourceNodes);
|
});
|
||||||
final BalancerParameters p = b.build();
|
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);
|
conf.setLong(DFSConfigKeys.DFS_BALANCER_GETBLOCKS_MIN_BLOCK_SIZE_KEY, 1);
|
||||||
final int r = Balancer.run(namenodes, p, conf);
|
final int r = Balancer.run(namenodes, p, conf);
|
||||||
|
|
Loading…
Reference in New Issue