|
38 | 38 | import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY;
|
39 | 39 | import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY;
|
40 | 40 |
|
| 41 | +import java.lang.reflect.Field; |
41 | 42 | import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
42 | 43 | import org.junit.AfterClass;
|
43 | 44 | import static org.junit.Assert.assertEquals;
|
|
67 | 68 | import java.util.concurrent.atomic.AtomicLong;
|
68 | 69 |
|
69 | 70 | import org.apache.commons.lang3.StringUtils;
|
| 71 | +import org.junit.Assert; |
70 | 72 | import org.junit.Before;
|
71 | 73 | import org.slf4j.Logger;
|
72 | 74 | import org.slf4j.LoggerFactory;
|
@@ -1219,6 +1221,50 @@ public void testBalancerCliParseBlockpools() {
|
1219 | 1221 | assertEquals(1, p.getBlockPools().size());
|
1220 | 1222 | }
|
1221 | 1223 |
|
| 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 | + |
1222 | 1268 | /**
|
1223 | 1269 | * Verify balancer exits 0 on success.
|
1224 | 1270 | */
|
|
0 commit comments