Skip to content

Commit 34049e7

Browse files
committed
fix ut and code style
1 parent e1bec48 commit 34049e7

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.servlet.http.HttpServletRequest;
5151
import javax.servlet.http.HttpServletResponse;
5252

53+
import org.apache.hadoop.classification.VisibleForTesting;
5354
import org.apache.hadoop.conf.Configuration;
5455
import org.apache.hadoop.fs.CommonConfigurationKeys;
5556
import org.apache.hadoop.http.HttpServer2;
@@ -63,6 +64,7 @@
6364
import org.apache.hadoop.yarn.conf.YarnConfiguration;
6465
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
6566
import org.apache.hadoop.yarn.exceptions.YarnException;
67+
import org.apache.hadoop.yarn.util.StringHelper;
6668
import org.apache.hadoop.yarn.webapp.MimeType;
6769
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
6870
import org.eclipse.jetty.server.ServerConnector;
@@ -363,6 +365,7 @@ public void testAppReportForEmptyTrackingUrl() throws Exception {
363365
//set AHS_ENBALED = true to simulate getting the app report from AHS
364366
configuration.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
365367
true);
368+
proxy.proxy.appReportFetcher.setAhsAppPageUrlBase(configuration);
366369
proxyConn = (HttpURLConnection) url.openConnection();
367370
proxyConn.connect();
368371
try {
@@ -375,8 +378,8 @@ public void testAppReportForEmptyTrackingUrl() throws Exception {
375378
String appAddressInAhs = WebAppUtils.getHttpSchemePrefix(configuration) +
376379
WebAppUtils.getAHSWebAppURLWithoutScheme(configuration) +
377380
"/applicationhistory" + "/app/" + app.toString();
378-
assertTrue("Webapp proxy servlet should have redirected to AHS",
379-
proxyConn.getURL().toString().equals(appAddressInAhs));
381+
assertEquals("Webapp proxy servlet should have redirected to AHS",
382+
appAddressInAhs, proxyConn.getURL().toString());
380383
}
381384
finally {
382385
proxy.close();
@@ -602,6 +605,7 @@ protected void serviceStart() throws Exception {
602605

603606
private class AppReportFetcherForTest extends DefaultAppReportFetcher {
604607
int answer = 0;
608+
private String ahsAppPageUrlBase = null;
605609

606610
public AppReportFetcherForTest(Configuration conf) {
607611
super(conf);
@@ -672,5 +676,19 @@ private FetchedAppReport getDefaultApplicationReport(ApplicationId appId,
672676
private FetchedAppReport getDefaultApplicationReport(ApplicationId appId) {
673677
return getDefaultApplicationReport(appId, true);
674678
}
679+
680+
@VisibleForTesting
681+
public String getAhsAppPageUrlBase() {
682+
return ahsAppPageUrlBase != null ? ahsAppPageUrlBase
683+
: super.getAhsAppPageUrlBase();
684+
}
685+
686+
@VisibleForTesting
687+
public void setAhsAppPageUrlBase(Configuration conf) {
688+
this.ahsAppPageUrlBase =
689+
StringHelper.pjoin(WebAppUtils.getHttpSchemePrefix(conf)
690+
+ WebAppUtils.getAHSWebAppURLWithoutScheme(conf),
691+
"applicationhistory", "app");
692+
}
675693
}
676694
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServletFed.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static void tearDown() throws Exception {
118118
}
119119

120120
@Test
121-
public void TestWebServlet() throws IOException {
121+
public void testWebServlet() throws IOException {
122122
HttpURLConnection conn;
123123
// 1. Mocked AppMaster web Test
124124
URL url = new URL("http://localhost:" + mockServerPort + "/amweb/apptest");
@@ -148,7 +148,7 @@ public void TestWebServlet() throws IOException {
148148
}
149149

150150
@Test(timeout=5000)
151-
public void TestWebAppProxyServletFed() throws Exception {
151+
public void testWebAppProxyServletFed() throws Exception {
152152

153153
Configuration conf = new Configuration();
154154
conf.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
@@ -163,10 +163,10 @@ public void TestWebAppProxyServletFed() throws Exception {
163163
SubClusterId subClusterId1 = SubClusterId.newInstance("scid1");
164164
SubClusterId subClusterId2 = SubClusterId.newInstance("scid2");
165165
SubClusterInfo subClusterInfo1 = SubClusterInfo.newInstance(subClusterId1,
166-
"10.0.0.1:1","10.0.0.1:1","10.0.0.1:1",
166+
"10.0.0.1:1", "10.0.0.1:1", "10.0.0.1:1",
167167
"localhost:" + mockServerPort, SubClusterState.SC_RUNNING, 0, "");
168168
SubClusterInfo subClusterInfo2 = SubClusterInfo.newInstance(subClusterId2,
169-
"10.0.0.2:1","10.0.0.2:1","10.0.0.2:1",
169+
"10.0.0.2:1", "10.0.0.2:1", "10.0.0.2:1",
170170
"10.0.0.2:1", SubClusterState.SC_RUNNING, 0, "");
171171

172172
// App1 and App2 is running applications.
@@ -302,12 +302,12 @@ private class WebAppProxyServerForTest extends CompositeService {
302302

303303
private WebAppProxyForTest proxy = null;
304304

305-
public WebAppProxyServerForTest() {
305+
WebAppProxyServerForTest() {
306306
super(WebAppProxyServer.class.getName());
307307
}
308308

309309
@Override
310-
public synchronized void serviceInit(Configuration conf) throws Exception {
310+
protected synchronized void serviceInit(Configuration conf) throws Exception {
311311
proxy = new WebAppProxyForTest();
312312
addService(proxy);
313313
super.serviceInit(conf);
@@ -353,8 +353,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
353353

354354
private class WebAppProxyForTest extends WebAppProxy {
355355

356-
HttpServer2 proxyServer;
357-
FedAppReportFetcher appReportFetcher;
356+
private HttpServer2 proxyServer;
357+
private FedAppReportFetcher appReportFetcher;
358358

359359
@Override
360360
protected void serviceStart() throws Exception {

0 commit comments

Comments
 (0)