Browse Source

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

Ayush Saxena 5 năm trước cách đây
mục cha
commit
d9fbedc4ae

+ 3 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNode.java

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

+ 2 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNodeImpl.java

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

+ 0 - 4
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/net/DFSTopologyNodeImpl.java

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

+ 5 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/net/TestNetworkTopology.java

@@ -351,6 +351,10 @@ public class TestNetworkTopology {
   
   @Test
   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++) {
       cluster.remove(dataNodes[i]);
     }
@@ -359,6 +363,7 @@ public class TestNetworkTopology {
     }
     assertEquals(0, cluster.getNumOfLeaves());
     assertEquals(0, cluster.clusterMap.getChildren().size());
+    assertEquals(0, cluster.clusterMap.getNumOfChildren());
     for(int i=0; i<dataNodes.length; i++) {
       cluster.add(dataNodes[i]);
     }