### Question:
Master { public static InetSocketAddress getMasterAddress(Configuration conf) { String masterAddress; String framework = conf.get(MRConfig.FRAMEWORK_NAME, MRConfig.YARN_FRAMEWORK_NAME); if (framework.equals(MRConfig.CLASSIC_FRAMEWORK_NAME)) { masterAddress = conf.get(MRConfig.MASTER_ADDRESS, "localhost:8012"); return NetUtils.createSocketAddr(masterAddress, 8012, MRConfig.MASTER_ADDRESS); } else { return conf.getSocketAddr( YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT); } }  static String getMasterUserName(Configuration conf); static InetSocketAddress getMasterAddress(Configuration conf); static String getMasterPrincipal(Configuration conf);  }### Answer:
@Test public void testGetMasterAddress() { YarnConfiguration conf = new YarnConfiguration(); String masterHostname = Master.getMasterAddress(conf).getHostName(); InetSocketAddress rmAddr = NetUtils.createSocketAddr(YarnConfiguration.DEFAULT_RM_ADDRESS); assertEquals(masterHostname, rmAddr.getHostName()); conf.set(MRConfig.FRAMEWORK_NAME, MRConfig.CLASSIC_FRAMEWORK_NAME); conf.set(MRConfig.MASTER_ADDRESS, "local:invalid"); try { Master.getMasterAddress(conf); fail("Should not reach here as there is a bad master address"); } catch (Exception e) { } conf.set(MRConfig.MASTER_ADDRESS, "bar.com:8042"); masterHostname = Master.getMasterAddress(conf).getHostName(); assertEquals(masterHostname, "bar.com"); conf.set(MRConfig.FRAMEWORK_NAME, MRConfig.YARN_FRAMEWORK_NAME); conf.set(YarnConfiguration.RM_ADDRESS, "foo1.com:8192"); masterHostname = Master.getMasterAddress(conf).getHostName(); assertEquals(masterHostname, "foo1.com"); }