abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r429853 - in /incubator/abdera/java/trunk: build/build.xml client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java dependencies/deps.properties
Date Tue, 08 Aug 2006 22:14:42 GMT
Author: rooneg
Date: Tue Aug  8 15:14:41 2006
New Revision: 429853

URL: http://svn.apache.org/viewvc?rev=429853&view=rev
Log:
Make the new cache tests use an embedded Jetty server instead of hitting
Mark Nottingham's web site.  This defaults to port 8080, but that can be
overridden via a property.

* build/build.xml: Add the new Jetty stuff, and build the client tests.

* dependencies/deps.properties: Add Jetty jars/urls.

* client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java
  Import a bunch of Jetty and Servlet classes.
  Update javadoc.
  (PORT_PROP, PORT): New fields.
  (CHECK_CACHE_INVALIDATE): Remove initial setting.
  (static): Initialize PORT and CHECK_CACHE_INVALIDATE.
  (setUp): Lazily set up our Jetty server.
  (Servlet): A trivial little servlet that handles our server side work.

Modified:
    incubator/abdera/java/trunk/build/build.xml
    incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java
    incubator/abdera/java/trunk/dependencies/deps.properties

Modified: incubator/abdera/java/trunk/build/build.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/build.xml?rev=429853&r1=429852&r2=429853&view=diff
==============================================================================
--- incubator/abdera/java/trunk/build/build.xml (original)
+++ incubator/abdera/java/trunk/build/build.xml Tue Aug  8 15:14:41 2006
@@ -66,6 +66,7 @@
   <property name="client" value="${basedir}/client" />
   <property name="client.src" value="${client}/src/main/java" />
   <property name="client.work" value="${work}/client" />
+  <property name="client.test.java" value="${client}/src/test/java" />
   <property name="client.jar" value="${dist}/${ant.project.name}.client.${version}.jar"
/>
   
   <property environment="env" />
@@ -129,6 +130,8 @@
           <available file="${dependencies}/${commons.httpclient.jar}" />
           <available file="${dependencies}/${junit.jar}" />
           <available file="${dependencies}/${wstx.jar}" />
+          <available file="${dependencies}/${jetty.jar}" />
+          <available file="${dependencies}/${jetty-util.jar}" />
         </and>
       </not>
     </condition>
@@ -265,6 +268,10 @@
            destdir="${client.work}"
            classpathref="jar.dependencies"
            classpath="${core.work}" />
+    <javac srcdir="${client.test.java}"
+           destdir="${test}"
+           classpathref="jar.dependencies"
+           classpath="${core.work};${parser.work};${extensions.work};${client.work}" />
     <mkdir dir="${client.work}/META-INF" />
     <copy todir="${client.work}/META-INF">
       <fileset dir="${basedir}">
@@ -451,6 +458,12 @@
            usetimestamp="true" />
       <get src="${wstx.dir}/${wstx.jar}"
            dest="${dependencies}/${wstx.jar}"
+           usetimestamp="true" />
+      <get src="${jetty.dir}/${jetty.jar}"
+           dest="${dependencies}/${jetty.jar}"
+           usetimestamp="true" />
+      <get src="${jetty-util.dir}/${jetty-util.jar}"
+           dest="${dependencies}/${jetty-util.jar}"
            usetimestamp="true" />
     </parallel>
   </target>

Modified: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java?rev=429853&r1=429852&r2=429853&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java
(original)
+++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java
Tue Aug  8 15:14:41 2006
@@ -21,6 +21,11 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.servlet.ServletHandler;
+
 import org.apache.abdera.protocol.client.Client;
 import org.apache.abdera.protocol.client.CommonsClient;
 import org.apache.abdera.protocol.client.RequestOptions;
@@ -28,19 +33,79 @@
 
 import junit.framework.TestCase;
 
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+
 /**
- * For now these are hitting Mark Nottingham's set of caching tests.  We'll
- * need to set up our own server.  The hard part about testing caching is
- * that we need a server endpoint to test against.  Also, the test results 
- * can be affected by proxies and intermediate caches.  If we want to run
- * these tests in an offline configuration, we'll need to provide instructions
- * on how to set up a local server and have a portable suite of tests. 
+ * These cache tests were originally based on Mark Nottingham's javascript
+ * cache tests, available at:
+ * 
+ *   http://www.mnot.net/javascript/xmlhttprequest/cache.html
+ * 
+ * They have since been modified to use an embedded Jetty server instead of
+ * going off over the internet to hit Mark's server, since there are too many
+ * things that can get in the way of those sort things (proxies, intermediate
+ * caches, etc) if you try to talk to a remote server.
  */
 public class CacheTests extends TestCase {
+
+  private static final String PORT_PROP = "abdera.test.client.cache.port";
+  private static String CHECK_CACHE_INVALIDATE;
+  private static int PORT;
   
-  private final static String CHECK_CACHE_INVALIDATE = 
-    "http://www.mnot.net/javascript/xmlhttprequest/check_cache_invalidate.s";
-  
+  static {
+    if (System.getProperty(PORT_PROP) != null) {
+      PORT = Integer.parseInt(System.getProperty(PORT_PROP));  
+    } else {
+      PORT = 8080;
+    }
+    
+    CHECK_CACHE_INVALIDATE = "http://localhost:" + PORT + "/";
+  }
+
+  private static Server server;
+
+  protected void setUp() throws Exception {
+    if (server == null) {
+      server = new Server();
+
+      Connector connector = new SocketConnector();
+
+      connector.setPort(PORT);
+
+      server.setConnectors(new Connector[]{connector});
+
+      ServletHandler handler = new ServletHandler();
+
+      server.setHandler(handler);
+
+      handler.addServletWithMapping(
+        "org.apache.abdera.test.client.cache.CacheTests$Servlet",
+        "/"
+      );
+
+      server.start();
+    }
+  }
+
+  public static class Servlet extends HttpServlet {
+    protected void doGet(HttpServletRequest request,
+                         HttpServletResponse response)
+      throws ServletException, IOException
+    {
+      String reqnum = request.getHeader("X-Reqnum");
+
+      response.setContentType("text/plain");
+      response.setStatus(HttpServletResponse.SC_OK);
+      response.setHeader("Cache-Control", "max-age=60");
+      response.setDateHeader("Date", System.currentTimeMillis());
+
+      response.getWriter().println(reqnum);
+    }
+  }
+
   public static void testRequestNoStore() throws Exception {
     
       Client client = new CommonsClient();

Modified: incubator/abdera/java/trunk/dependencies/deps.properties
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/deps.properties?rev=429853&r1=429852&r2=429853&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/deps.properties (original)
+++ incubator/abdera/java/trunk/dependencies/deps.properties Tue Aug  8 15:14:41 2006
@@ -70,4 +70,10 @@
 retroweaver.zip=retroweaver-1.2.3.zip
 
 xmlsecurity.dir=http://www.apache.org/dist/java-repository/xml-security/jars
-xmlsecurity.jar=xmlsec-1.3.0.jar
\ No newline at end of file
+xmlsecurity.jar=xmlsec-1.3.0.jar
+
+jetty.dir=http://www.ibiblio.org/maven2/jetty/jetty/6.0.0rc0
+jetty.jar=jetty-6.0.0rc0.jar
+
+jetty-util.dir=http://www.ibiblio.org/maven2/jetty/jetty-util/6.0.0rc0
+jetty-util.jar=jetty-util-6.0.0rc0.jar



Mime
View raw message