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 @@ interface Factory<N extends InnerNode> {
/** @return its children */
List<Node> getChildren();
/** @return the number of children this node has. */
int getNumOfChildren();
/** @return the number of leave nodes. */
int getNumOfLeaves();

View File

@ -59,7 +59,8 @@ public List<Node> getChildren() {
}
/** @return the number of children this node has. */
int getNumOfChildren() {
@Override
public int getNumOfChildren() {
return children.size();
}

View File

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

View File

@ -351,6 +351,10 @@ public void testSortByDistance() throws Exception {
@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 void testRemove() throws Exception {
}
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]);
}