hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r831535 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http: impl/nio/reactor/ mockup/ nio/protocol/
Date Sat, 31 Oct 2009 12:07:56 GMT
Author: olegk
Date: Sat Oct 31 12:07:56 2009
New Revision: 831535

URL: http://svn.apache.org/viewvc?rev=831535&view=rev
Log:
Better I/O reactor state checks

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
Sat Oct 31 12:07:56 2009
@@ -29,9 +29,10 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -57,6 +58,7 @@
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
@@ -73,9 +75,6 @@
 
 /**
  * Tests for basic I/O functionality.
- *
- * 
- * @version $Id$
  */
 public class TestDefaultIOReactors extends HttpCoreNIOTestBase {
 
@@ -122,6 +121,9 @@
             }
 
             public void finalizeContext(final HttpContext context) {
+                while (requestConns.getCount() > 0) {
+                    requestConns.countDown();
+                }
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
@@ -202,13 +204,28 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
                     null);
+            connRequests.add(sessionRequest);
         }
+        
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
      
-        requestConns.await(10000, TimeUnit.MILLISECONDS);
+        requestConns.await();
         assertEquals(0, requestConns.getCount());
      
         this.client.shutdown();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
Sat Oct 31 12:07:56 2009
@@ -29,6 +29,8 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
+import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
 
 import junit.framework.Test;
@@ -52,6 +54,7 @@
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
@@ -198,15 +201,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        assertEquals(IOReactorStatus.ACTIVE, this.server.getStatus());
-        assertEquals(IOReactorStatus.ACTIVE, this.client.getStatus());
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
         
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
                     null);
+            connRequests.add(sessionRequest);
         }
-     
+        
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+        
         requestConns.await();
         assertEquals(0, requestConns.getCount());
      

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
Sat Oct 31 12:07:56 2009
@@ -38,6 +38,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.HttpParams;
 
 public class TestHttpClient {
@@ -74,8 +75,8 @@
         this.ioReactor.execute(ioEventDispatch);
     }
     
-    public void openConnection(final InetSocketAddress address, final Object attachment)
{
-        this.ioReactor.connect(address, null, attachment, null);
+    public SessionRequest openConnection(final InetSocketAddress address, final Object attachment)
{
+        return this.ioReactor.connect(address, null, attachment, null);
     }
  
     public void start(final NHttpClientHandler clientHandler) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
Sat Oct 31 12:07:56 2009
@@ -45,6 +45,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.HttpParams;
 
 public class TestHttpSSLClient {
@@ -116,8 +117,8 @@
         this.ioReactor.execute(ioEventDispatch);
     }
     
-    public void openConnection(final InetSocketAddress address, final Object attachment)
{
-        this.ioReactor.connect(address, null, attachment, null);
+    public SessionRequest openConnection(final InetSocketAddress address, final Object attachment)
{
+        return this.ioReactor.connect(address, null, attachment, null);
     }
  
     public void start(final NHttpClientHandler clientHandler) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
Sat Oct 31 12:07:56 2009
@@ -30,6 +30,7 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -54,7 +55,9 @@
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpExpectationVerifier;
@@ -73,9 +76,6 @@
 
 /**
  * HttpCore NIO integration tests for async handlers.
- *
- *
- * @version $Id$
  */
 public class TestAsyncNHttpHandlers extends HttpCoreNIOTestBase {
 
@@ -151,12 +151,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();
@@ -382,10 +397,20 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
-        this.client.openConnection(
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        SessionRequest sessionRequest = this.client.openConnection(
                 new InetSocketAddress("localhost", serverAddress.getPort()),
                 queue);
 
+        sessionRequest.waitFor();
+        if (sessionRequest.getException() != null) {
+            throw sessionRequest.getException();
+        }
+        assertNotNull(sessionRequest.getSession());
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < 2; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();
@@ -466,11 +491,26 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
+        }
+
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
         }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
@@ -630,11 +670,26 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
+        }
+
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
         }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
@@ -736,12 +791,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();
@@ -816,12 +886,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
 
@@ -904,12 +989,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBufferingNHttpHandlers.java
Sat Oct 31 12:07:56 2009
@@ -29,6 +29,7 @@
 
 import java.io.UnsupportedEncodingException;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -49,7 +50,9 @@
 import org.apache.http.mockup.SimpleEventListener;
 import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
@@ -67,9 +70,6 @@
 /**
  * HttpCore NIO integration tests using buffering versions of the 
  * protocol handlers.
- *
- *
- * @version $Id$
  */
 public class TestBufferingNHttpHandlers extends HttpCoreNIOTestBase {
 
@@ -145,12 +145,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
Sat Oct 31 12:07:56 2009
@@ -29,6 +29,7 @@
 
 import java.io.UnsupportedEncodingException;
 import java.net.InetSocketAddress;
+import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -51,6 +52,7 @@
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
@@ -66,9 +68,6 @@
 
 /**
  * HttpCore NIO SSL tests.
- *
- * 
- * @version $Id$
  */
 public class TestNIOSSLHttp extends HttpCoreNIOSSLTestBase {
 
@@ -144,15 +143,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
-        assertEquals(IOReactorStatus.ACTIVE, this.server.getStatus());
-        assertEquals(IOReactorStatus.ACTIVE, this.client.getStatus());
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
         
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+        
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java?rev=831535&r1=831534&r2=831535&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandlers.java
Sat Oct 31 12:07:56 2009
@@ -36,6 +36,7 @@
 import java.net.InetSocketAddress;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
@@ -67,7 +68,9 @@
 import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpContext;
@@ -90,9 +93,6 @@
 /**
  * HttpCore NIO integration tests using throttling versions of the 
  * protocol handlers.
- *
- * 
- * @version $Id$
  */
 public class TestThrottlingNHttpHandlers extends HttpCoreNIOTestBase {
 
@@ -184,11 +184,26 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
+        }
+
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
         }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
@@ -398,9 +413,19 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        this.client.openConnection(
-                new InetSocketAddress("localhost", serverAddress.getPort()), 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        SessionRequest sessionRequest = this.client.openConnection(
+                new InetSocketAddress("localhost", serverAddress.getPort()),
                 null);
+
+        sessionRequest.waitFor();
+        if (sessionRequest.getException() != null) {
+            throw sessionRequest.getException();
+        }
+        assertNotNull(sessionRequest.getSession());
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
         
         // wait for the client to invoke finalizeContext().
         synchronized (clientExpectations) {
@@ -567,10 +592,20 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
-        this.client.openConnection(
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        SessionRequest sessionRequest = this.client.openConnection(
                 new InetSocketAddress("localhost", serverAddress.getPort()),
                 queue);
 
+        sessionRequest.waitFor();
+        if (sessionRequest.getException() != null) {
+            throw sessionRequest.getException();
+        }
+        assertNotNull(sessionRequest.getSession());
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < 2; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();
@@ -653,12 +688,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();
@@ -760,11 +810,26 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
+        }
+
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
         }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
@@ -908,12 +973,27 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        
+        Queue<SessionRequest> connRequests = new LinkedList<SessionRequest>();
         for (int i = 0; i < connNo; i++) {
-            this.client.openConnection(
+            SessionRequest sessionRequest = this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),
                     queue);
+            connRequests.add(sessionRequest);
         }
 
+        while (!connRequests.isEmpty()) {
+            SessionRequest sessionRequest = connRequests.remove();
+            sessionRequest.waitFor();
+            if (sessionRequest.getException() != null) {
+                throw sessionRequest.getException();
+            }
+            assertNotNull(sessionRequest.getSession());
+        }
+        
+        assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
+
         for (int i = 0; i < jobs.length; i++) {
             TestJob testjob = jobs[i];
             testjob.waitFor();



Mime
View raw message