Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 1569 invoked from network); 2 Jun 2010 15:44:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Jun 2010 15:44:15 -0000 Received: (qmail 54757 invoked by uid 500); 2 Jun 2010 15:44:15 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 54725 invoked by uid 500); 2 Jun 2010 15:44:14 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 54718 invoked by uid 99); 2 Jun 2010 15:44:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jun 2010 15:44:13 +0000 X-ASF-Spam-Status: No, hits=-1635.0 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jun 2010 15:44:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A98B22388978; Wed, 2 Jun 2010 15:43:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r950605 - in /hadoop/common/trunk: ./ src/java/org/apache/hadoop/http/ src/test/core/org/apache/hadoop/http/ Date: Wed, 02 Jun 2010 15:43:51 -0000 To: common-commits@hadoop.apache.org From: tomwhite@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100602154351.A98B22388978@eris.apache.org> Author: tomwhite Date: Wed Jun 2 15:43:51 2010 New Revision: 950605 URL: http://svn.apache.org/viewvc?rev=950605&view=rev Log: HADOOP-6461. Webapps aren't located correctly post-split. Contributed by Todd Lipcon and Steve Loughran. Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/HttpServerFunctionalTest.java (with props) hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java (with props) Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/build.xml hadoop/common/trunk/src/java/org/apache/hadoop/http/HttpServer.java hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServer.java hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestServletFilter.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Wed Jun 2 15:43:51 2010 @@ -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 Modified: hadoop/common/trunk/build.xml URL: http://svn.apache.org/viewvc/hadoop/common/trunk/build.xml?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/build.xml (original) +++ hadoop/common/trunk/build.xml Wed Jun 2 15:43:51 2010 @@ -79,6 +79,7 @@ + @@ -630,6 +631,8 @@ + + 0) { + out.append(new String(buffer, 0, len)); + len = in.read(buffer); + } + return out.toString(); + } +} Propchange: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/HttpServerFunctionalTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java Wed Jun 2 15:43:51 2010 @@ -36,8 +36,9 @@ import javax.servlet.http.HttpServletReq 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 @@ public class TestGlobalFilter extends ju } } + @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"; Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServer.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServer.java?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServer.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServer.java Wed Jun 2 15:43:51 2010 @@ -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 javax.servlet.http.HttpServletRes 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 class TestHttpServer { } } - 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 { Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java Wed Jun 2 15:43:51 2010 @@ -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 @@ public class TestHttpServerLifecycle { * @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 @@ public class TestHttpServerLifecycle { @Test public void testStartedServerIsAlive() throws Throwable { HttpServer server = null; try { - server = createServer(); + server = createTestServer(); assertNotLive(server); server.start(); assertAlive(server); @@ -122,7 +85,7 @@ public class TestHttpServerLifecycle { * @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 @@ public class TestHttpServerLifecycle { * @throws Throwable on failure */ @Test public void testStoppingTwiceServerIsAllowed() throws Throwable { - HttpServer server = createAndStartServer(); + HttpServer server = createAndStartTestServer(); assertAlive(server); stop(server); assertNotLive(server); Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java?rev=950605&view=auto ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java (added) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java Wed Jun 2 15:43:51 2010 @@ -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); + } + } + +} Propchange: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestServletFilter.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestServletFilter.java?rev=950605&r1=950604&r2=950605&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestServletFilter.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestServletFilter.java Wed Jun 2 15:43:51 2010 @@ -35,8 +35,9 @@ import javax.servlet.http.HttpServletReq 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 @@ public class TestServletFilter extends j } } + @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";