hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r544654 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio: mockup/SimpleThreadPoolExecutor.java protocol/TestNIOHttp.java
Date Tue, 05 Jun 2007 22:05:05 GMT
Author: olegk
Date: Tue Jun  5 15:05:04 2007
New Revision: 544654

URL: http://svn.apache.org/viewvc?view=rev&rev=544654
Log:
Added test setup decorators to the TestNIOHttp test suite to exercise both buffering and throttling
HTTP service handlers

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/SimpleThreadPoolExecutor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/SimpleThreadPoolExecutor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/SimpleThreadPoolExecutor.java?view=diff&rev=544654&r1=544653&r2=544654
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/SimpleThreadPoolExecutor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/SimpleThreadPoolExecutor.java
Tue Jun  5 15:05:04 2007
@@ -119,7 +119,7 @@
         
         public Thread lease() {
             if (this.shutdown) {
-                throw new IllegalArgumentException("Thread pool shut down");
+                throw new IllegalStateException("Thread pool shut down");
             }
             synchronized (this) {
                 if (!this.available.isEmpty()) {
@@ -133,9 +133,6 @@
         }
         
         public void release(final Thread t) {
-            if (this.shutdown) {
-                throw new IllegalArgumentException("Thread pool shut down");
-            }
             synchronized (this) {
                 if (this.leased.contains(t)) {
                     this.leased.remove(t);
@@ -212,7 +209,6 @@
                 }
             } catch (InterruptedException ex) {
             } finally {
-                System.err.println(this + ": terminate");
                 this.pool.remove(this);
             }
         }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java?view=diff&rev=544654&r1=544653&r2=544654
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java
Tue Jun  5 15:05:04 2007
@@ -35,9 +35,11 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.Random;
 
+import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -61,6 +63,7 @@
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.mockup.CountingEventListener;
 import org.apache.http.nio.mockup.SimpleHttpRequestHandlerResolver;
+import org.apache.http.nio.mockup.SimpleThreadPoolExecutor;
 import org.apache.http.nio.mockup.TestHttpClient;
 import org.apache.http.nio.mockup.TestHttpServer;
 import org.apache.http.params.BasicHttpParams;
@@ -93,25 +96,74 @@
  */
 public class TestNIOHttp extends TestCase {
 
+    private static final int MODE_BUFFERING    = 0;
+    private static final int MODE_THROTTLING   = 1;
+    
+    private int clientMode = MODE_BUFFERING;
+    private int serverMode = MODE_BUFFERING;
+    
     // ------------------------------------------------------------ Constructor
     public TestNIOHttp(String testName) {
         super(testName);
     }
 
+    public int getClientMode() {
+        return this.clientMode;
+    }
+
+    public void setClientMode(int clientMode) {
+        this.clientMode = clientMode;
+    }
+
+    public int getServerMode() {
+        return this.serverMode;
+    }
+
+    public void setServerMode(int serverMode) {
+        this.serverMode = serverMode;
+    }
+
     // ------------------------------------------------------------------- Main
     public static void main(String args[]) {
         String[] testCaseName = { TestNIOHttp.class.getName() };
         junit.textui.TestRunner.main(testCaseName);
     }
 
+    static class ServerModeDecorator extends TestSetup {
+
+        private int mode;
+        
+        public ServerModeDecorator(final TestNIOHttp test, int mode) {
+            super(test);
+            this.mode = mode;
+        }
+                
+        protected void setUp() throws Exception {
+            TestNIOHttp testcase = (TestNIOHttp)getTest();
+            testcase.setServerMode(this.mode);
+        }  
+    }
+    
     // ------------------------------------------------------- TestCase Methods
 
     public static Test suite() {
-        return new TestSuite(TestNIOHttp.class);
+        TestSuite source = new TestSuite(TestNIOHttp.class);
+        
+        TestSuite suite = new TestSuite();
+        for (Enumeration en = source.tests(); en.hasMoreElements(); ) {
+            TestNIOHttp test = (TestNIOHttp) en.nextElement();
+            suite.addTest(new ServerModeDecorator(test, MODE_BUFFERING));            
+        }
+        for (Enumeration en = source.tests(); en.hasMoreElements(); ) {
+            TestNIOHttp test = (TestNIOHttp) en.nextElement();
+            suite.addTest(new ServerModeDecorator(test, MODE_THROTTLING));            
+        }
+        return suite;
     }
 
     private TestHttpServer server;
     private TestHttpClient client;
+    private SimpleThreadPoolExecutor executor;
     
     protected void setUp() throws Exception {
         HttpParams serverParams = new BasicHttpParams();
@@ -134,9 +186,11 @@
             .setParameter(HttpProtocolParams.USER_AGENT, "TEST-CLIENT/1.1");
         
         this.client = new TestHttpClient(clientParams);
+        this.executor = new SimpleThreadPoolExecutor();
     }
 
     protected void tearDown() throws Exception {
+        this.executor.shutdown();
         this.server.shutdown();
         this.client.shutdown();
     }
@@ -151,18 +205,36 @@
         httpproc.addInterceptor(new ResponseContent());
         httpproc.addInterceptor(new ResponseConnControl());
 
-        BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
-                httpproc,
-                new DefaultHttpResponseFactory(),
-                new DefaultConnectionReuseStrategy(),
-                this.server.getParams());
-
-        serviceHandler.setHandlerResolver(
-                new SimpleHttpRequestHandlerResolver(requestHandler));
-        serviceHandler.setExpectationVerifier(expectationVerifier);
-        serviceHandler.setEventListener(eventListener);
-        
-        return serviceHandler;
+        if (this.serverMode == MODE_BUFFERING) {
+            BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
+                    httpproc,
+                    new DefaultHttpResponseFactory(),
+                    new DefaultConnectionReuseStrategy(),
+                    this.server.getParams());
+
+            serviceHandler.setHandlerResolver(
+                    new SimpleHttpRequestHandlerResolver(requestHandler));
+            serviceHandler.setExpectationVerifier(expectationVerifier);
+            serviceHandler.setEventListener(eventListener);
+            
+            return serviceHandler;
+        }
+        if (this.serverMode == MODE_THROTTLING) {
+            ThrottlingHttpServiceHandler serviceHandler = new ThrottlingHttpServiceHandler(
+                    httpproc,
+                    new DefaultHttpResponseFactory(),
+                    new DefaultConnectionReuseStrategy(),
+                    this.executor,
+                    this.server.getParams());
+
+            serviceHandler.setHandlerResolver(
+                    new SimpleHttpRequestHandlerResolver(requestHandler));
+            serviceHandler.setExpectationVerifier(expectationVerifier);
+            serviceHandler.setEventListener(eventListener);
+            
+            return serviceHandler;
+        }
+        throw new IllegalStateException();
     }
     
     private NHttpClientHandler createHttpClientHandler(



Mime
View raw message