Skip to content

Commit c2cd0bd

Browse files
committed
HDFS-16119. start balancer with parameters -hotBlockTimeInterval xxx is invalid
1 parent 310a266 commit c2cd0bd

File tree

1 file changed

+46
-0
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer

1 file changed

+46
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY;
3939
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY;
4040

41+
import java.lang.reflect.Field;
4142
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
4243
import org.junit.AfterClass;
4344
import static org.junit.Assert.assertEquals;
@@ -67,6 +68,7 @@
6768
import java.util.concurrent.atomic.AtomicLong;
6869

6970
import org.apache.commons.lang3.StringUtils;
71+
import org.junit.Assert;
7072
import org.junit.Before;
7173
import org.slf4j.Logger;
7274
import org.slf4j.LoggerFactory;
@@ -1219,6 +1221,50 @@ public void testBalancerCliParseBlockpools() {
12191221
assertEquals(1, p.getBlockPools().size());
12201222
}
12211223

1224+
@Test
1225+
public void testBalancerCliParseHotBlockTimeInterval() {
1226+
String[] parameters = new String[]{"-hotBlockTimeInterval", "1000"};
1227+
BalancerParameters p = Balancer.Cli.parse(parameters);
1228+
assertEquals(1000, p.getHotBlockTimeInterval());
1229+
}
1230+
1231+
@Test
1232+
public void testBalancerDispatchHotBlockTimeInterval() {
1233+
String[] parameters = new String[]{"-hotBlockTimeInterval", "1000"};
1234+
BalancerParameters p = Balancer.Cli.parse(parameters);
1235+
Configuration conf = new HdfsConfiguration();
1236+
initConf(conf);
1237+
try {
1238+
cluster = new MiniDFSCluster
1239+
.Builder(conf)
1240+
.numDataNodes(0)
1241+
.setNNRedundancyConsiderLoad(false)
1242+
.build();
1243+
cluster.getConfiguration(0).setInt(DFSConfigKeys.DFS_REPLICATION_KEY,
1244+
DFSConfigKeys.DFS_REPLICATION_DEFAULT);
1245+
conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY,
1246+
DFSConfigKeys.DFS_REPLICATION_DEFAULT);
1247+
cluster.waitClusterUp();
1248+
cluster.waitActive();
1249+
Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
1250+
List<NameNodeConnector> connectors = NameNodeConnector.newNameNodeConnectors(namenodes,
1251+
Balancer.class.getSimpleName(), Balancer.BALANCER_ID_PATH, conf,
1252+
BalancerParameters.DEFAULT.getMaxIdleIteration());
1253+
1254+
Balancer run = new Balancer(connectors.get(0), p, new HdfsConfiguration());
1255+
Field field = run.getClass().getDeclaredField("dispatcher");
1256+
field.setAccessible(true);
1257+
Object dispatcher = field.get(run);
1258+
1259+
Field field1 = dispatcher.getClass().getDeclaredField("hotBlockTimeInterval");
1260+
field1.setAccessible(true);
1261+
Object hotBlockTimeInterval = field1.get(dispatcher);
1262+
assertEquals(1000, Long.parseLong(String.valueOf(hotBlockTimeInterval)));
1263+
} catch (Exception e) {
1264+
Assert.fail(e.getMessage());
1265+
}
1266+
}
1267+
12221268
/**
12231269
* Verify balancer exits 0 on success.
12241270
*/

0 commit comments

Comments
 (0)