Skip to content

Commit cb632fa

Browse files
author
Felix Nguyen
committed
HDFS-17634. Add unit test
1 parent 51cb3f7 commit cb632fa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Collections;
2626
import java.util.HashMap;
2727
import java.util.Map;
28+
import java.util.Optional;
2829
import java.util.concurrent.ExecutionException;
2930
import java.util.concurrent.TimeUnit;
3031
import java.util.function.Function;
@@ -476,6 +477,7 @@ private String getNodesImpl(final DatanodeReportType type) {
476477
innerinfo.put("infoSecureAddr", node.getInfoSecureAddr());
477478
innerinfo.put("xferaddr", node.getXferAddr());
478479
innerinfo.put("location", node.getNetworkLocation());
480+
innerinfo.put("uuid", Optional.ofNullable(node.getDatanodeUuid()).orElse(""));
479481
innerinfo.put("lastContact", getLastContact(node));
480482
innerinfo.put("usedSpace", node.getDfsUsed());
481483
innerinfo.put("adminState", node.getAdminState().toString());

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
import org.apache.hadoop.service.Service.STATE;
136136
import org.apache.hadoop.test.GenericTestUtils;
137137
import org.apache.hadoop.test.LambdaTestUtils;
138+
139+
import org.codehaus.jettison.json.JSONArray;
138140
import org.codehaus.jettison.json.JSONException;
139141
import org.codehaus.jettison.json.JSONObject;
140142
import org.junit.After;
@@ -1880,6 +1882,22 @@ public void testNamenodeMetrics() throws Exception {
18801882
JSONObject jsonObject = new JSONObject(jsonString0);
18811883
assertEquals(NUM_SUBCLUSTERS * NUM_DNS, jsonObject.names().length());
18821884

1885+
JSONObject jsonObjectNn =
1886+
new JSONObject(cluster.getRandomNamenode().getNamenode().getNamesystem().getLiveNodes());
1887+
// DN report by NN and router should be the same
1888+
String randomDn = (String) jsonObjectNn.names().get(0);
1889+
JSONObject randomReportNn = jsonObjectNn.getJSONObject(randomDn);
1890+
JSONObject randomReportRouter = jsonObject.getJSONObject(randomDn);
1891+
JSONArray keys = randomReportNn.names();
1892+
for (int i = 0; i < keys.length(); i++) {
1893+
String key = keys.getString(i);
1894+
// Skip the 2 keys that always return -1
1895+
if (key.equals("blockScheduled") || key.equals("volfails")) {
1896+
continue;
1897+
}
1898+
assertEquals(randomReportRouter.get(key), randomReportNn.get(key));
1899+
}
1900+
18831901
// We should be caching this information
18841902
String jsonString1 = metrics.getLiveNodes();
18851903
assertEquals(jsonString0, jsonString1);

0 commit comments

Comments
 (0)