@Test
public void testGetYarnConfWithRmHaId() throws IOException {

  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_HA_ID, "rm0");
  conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false);
  YarnConfiguration result = YarnClientUtils.getYarnConfWithRmHaId(conf);
  assertSameConf(conf, result);
  assertEquals("RM_HA_ID was changed when it shouldn't have been: "
      + result.get(YarnConfiguration.RM_HA_ID), "rm0",
      result.get(YarnConfiguration.RM_HA_ID));
  conf = new Configuration();
  conf.set(YarnConfiguration.RM_HA_ID, "rm0");
  conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
  result = YarnClientUtils.getYarnConfWithRmHaId(conf);
  assertSameConf(conf, result);
  assertEquals("RM_HA_ID was changed when it shouldn't have been: "
      + result.get(YarnConfiguration.RM_HA_ID), "rm0",
      result.get(YarnConfiguration.RM_HA_ID));
  conf = new Configuration();
  conf.set(YarnConfiguration.RM_HA_IDS, "rm0,rm1");
  conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
  result = YarnClientUtils.getYarnConfWithRmHaId(conf);
  assertSameConf(conf, result);
  assertEquals("RM_HA_ID was not set correctly: "
       + result.get(YarnConfiguration.RM_HA_ID), "rm0",
       result.get(YarnConfiguration.RM_HA_ID));
  conf = new Configuration();
  conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
  try {
    YarnClientUtils.getYarnConfWithRmHaId(conf);
    fail("Allowed invalid HA configuration: HA is enabled, but no RM ID "
        + "is set");
  } catch (IOException ex) {
    // Expected
  }
}