@Test
public void testNamenodeStatsDataSource() throws IOException, JSONException {

  RBFMetrics metrics = getRouter().getMetrics();
  String jsonString = metrics.getNamenodes();
  JSONObject jsonObject = new JSONObject(jsonString);
  Iterator<?> keys = jsonObject.keys();
  int nnsFound = 0;
  while (keys.hasNext()) {
    // Validate each entry against our mocks
    JSONObject json = jsonObject.getJSONObject((String) keys.next());
    String nameserviceId = json.getString("nameserviceId");
    String namenodeId = json.getString("namenodeId");
    MembershipState mockEntry =
        this.findMockNamenode(nameserviceId, namenodeId);
    assertNotNull(mockEntry);
    assertEquals(json.getString("state"), mockEntry.getState().toString());
    MembershipStats stats = mockEntry.getStats();
    assertEquals(json.getLong("numOfActiveDatanodes"),
        stats.getNumOfActiveDatanodes());
    assertEquals(json.getLong("numOfDeadDatanodes"),
        stats.getNumOfDeadDatanodes());
    assertEquals(json.getLong("numOfStaleDatanodes"),
        stats.getNumOfStaleDatanodes());
    assertEquals(json.getLong("numOfDecommissioningDatanodes"),
        stats.getNumOfDecommissioningDatanodes());
    assertEquals(json.getLong("numOfDecomActiveDatanodes"),
        stats.getNumOfDecomActiveDatanodes());
    assertEquals(json.getLong("numOfDecomDeadDatanodes"),
        stats.getNumOfDecomDeadDatanodes());
    assertEquals(json.getLong("numOfInMaintenanceLiveDataNodes"),
        stats.getNumOfInMaintenanceLiveDataNodes());
    assertEquals(json.getLong("numOfInMaintenanceDeadDataNodes"),
        stats.getNumOfInMaintenanceDeadDataNodes());
    assertEquals(json.getLong("numOfEnteringMaintenanceDataNodes"),
        stats.getNumOfEnteringMaintenanceDataNodes());
    assertEquals(json.getLong("numOfBlocks"), stats.getNumOfBlocks());
    assertEquals(json.getString("rpcAddress"), mockEntry.getRpcAddress());
    assertEquals(json.getString("webScheme"), mockEntry.getWebScheme());
    assertEquals(json.getString("webAddress"), mockEntry.getWebAddress());
    nnsFound++;
  }
  // Validate all memberships are present
  assertEquals(getActiveMemberships().size() + getStandbyMemberships().size(),
      nnsFound);
}