|
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -32,10 +34,14 @@ import java.net.HttpCookie;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.Enumeration;
|
|
import java.util.Enumeration;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+import javax.servlet.ServletConfig;
|
|
|
|
+import javax.servlet.ServletContext;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -90,6 +96,7 @@ public class TestWebAppProxyServlet {
|
|
context.setContextPath("/foo");
|
|
context.setContextPath("/foo");
|
|
server.setHandler(context);
|
|
server.setHandler(context);
|
|
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
|
|
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
|
|
|
|
+ context.addServlet(new ServletHolder(TimeOutTestServlet.class), "/timeout");
|
|
server.getConnectors()[0].setHost("localhost");
|
|
server.getConnectors()[0].setHost("localhost");
|
|
server.start();
|
|
server.start();
|
|
originalPort = server.getConnectors()[0].getLocalPort();
|
|
originalPort = server.getConnectors()[0].getLocalPort();
|
|
@@ -137,6 +144,29 @@ public class TestWebAppProxyServlet {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressWarnings("serial")
|
|
|
|
+ public static class TimeOutTestServlet extends HttpServlet {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(10 * 1000);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ LOG.warn("doGet() interrupted", e);
|
|
|
|
+ resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ resp.setStatus(HttpServletResponse.SC_OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
+ resp.setStatus(HttpServletResponse.SC_OK);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test(timeout=5000)
|
|
@Test(timeout=5000)
|
|
public void testWebAppProxyServlet() throws Exception {
|
|
public void testWebAppProxyServlet() throws Exception {
|
|
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
@@ -248,6 +278,45 @@ public class TestWebAppProxyServlet {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test(expected = SocketTimeoutException.class)
|
|
|
|
+ public void testWebAppProxyConnectionTimeout()
|
|
|
|
+ throws IOException, ServletException{
|
|
|
|
+ HttpServletRequest request = mock(HttpServletRequest.class);
|
|
|
|
+ when(request.getMethod()).thenReturn("GET");
|
|
|
|
+ when(request.getRemoteUser()).thenReturn("dr.who");
|
|
|
|
+ when(request.getPathInfo()).thenReturn("/application_00_0");
|
|
|
|
+ when(request.getHeaderNames()).thenReturn(Collections.emptyEnumeration());
|
|
|
|
+
|
|
|
|
+ HttpServletResponse response = mock(HttpServletResponse.class);
|
|
|
|
+ when(response.getOutputStream()).thenReturn(null);
|
|
|
|
+
|
|
|
|
+ WebAppProxyServlet servlet = new WebAppProxyServlet();
|
|
|
|
+ YarnConfiguration conf = new YarnConfiguration();
|
|
|
|
+ conf.setBoolean(YarnConfiguration.RM_PROXY_TIMEOUT_ENABLED,
|
|
|
|
+ true);
|
|
|
|
+ conf.setInt(YarnConfiguration.RM_PROXY_CONNECTION_TIMEOUT,
|
|
|
|
+ 1000);
|
|
|
|
+
|
|
|
|
+ servlet.setConf(conf);
|
|
|
|
+
|
|
|
|
+ ServletConfig config = mock(ServletConfig.class);
|
|
|
|
+ ServletContext context = mock(ServletContext.class);
|
|
|
|
+ when(config.getServletContext()).thenReturn(context);
|
|
|
|
+
|
|
|
|
+ AppReportFetcherForTest appReportFetcher =
|
|
|
|
+ new AppReportFetcherForTest(new YarnConfiguration());
|
|
|
|
+
|
|
|
|
+ when(config.getServletContext()
|
|
|
|
+ .getAttribute(WebAppProxy.FETCHER_ATTRIBUTE))
|
|
|
|
+ .thenReturn(appReportFetcher);
|
|
|
|
+
|
|
|
|
+ appReportFetcher.answer = 7;
|
|
|
|
+
|
|
|
|
+ servlet.init(config);
|
|
|
|
+ servlet.doGet(request, response);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test(timeout=5000)
|
|
@Test(timeout=5000)
|
|
public void testAppReportForEmptyTrackingUrl() throws Exception {
|
|
public void testAppReportForEmptyTrackingUrl() throws Exception {
|
|
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
@@ -330,12 +399,13 @@ public class TestWebAppProxyServlet {
|
|
assertEquals(proxyConn.getRequestProperties().size(), 4);
|
|
assertEquals(proxyConn.getRequestProperties().size(), 4);
|
|
proxyConn.connect();
|
|
proxyConn.connect();
|
|
assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode());
|
|
assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode());
|
|
- // Verify if number of headers received by end server is 8.
|
|
|
|
- // Eight headers include Accept, Host, Connection, User-Agent, Cookie,
|
|
|
|
- // Origin, Access-Control-Request-Method and
|
|
|
|
|
|
+ // Verify if number of headers received by end server is 9.
|
|
|
|
+ // This should match WebAppProxyServlet#PASS_THROUGH_HEADERS.
|
|
|
|
+ // Nine headers include Accept, Host, Connection, User-Agent, Cookie,
|
|
|
|
+ // Origin, Access-Control-Request-Method, Accept-Encoding, and
|
|
// Access-Control-Request-Headers. Pls note that Unknown-Header is dropped
|
|
// Access-Control-Request-Headers. Pls note that Unknown-Header is dropped
|
|
// by proxy as it is not in the list of allowed headers.
|
|
// by proxy as it is not in the list of allowed headers.
|
|
- assertEquals(numberOfHeaders, 8);
|
|
|
|
|
|
+ assertEquals(numberOfHeaders, 9);
|
|
assertFalse(hasUnknownHeader);
|
|
assertFalse(hasUnknownHeader);
|
|
} finally {
|
|
} finally {
|
|
proxy.close();
|
|
proxy.close();
|
|
@@ -553,6 +623,12 @@ public class TestWebAppProxyServlet {
|
|
return result;
|
|
return result;
|
|
} else if (answer == 6) {
|
|
} else if (answer == 6) {
|
|
return getDefaultApplicationReport(appId, false);
|
|
return getDefaultApplicationReport(appId, false);
|
|
|
|
+ } else if (answer == 7) {
|
|
|
|
+ // test connection timeout
|
|
|
|
+ FetchedAppReport result = getDefaultApplicationReport(appId);
|
|
|
|
+ result.getApplicationReport().setOriginalTrackingUrl("localhost:"
|
|
|
|
+ + originalPort + "/foo/timeout?a=b#main");
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|