hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1172673 - /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
Date Mon, 19 Sep 2011 15:42:23 GMT
Author: olegk
Date: Mon Sep 19 15:42:23 2011
New Revision: 1172673

URL: http://svn.apache.org/viewvc?rev=1172673&view=rev
Log:
Fixed possible race condition in the #testGracefulShutdown test case

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.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=1172673&r1=1172672&r2=1172673&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
Mon Sep 19 15:42:23 2011
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.http.HttpCoreNIOTestBase;
@@ -104,10 +105,10 @@ public class TestDefaultIOReactors exten
     @Test
     public void testGracefulShutdown() throws Exception {
         final int connNo = 10;
-        final AtomicInteger closedServerConns = new AtomicInteger(0);
-        final AtomicInteger openServerConns = new AtomicInteger(0);
+        final CountDownLatch openServerConns = new CountDownLatch(connNo);
+        final CountDownLatch openClientConns = new CountDownLatch(connNo);
         final AtomicInteger closedClientConns = new AtomicInteger(0);
-        final AtomicInteger openClientConns = new AtomicInteger(0);
+        final AtomicInteger closedServerConns = new AtomicInteger(0);
 
         this.connpool.setDefaultMaxPerRoute(connNo);
         this.connpool.setMaxTotal(connNo);
@@ -121,7 +122,7 @@ public class TestDefaultIOReactors exten
 
             @Override
             public void connected(final NHttpServerConnection conn) {
-                openServerConns.incrementAndGet();
+                openServerConns.countDown();
                 super.connected(conn);
             }
 
@@ -136,7 +137,7 @@ public class TestDefaultIOReactors exten
 
             @Override
             public void connected(final NHttpClientConnection conn, final Object attachment)
{
-                openClientConns.incrementAndGet();
+                openClientConns.countDown();
                 super.connected(conn, attachment);
             }
 
@@ -170,13 +171,15 @@ public class TestDefaultIOReactors exten
 
         Assert.assertEquals("Test client status", IOReactorStatus.ACTIVE, this.client.getStatus());
 
+        openClientConns.await(15, TimeUnit.SECONDS);
+        openServerConns.await(15, TimeUnit.SECONDS);
+        
         this.connpool.shutdown(2000);
         this.client.shutdown();
         this.server.shutdown();
 
-        Assert.assertEquals("Client connections that should have been opened", connNo, openClientConns.get());
-        Assert.assertEquals("Client connections that should have been closed", openClientConns.get(),
closedClientConns.get());
-        Assert.assertEquals("Server connections that should have been closed", openServerConns.get(),
closedServerConns.get());
+        Assert.assertEquals("Client connections that should have been closed", connNo, closedClientConns.get());
+        Assert.assertEquals("Server connections that should have been closed", connNo, closedServerConns.get());
     }
 
     @Test



Mime
View raw message