diff --git a/CHANGES.txt b/CHANGES.txt
index 1375b41d19..8e5b965c9b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1602,6 +1602,9 @@ Release 0.21.0 - Unreleased
HADOOP-6404. Rename the generated artifacts to common instead of core.
(tomwhite)
+ HADOOP-6461. Webapps aren't located correctly post-split.
+ (Todd Lipcon and Steve Loughran via tomwhite)
+
Release 0.20.3 - Unreleased
NEW FEATURES
diff --git a/build.xml b/build.xml
index 2ba0ee4f73..1195e66d61 100644
--- a/build.xml
+++ b/build.xml
@@ -79,6 +79,7 @@
+
@@ -630,6 +631,8 @@
+
+
0) {
+ out.append(new String(buffer, 0, len));
+ len = in.read(buffer);
+ }
+ return out.toString();
+ }
+}
diff --git a/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java b/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
index 35a50e5e5d..d9b10ae091 100644
--- a/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
+++ b/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
@@ -36,8 +36,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
-public class TestGlobalFilter extends junit.framework.TestCase {
+public class TestGlobalFilter extends HttpServerFunctionalTest {
static final Log LOG = LogFactory.getLog(HttpServer.class);
static final Set RECORDS = new TreeSet();
@@ -95,13 +96,14 @@ static void access(String urlstring) throws IOException {
}
}
+ @Test
public void testServletFilter() throws Exception {
Configuration conf = new Configuration();
//start a http server with CountingFilter
conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY,
RecordingFilter.Initializer.class.getName());
- HttpServer http = new HttpServer("..", "localhost", 0, true, conf);
+ HttpServer http = createTestServer(conf);
http.start();
final String fsckURL = "/fsck";
diff --git a/src/test/core/org/apache/hadoop/http/TestHttpServer.java b/src/test/core/org/apache/hadoop/http/TestHttpServer.java
index 1c335ecbaf..77f174cf03 100644
--- a/src/test/core/org/apache/hadoop/http/TestHttpServer.java
+++ b/src/test/core/org/apache/hadoop/http/TestHttpServer.java
@@ -17,12 +17,7 @@
*/
package org.apache.hadoop.http;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -50,17 +45,15 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.ConfServlet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys;
-import org.apache.hadoop.http.HttpServer.QuotingInputFilter;
import org.apache.hadoop.security.Groups;
import org.apache.hadoop.security.ShellBasedUnixGroupsMapping;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-public class TestHttpServer {
+public class TestHttpServer extends HttpServerFunctionalTest {
private static HttpServer server;
private static URL baseUrl;
private static final int MAX_THREADS = 10;
@@ -115,30 +108,12 @@ public void doGet(HttpServletRequest request,
}
}
- private String readOutput(URL url) throws IOException {
- StringBuilder out = new StringBuilder();
- InputStream in = url.openConnection().getInputStream();
- byte[] buffer = new byte[64 * 1024];
- int len = in.read(buffer);
- while (len > 0) {
- out.append(new String(buffer, 0, len));
- len = in.read(buffer);
- }
- return out.toString();
- }
-
@BeforeClass public static void setup() throws Exception {
- new File(System.getProperty("build.webapps", "build/webapps") + "/test"
- ).mkdirs();
- Configuration conf = new Configuration();
- // Set the maximum threads
- conf.setInt(HttpServer.HTTP_MAX_THREADS, MAX_THREADS);
- server = new HttpServer("test", "0.0.0.0", 0, true, conf);
+ server = createTestServer();
server.addServlet("echo", "/echo", EchoServlet.class);
server.addServlet("echomap", "/echomap", EchoMapServlet.class);
server.start();
- int port = server.getPort();
- baseUrl = new URL("http://localhost:" + port + "/");
+ baseUrl = getServerURL(server);
}
@AfterClass public static void cleanup() throws Exception {
diff --git a/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java b/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
index 861f44ed8b..a205bf8519 100644
--- a/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
+++ b/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
@@ -17,46 +17,9 @@
*/
package org.apache.hadoop.http;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import java.io.File;
-
-public class TestHttpServerLifecycle {
-
-
- /**
- * Create but do not start the server
- * @return the server instance in the member variable "server"
- * @throws Exception on any failure
- */
- private HttpServer createServer() throws Exception {
- new File(System.getProperty("build.webapps", "build/webapps") + "/test"
- ).mkdirs();
- HttpServer server = new HttpServer("test", "0.0.0.0", 0, true);
- return server;
- }
-
- /**
- * Create and start the server
- * @return the newly started server
- * @throws Exception on any failure
- */
- private HttpServer createAndStartServer() throws Exception {
- HttpServer server = createServer();
- server.start();
- return server;
- }
-
- /**
- * If the server is non null, stop it
- * @throws Exception on any failure
- */
- private void stop(HttpServer server) throws Exception {
- if (server != null) {
- server.stop();
- }
- }
+public class TestHttpServerLifecycle extends HttpServerFunctionalTest {
/**
* Check that a server is alive by probing the {@link HttpServer#isAlive()} method
@@ -79,12 +42,12 @@ private void assertNotLive(HttpServer server) {
* @throws Throwable on failure
*/
@Test public void testCreatedServerIsNotAlive() throws Throwable {
- HttpServer server = createServer();
+ HttpServer server = createTestServer();
assertNotLive(server);
}
@Test public void testStopUnstartedServer() throws Throwable {
- HttpServer server = createServer();
+ HttpServer server = createTestServer();
stop(server);
}
@@ -96,7 +59,7 @@ private void assertNotLive(HttpServer server) {
@Test public void testStartedServerIsAlive() throws Throwable {
HttpServer server = null;
try {
- server = createServer();
+ server = createTestServer();
assertNotLive(server);
server.start();
assertAlive(server);
@@ -122,7 +85,7 @@ private void assertToStringContains(HttpServer server, String text) {
* @throws Throwable on failure
*/
@Test public void testStoppedServerIsNotAlive() throws Throwable {
- HttpServer server = createAndStartServer();
+ HttpServer server = createAndStartTestServer();
assertAlive(server);
stop(server);
assertNotLive(server);
@@ -134,7 +97,7 @@ private void assertToStringContains(HttpServer server, String text) {
* @throws Throwable on failure
*/
@Test public void testStoppingTwiceServerIsAllowed() throws Throwable {
- HttpServer server = createAndStartServer();
+ HttpServer server = createAndStartTestServer();
assertAlive(server);
stop(server);
assertNotLive(server);
diff --git a/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java b/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java
new file mode 100644
index 0000000000..c3ae6cef2f
--- /dev/null
+++ b/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.http;
+
+
+import org.junit.Test;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import java.io.FileNotFoundException;
+
+/**
+ * Test webapp loading
+ */
+public class TestHttpServerWebapps extends HttpServerFunctionalTest {
+ private static final Log log = LogFactory.getLog(TestHttpServerWebapps.class);
+
+ /**
+ * Test that the test server is loadable on the classpath
+ * @throws Throwable if something went wrong
+ */
+ @Test
+ public void testValidServerResource() throws Throwable {
+ HttpServer server = null;
+ try {
+ server = createServer("test");
+ } finally {
+ stop(server);
+ }
+ }
+
+ /**
+ * Test that an invalid webapp triggers an exception
+ * @throws Throwable if something went wrong
+ */
+ @Test
+ public void testMissingServerResource() throws Throwable {
+ try {
+ HttpServer server = createServer("NoSuchWebapp");
+ //should not have got here.
+ //close the server
+ String serverDescription = server.toString();
+ stop(server);
+ fail("Expected an exception, got " + serverDescription);
+ } catch (FileNotFoundException expected) {
+ log.debug("Expected exception " + expected, expected);
+ }
+ }
+
+}
diff --git a/src/test/core/org/apache/hadoop/http/TestServletFilter.java b/src/test/core/org/apache/hadoop/http/TestServletFilter.java
index 73073f7627..6cd21beb1b 100644
--- a/src/test/core/org/apache/hadoop/http/TestServletFilter.java
+++ b/src/test/core/org/apache/hadoop/http/TestServletFilter.java
@@ -35,8 +35,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
-public class TestServletFilter extends junit.framework.TestCase {
+public class TestServletFilter extends HttpServerFunctionalTest {
static final Log LOG = LogFactory.getLog(HttpServer.class);
static volatile String uri = null;
@@ -93,13 +94,14 @@ static void access(String urlstring) throws IOException {
}
}
+ @Test
public void testServletFilter() throws Exception {
Configuration conf = new Configuration();
//start a http server with CountingFilter
conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY,
SimpleFilter.Initializer.class.getName());
- HttpServer http = new HttpServer("..", "localhost", 0, true, conf);
+ HttpServer http = createTestServer(conf);
http.start();
final String fsckURL = "/fsck";