diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java index 3445e27..7ea5f51 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDistributedShell.java @@ -26,13 +26,13 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; +import java.net.InetAddress; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Assert; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -169,7 +169,9 @@ public void run() { yarnClient.init(new Configuration(yarnCluster.getConfig())); yarnClient.start(); String hostName = NetUtils.getHostname(); + boolean verified = false; + String errorMessage = ""; while(!verified) { List apps = yarnClient.getApplications(); if (apps.size() == 0 ) { @@ -177,15 +179,18 @@ public void run() { continue; } ApplicationReport appReport = apps.get(0); - if (appReport.getHost().startsWith(hostName) - && appReport.getRpcPort() == -1) { + errorMessage = + "Expected host name to start with '" + hostName + "', was '" + + appReport.getHost() + "'. Expected rpc port to be '-1', was '" + + appReport.getRpcPort() + "'."; + if (checkHostname(appReport.getHost()) && appReport.getRpcPort() == -1) { verified = true; } if (appReport.getYarnApplicationState() == YarnApplicationState.FINISHED) { break; } } - Assert.assertTrue(verified); + Assert.assertTrue(errorMessage, verified); t.join(); LOG.info("Client run completed. Result=" + result); Assert.assertTrue(result.get()); @@ -212,6 +217,49 @@ public void run() { .toString(), ApplicationMaster.DSEntity.DS_CONTAINER.toString()); } + private boolean checkHostname(String appHostname) throws Exception { + + String hostname = NetUtils.getHostname(); + if (hostname.equals(appHostname)) { + return true; + } + + Assert.assertTrue("Unknown format for hostname " + appHostname, + appHostname.contains("/")); + Assert.assertTrue("Unknown format for hostname " + hostname, + hostname.contains("/")); + + String[] appHostnameParts = appHostname.split("/"); + String[] hostnameParts = hostname.split("/"); + if (appHostnameParts[1].equals(hostnameParts[1])) { + // if ip's match, compare fqdn for both + String appFQDN = + InetAddress.getByName(appHostnameParts[0]).getCanonicalHostName(); + String localFQDN = + InetAddress.getByName(hostnameParts[0]).getCanonicalHostName(); + if (appFQDN.equals(localFQDN)) { + return true; + } + } else if (appHostnameParts[0].equals(hostnameParts[0])) { + // hostnames match, check ip addresses + boolean appIPCheck = false; + boolean localIPCheck = false; + InetAddress[] addresses = InetAddress.getAllByName(appHostnameParts[0]); + for (InetAddress ia : addresses) { + if (ia.getHostAddress().equals(appHostnameParts[1])) { + appIPCheck = true; + continue; + } + if (ia.getHostAddress().equals(hostnameParts[1])) { + localIPCheck = true; + } + } + return (appIPCheck && localIPCheck); + } + + return false; + } + @Test(timeout=90000) public void testDSRestartWithPreviousRunningContainers() throws Exception { String[] args = {