@Test
public void testNodeRegistrationWithCentralLabelConfig() throws Exception {

  writeToHostsFile("host2");
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH,
      hostFile.getAbsolutePath());
  conf.set(YarnConfiguration.NODELABEL_CONFIGURATION_TYPE,
      YarnConfiguration.DEFAULT_NODELABEL_CONFIGURATION_TYPE);
  final RMNodeLabelsManager nodeLabelsMgr = new NullRMNodeLabelsManager();
  rm = new MockRM(conf) {
    @Override
    protected RMNodeLabelsManager createNodeLabelManager() {
      return nodeLabelsMgr;
    }
  };
  rm.start();
  try {
    nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("A", "B", "C"));
  } catch (IOException e) {
    Assert.fail("Caught Exception while initializing");
    e.printStackTrace();
  }
  ResourceTrackerService resourceTrackerService =
      rm.getResourceTrackerService();
  RegisterNodeManagerRequest req =
      Records.newRecord(RegisterNodeManagerRequest.class);
  NodeId nodeId = NodeId.newInstance("host2", 1234);
  Resource capability = BuilderUtils.newResource(1024, 1);
  req.setResource(capability);
  req.setNodeId(nodeId);
  req.setHttpPort(1234);
  req.setNMVersion(YarnVersionInfo.getVersion());
  req.setNodeLabels(toNodeLabelSet("A"));
  RegisterNodeManagerResponse response =
      resourceTrackerService.registerNodeManager(req);
  // registered to RM with central label config
  Assert.assertEquals(NodeAction.NORMAL, response.getNodeAction());
  Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId));
  Assert
      .assertFalse(
          "Node Labels should not accepted by RM If its configured with " +
              "Central configuration",
          response.getAreNodeLabelsAcceptedByRM());
  if (rm != null) {
    rm.stop();
  }
}