HDFS-14936. Add getNumOfChildren() for interface InnerNode. Contributed by Lisheng Sun.

This commit is contained in:
Ayush Saxena 2019-10-31 23:39:27 +05:30
parent 8c9173c87c
commit d9fbedc4ae
4 changed files with 10 additions and 5 deletions

View File

@ -47,6 +47,9 @@ public interface InnerNode extends Node {
/** @return its children */ /** @return its children */
List<Node> getChildren(); List<Node> getChildren();
/** @return the number of children this node has. */
int getNumOfChildren();
/** @return the number of leave nodes. */ /** @return the number of leave nodes. */
int getNumOfLeaves(); int getNumOfLeaves();

View File

@ -59,7 +59,8 @@ public class InnerNodeImpl extends NodeBase implements InnerNode {
} }
/** @return the number of children this node has. */ /** @return the number of children this node has. */
int getNumOfChildren() { @Override
public int getNumOfChildren() {
return children.size(); return children.size();
} }

View File

@ -109,10 +109,6 @@ public class DFSTopologyNodeImpl extends InnerNodeImpl {
} }
} }
int getNumOfChildren() {
return children.size();
}
private void incStorageTypeCount(StorageType type) { private void incStorageTypeCount(StorageType type) {
// no locking because the caller is synchronized already // no locking because the caller is synchronized already
if (storageTypeCounts.containsKey(type)) { if (storageTypeCounts.containsKey(type)) {

View File

@ -351,6 +351,10 @@ public class TestNetworkTopology {
@Test @Test
public void testRemove() throws Exception { public void testRemove() throws Exception {
// this cluster topology is:
// /d1/r1, /d1/r2, /d2/r3, /d3/r1, /d3/r2, /d4/r1
// so root "" has four children
assertEquals(4, cluster.clusterMap.getNumOfChildren());
for(int i=0; i<dataNodes.length; i++) { for(int i=0; i<dataNodes.length; i++) {
cluster.remove(dataNodes[i]); cluster.remove(dataNodes[i]);
} }
@ -359,6 +363,7 @@ public class TestNetworkTopology {
} }
assertEquals(0, cluster.getNumOfLeaves()); assertEquals(0, cluster.getNumOfLeaves());
assertEquals(0, cluster.clusterMap.getChildren().size()); assertEquals(0, cluster.clusterMap.getChildren().size());
assertEquals(0, cluster.clusterMap.getNumOfChildren());
for(int i=0; i<dataNodes.length; i++) { for(int i=0; i<dataNodes.length; i++) {
cluster.add(dataNodes[i]); cluster.add(dataNodes[i]);
} }