@Test
public void testGracefulDecommissionDefaultTimeoutResolution()
    throws Exception {

  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, excludeHostXmlFile
      .getAbsolutePath());
  writeToHostsXmlFile(excludeHostXmlFile, Pair.of("", null));
  rm = new MockRM(conf);
  rm.start();
  int nodeMemory = 1024;
  MockNM nm1 = rm.registerNode("host1:1234", nodeMemory);
  MockNM nm2 = rm.registerNode("host2:5678", nodeMemory);
  MockNM nm3 = rm.registerNode("host3:9101", nodeMemory);
  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(nm1.getNodeId(), NodeState.RUNNING);
  rm.waitForState(nm2.getNodeId(), NodeState.RUNNING);
  rm.waitForState(nm3.getNodeId(), NodeState.RUNNING);
  // Graceful decommission both host1 and host2, with
  // non default timeout for host1
  final Integer nm1DecommissionTimeout = 20;
  writeToHostsXmlFile(
      excludeHostXmlFile,
      Pair.of(nm1.getNodeId().getHost(), nm1DecommissionTimeout),
      Pair.of(nm2.getNodeId().getHost(), null));
  rm.getNodesListManager().refreshNodes(conf, true);
  rm.waitForState(nm1.getNodeId(), NodeState.DECOMMISSIONING);
  rm.waitForState(nm2.getNodeId(), NodeState.DECOMMISSIONING);
  Assert.assertEquals(
      nm1DecommissionTimeout, rm.getDecommissioningTimeout(nm1.getNodeId()));
  Integer defaultDecTimeout =
      conf.getInt(YarnConfiguration.RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT,
          YarnConfiguration.DEFAULT_RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT);
  Assert.assertEquals(
      defaultDecTimeout, rm.getDecommissioningTimeout(nm2.getNodeId()));
  // Graceful decommission host3 with a new default timeout
  final Integer newDefaultDecTimeout = defaultDecTimeout + 10;
  writeToHostsXmlFile(
      excludeHostXmlFile, Pair.of(nm3.getNodeId().getHost(), null));
  conf.setInt(YarnConfiguration.RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT,
      newDefaultDecTimeout);
  rm.getNodesListManager().refreshNodes(conf, true);
  rm.waitForState(nm3.getNodeId(), NodeState.DECOMMISSIONING);
  Assert.assertEquals(
      newDefaultDecTimeout, rm.getDecommissioningTimeout(nm3.getNodeId()));
}