@Test
public void testGracefulDecommissionNoApp() throws Exception {

  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());
  writeToHostsFile("");
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  MockNM nm3 = rm.registerNode("host3:4433", 5120);
  int metricCount = ClusterMetrics.getMetrics().getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat1 = nm1.nodeHeartbeat(true);
  NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true);
  NodeHeartbeatResponse nodeHeartbeat3 = nm3.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction()));
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat2.getNodeAction()));
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat3.getNodeAction()));
  rm.waitForState(nm2.getNodeId(), NodeState.RUNNING);
  rm.waitForState(nm3.getNodeId(), NodeState.RUNNING);
  // Graceful decommission both host2 and host3.
  writeToHostsFile("host2", "host3");
  rm.getNodesListManager().refreshNodes(conf, true);
  rm.waitForState(nm2.getNodeId(), NodeState.DECOMMISSIONING);
  rm.waitForState(nm3.getNodeId(), NodeState.DECOMMISSIONING);
  nodeHeartbeat1 = nm1.nodeHeartbeat(true);
  nodeHeartbeat2 = nm2.nodeHeartbeat(true);
  nodeHeartbeat3 = nm3.nodeHeartbeat(true);
  checkDecommissionedNMCount(rm, metricCount + 2);
  rm.waitForState(nm2.getNodeId(), NodeState.DECOMMISSIONED);
  rm.waitForState(nm3.getNodeId(), NodeState.DECOMMISSIONED);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction()));
  Assert.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat2.getNodeAction());
  Assert.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat3.getNodeAction());
}