hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r950606 - in /hadoop/common/branches/branch-0.21: ./ src/java/org/apache/hadoop/http/ src/test/core/org/apache/hadoop/http/
Date Wed, 02 Jun 2010 15:45:30 GMT
Author: tomwhite
Date: Wed Jun  2 15:45:29 2010
New Revision: 950606

URL: http://svn.apache.org/viewvc?rev=950606&view=rev
Log:
Merge -r 950604:950605 from trunk to 0.21 branch. Fixes: HADOOP-6461

Added:
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/HttpServerFunctionalTest.java
      - copied unchanged from r950605, hadoop/common/trunk/src/test/core/org/apache/hadoop/http/HttpServerFunctionalTest.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java
      - copied unchanged from r950605, hadoop/common/trunk/src/test/core/org/apache/hadoop/http/TestHttpServerWebapps.java
Modified:
    hadoop/common/branches/branch-0.21/CHANGES.txt
    hadoop/common/branches/branch-0.21/build.xml
    hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/http/HttpServer.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServer.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestServletFilter.java

Modified: hadoop/common/branches/branch-0.21/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/CHANGES.txt?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.21/CHANGES.txt Wed Jun  2 15:45:29 2010
@@ -1548,6 +1548,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/branches/branch-0.21/build.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/build.xml?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/build.xml (original)
+++ hadoop/common/branches/branch-0.21/build.xml Wed Jun  2 15:45:29 2010
@@ -79,6 +79,7 @@
   <property name="test.build.extraconf" value="${test.build.dir}/extraconf"/>
   <property name="test.build.javadoc" value="${test.build.dir}/docs/api"/>
   <property name="test.build.javadoc.dev" value="${test.build.dir}/docs/dev-api"/>
+  <property name="test.build.webapps" value="${build.dir}/webapps"/>
   <property name="test.include" value="Test*"/>
   <property name="test.classpath.id" value="test.classpath"/>
   <property name="test.output" value="no"/>
@@ -630,6 +631,8 @@
       <delete file="${test.build.dir}/testsfailed"/>
       <delete dir="@{test.dir}/data" />
       <mkdir dir="@{test.dir}/data" />
+      <delete dir="${test.build.webapps}"/>
+      <mkdir dir="${test.build.webapps}/test" />
       <delete dir="@{test.dir}/logs" />
       <mkdir dir="@{test.dir}/logs" />
       <copy file="${test.src.dir}/hadoop-policy.xml"

Modified: hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/http/HttpServer.java?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/http/HttpServer.java (original)
+++ hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/http/HttpServer.java Wed
Jun  2 15:45:29 2010
@@ -19,6 +19,7 @@ package org.apache.hadoop.http;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.FileNotFoundException;
 import java.net.BindException;
 import java.net.InetSocketAddress;
 import java.net.URL;
@@ -129,7 +130,7 @@ public class HttpServer implements Filte
         new QueuedThreadPool() : new QueuedThreadPool(maxThreads);
     webServer.setThreadPool(threadPool);
 
-    final String appDir = getWebAppsPath();
+    final String appDir = getWebAppsPath(name);
     ContextHandlerCollection contexts = new ContextHandlerCollection();
     webServer.setHandler(contexts);
 
@@ -364,14 +365,17 @@ public class HttpServer implements Filte
 
   /**
    * Get the pathname to the webapps files.
+   * @param appName eg "secondary" or "datanode"
    * @return the pathname as a URL
-   * @throws IOException if 'webapps' directory cannot be found on CLASSPATH.
+   * @throws FileNotFoundException if 'webapps' directory cannot be found on CLASSPATH.
    */
-  protected String getWebAppsPath() throws IOException {
-    URL url = getClass().getClassLoader().getResource("webapps");
+  private String getWebAppsPath(String appName) throws FileNotFoundException {
+    URL url = getClass().getClassLoader().getResource("webapps/" + appName);
     if (url == null) 
-      throw new IOException("webapps not found in CLASSPATH"); 
-    return url.toString();
+      throw new FileNotFoundException("webapps/" + appName
+          + " not found in CLASSPATH");
+    String urlString = url.toString();
+    return urlString.substring(0, urlString.lastIndexOf('/'));
   }
 
   /**

Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
(original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestGlobalFilter.java
Wed Jun  2 15:45:29 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<String> RECORDS = new TreeSet<String>(); 
 
@@ -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/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServer.java?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServer.java
(original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServer.java
Wed Jun  2 15:45:29 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/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
(original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestHttpServerLifecycle.java
Wed Jun  2 15:45:29 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);

Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestServletFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestServletFilter.java?rev=950606&r1=950605&r2=950606&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestServletFilter.java
(original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/http/TestServletFilter.java
Wed Jun  2 15:45:29 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";



Mime
View raw message