public static String getMasterAddress(Configuration conf) {
    String masterAddress = conf.get(MRConfig.MASTER_ADDRESS, "localhost:8012");

    return NetUtils.createSocketAddr(masterAddress, 8012,
            MRConfig.MASTER_ADDRESS).getHostName();
  }
@Test
  public void testGetMasterAddress() {
    YarnConfiguration conf = new YarnConfiguration();

    // Trying invalid master address for classic 
    conf.set(MRConfig.FRAMEWORK_NAME, MRConfig.CLASSIC_FRAMEWORK_NAME);
    conf.set(MRConfig.MASTER_ADDRESS, "local:invalid");

    // should throw an exception for invalid value
    try {
      Master.getMasterAddress(conf);
      fail("Should not reach here as there is a bad master address");
    }
    catch (Exception e) {
      // Expected
    }

    // Change master address to a valid value
    conf.set(MRConfig.MASTER_ADDRESS, "bar.com:8042");    
    String masterHostname = Master.getMasterAddress(conf);
    assertThat(masterHostname).isEqualTo("bar.com");
  }