You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xg...@apache.org on 2015/05/19 18:56:52 UTC
hadoop git commit: YARN-3601. Fix UT
TestRMFailover.testRMWebAppRedirect. Contributed by Weiwei Yang
Repository: hadoop
Updated Branches:
refs/heads/trunk de30d66b2 -> 5009ad4a7
YARN-3601. Fix UT TestRMFailover.testRMWebAppRedirect. Contributed by Weiwei Yang
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5009ad4a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5009ad4a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5009ad4a
Branch: refs/heads/trunk
Commit: 5009ad4a7f712fc578b461ecec53f7f97eaaed0c
Parents: de30d66
Author: Xuan <xg...@apache.org>
Authored: Tue May 19 09:56:01 2015 -0700
Committer: Xuan <xg...@apache.org>
Committed: Tue May 19 09:56:01 2015 -0700
----------------------------------------------------------------------
hadoop-yarn-project/CHANGES.txt | 2 +
.../hadoop/yarn/client/TestRMFailover.java | 78 ++++++++++----------
2 files changed, 40 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/5009ad4a/hadoop-yarn-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt
index c6f753d..e17e9c7 100644
--- a/hadoop-yarn-project/CHANGES.txt
+++ b/hadoop-yarn-project/CHANGES.txt
@@ -509,6 +509,8 @@ Release 2.7.1 - UNRELEASED
YARN-3526. ApplicationMaster tracking URL is incorrectly redirected
on a QJM cluster. (Weiwei Yang via xgong)
+ YARN-3601. Fix UT TestRMFailover.testRMWebAppRedirect. (Weiwei Yang via xgong)
+
Release 2.7.0 - 2015-04-20
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/hadoop/blob/5009ad4a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
index d4fc5c1..cd22743 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
@@ -21,13 +21,13 @@ package org.apache.hadoop.yarn.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.util.List;
-import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -48,7 +48,6 @@ import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class TestRMFailover extends ClientBaseWithFixes {
@@ -275,10 +274,6 @@ public class TestRMFailover extends ClientBaseWithFixes {
assertEquals(404, response.getResponseCode());
}
- // ignore this testcase, Always gets "too many redirect loops" exception
- // Probably because of the limitation of MiniYARNCluster.
- // Verified the behavior in a single node cluster.
- @Ignore
@Test
public void testRMWebAppRedirect() throws YarnException,
InterruptedException, IOException {
@@ -290,59 +285,62 @@ public class TestRMFailover extends ClientBaseWithFixes {
getAdminService(0).transitionToActive(req);
String rm1Url = "http://0.0.0.0:18088";
String rm2Url = "http://0.0.0.0:28088";
- String header = getHeader("Refresh", rm2Url);
- assertTrue(header.contains("; url=" + rm1Url));
+ String redirectURL = getRedirectURL(rm2Url);
+ // if uri is null, RMWebAppFilter will append a slash at the trail of the redirection url
+ assertEquals(redirectURL,rm1Url+"/");
- header = getHeader("Refresh", rm2Url + "/metrics");
- assertTrue(header.contains("; url=" + rm1Url));
+ redirectURL = getRedirectURL(rm2Url + "/metrics");
+ assertEquals(redirectURL,rm1Url + "/metrics");
- header = getHeader("Refresh", rm2Url + "/jmx");
- assertTrue(header.contains("; url=" + rm1Url));
+ redirectURL = getRedirectURL(rm2Url + "/jmx");
+ assertEquals(redirectURL,rm1Url + "/jmx");
// standby RM links /conf, /stacks, /logLevel, /static, /logs,
// /cluster/cluster as well as webService
// /ws/v1/cluster/info should not be redirected to active RM
- header = getHeader("Refresh", rm2Url + "/cluster/cluster");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/cluster/cluster");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/conf");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/conf");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/stacks");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/stacks");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/logLevel");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/logLevel");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/static");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/static");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/logs");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/logs");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/ws/v1/cluster/info");
- assertEquals(null, header);
+ redirectURL = getRedirectURL(rm2Url + "/ws/v1/cluster/info");
+ assertNull(redirectURL);
- header = getHeader("Refresh", rm2Url + "/ws/v1/cluster/apps");
- assertTrue(header.contains("; url=" + rm1Url));
+ redirectURL = getRedirectURL(rm2Url + "/ws/v1/cluster/apps");
+ assertEquals(redirectURL, rm1Url + "/ws/v1/cluster/apps");
- header = getHeader("Refresh", rm2Url + "/proxy/" + fakeAppId);
- assertEquals(null, header);
-
- // Due to the limitation of MiniYARNCluster and dispatcher is a singleton,
- // we couldn't add the test case after explicitFailover();
+ redirectURL = getRedirectURL(rm2Url + "/proxy/" + fakeAppId);
+ assertNull(redirectURL);
}
- static String getHeader(String field, String url) {
- String fieldHeader = null;
+ // set up http connection with the given url and get the redirection url from the response
+ // return null if the url is not redirected
+ static String getRedirectURL(String url) {
+ String redirectUrl = null;
try {
- Map<String, List<String>> map =
- new URL(url).openConnection().getHeaderFields();
- fieldHeader = map.get(field).get(0);
+ HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
+ // do not automatically follow the redirection
+ // otherwise we get too many redirections exception
+ conn.setInstanceFollowRedirects(false);
+ if(conn.getResponseCode() == HttpServletResponse.SC_TEMPORARY_REDIRECT)
+ redirectUrl = conn.getHeaderField("Location");
} catch (Exception e) {
// throw new RuntimeException(e);
}
- return fieldHeader;
+ return redirectUrl;
}
}