hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r930540 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor: TestDefaultIOReactors.java TestDefaultIOReactorsSSL.java
Date Sat, 03 Apr 2010 16:39:42 GMT
Author: olegk
Date: Sat Apr  3 16:39:42 2010
New Revision: 930540

URL: http://svn.apache.org/viewvc?rev=930540&view=rev
Log:
Improved test case

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

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=930540&r1=930539&r2=930540&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 Apr  3 16:39:42 2010
@@ -33,6 +33,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -102,8 +103,10 @@ public class TestDefaultIOReactors exten
         
         final int connNo = 10;
         final CountDownLatch requestConns = new CountDownLatch(connNo); 
-        final CountDownLatch closedServerConns = new CountDownLatch(connNo); 
-        final CountDownLatch closedClientConns = new CountDownLatch(connNo); 
+        final AtomicInteger closedServerConns = new AtomicInteger(0); 
+        final AtomicInteger openServerConns = new AtomicInteger(0); 
+        final AtomicInteger closedClientConns = new AtomicInteger(0); 
+        final AtomicInteger openClientConns = new AtomicInteger(0); 
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
@@ -146,8 +149,14 @@ public class TestDefaultIOReactors exten
         EventListener serverEventListener = new SimpleEventListener() {
 
             @Override
+            public void connectionOpen(NHttpConnection conn) {
+                openServerConns.incrementAndGet();
+                super.connectionOpen(conn);
+            }
+
+            @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedServerConns.countDown();
+                closedServerConns.incrementAndGet();
                 super.connectionClosed(conn);
             }
             
@@ -174,8 +183,14 @@ public class TestDefaultIOReactors exten
         EventListener clientEventListener = new SimpleEventListener() {
 
             @Override
+            public void connectionOpen(NHttpConnection conn) {
+                openClientConns.incrementAndGet();
+                super.connectionOpen(conn);
+            }
+
+            @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedClientConns.countDown();
+                closedClientConns.incrementAndGet();
                 super.connectionClosed(conn);
             }
             
@@ -231,11 +246,8 @@ public class TestDefaultIOReactors exten
         this.client.shutdown();
         this.server.shutdown();
         
-        closedClientConns.await();
-        assertEquals(0, closedClientConns.getCount());
-     
-        closedServerConns.await();
-        assertEquals(0, closedServerConns.getCount());
+        assertEquals(openClientConns.get(), closedClientConns.get());
+        assertEquals(openServerConns.get(), closedServerConns.get());
     }
     
     public void testRuntimeException() throws Exception {

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=930540&r1=930539&r2=930540&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 Apr  3 16:39:42 2010
@@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
 import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -99,8 +100,10 @@ public class TestDefaultIOReactorsSSL ex
         
         final int connNo = 10;
         final CountDownLatch requestConns = new CountDownLatch(connNo); 
-        final CountDownLatch closedServerConns = new CountDownLatch(connNo); 
-        final CountDownLatch closedClientConns = new CountDownLatch(connNo); 
+        final AtomicInteger closedServerConns = new AtomicInteger(0); 
+        final AtomicInteger openServerConns = new AtomicInteger(0); 
+        final AtomicInteger closedClientConns = new AtomicInteger(0); 
+        final AtomicInteger openClientConns = new AtomicInteger(0); 
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
@@ -143,8 +146,14 @@ public class TestDefaultIOReactorsSSL ex
         EventListener serverEventListener = new SimpleEventListener() {
 
             @Override
+            public void connectionOpen(NHttpConnection conn) {
+                openServerConns.incrementAndGet();
+                super.connectionOpen(conn);
+            }
+
+            @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedServerConns.countDown();
+                closedServerConns.incrementAndGet();
                 super.connectionClosed(conn);
             }
             
@@ -171,8 +180,14 @@ public class TestDefaultIOReactorsSSL ex
         EventListener clientEventListener = new SimpleEventListener() {
 
             @Override
+            public void connectionOpen(NHttpConnection conn) {
+                openClientConns.incrementAndGet();
+                super.connectionOpen(conn);
+            }
+
+            @Override
             public void connectionClosed(NHttpConnection conn) {
-                closedClientConns.countDown();
+                closedClientConns.incrementAndGet();
                 super.connectionClosed(conn);
             }
             
@@ -228,11 +243,8 @@ public class TestDefaultIOReactorsSSL ex
         this.client.shutdown();
         this.server.shutdown();
         
-        closedClientConns.await();
-        assertEquals(0, closedClientConns.getCount());
-     
-        closedServerConns.await();
-        assertEquals(0, closedServerConns.getCount());
+        assertEquals(openClientConns.get(), closedClientConns.get());
+        assertEquals(openServerConns.get(), closedServerConns.get());
     }
 
 }



Mime
View raw message