@Test
public void testResourceCheck() throws Exception {

  HdfsConfiguration conf = new HdfsConfiguration();
  File basedir = new File(MiniDFSCluster.getBaseDirectory(),
      GenericTestUtils.getMethodName());
  MiniDFSCluster tmpCluster = new MiniDFSCluster.Builder(conf, basedir)
      .numDataNodes(0)
      .nnTopology(MiniDFSNNTopology.simpleHATopology())
      .build();
  try {
    MockNameNodeResourceChecker mockResourceChecker =
        new MockNameNodeResourceChecker(conf);
    tmpCluster.getNameNode(0).getNamesystem()
        .setNNResourceChecker(mockResourceChecker);
    NNHAServiceTarget haTarget = new NNHAServiceTarget(conf,
        DFSUtil.getNamenodeNameServiceId(
            new HdfsConfiguration()), "nn1");
    HAServiceProtocol rpc = haTarget.getHealthMonitorProxy(conf, conf.getInt(
        HA_HM_RPC_TIMEOUT_KEY, HA_HM_RPC_TIMEOUT_DEFAULT));
    MetricsRecordBuilder rb = getMetrics(NN_METRICS);
    for (long i = 0; i < 10; i++) {
      rpc.monitorHealth();
      assertQuantileGauges("ResourceCheckTime1s", rb);
    }
  } finally {
    if (tmpCluster != null) {
      tmpCluster.shutdown();
    }
  }
}