activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1177338 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java
Date Thu, 29 Sep 2011 15:38:15 GMT
Author: tabish
Date: Thu Sep 29 15:38:15 2011
New Revision: 1177338

URL: http://svn.apache.org/viewvc?rev=1177338&view=rev
Log:
Make the test work without relying on a sleep statement to get the results needed.

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java?rev=1177338&r1=1177337&r2=1177338&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java
Thu Sep 29 15:38:15 2011
@@ -26,50 +26,52 @@ import javax.net.ServerSocketFactory;
 import junit.framework.TestCase;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.util.Wait;
 
 public class SlowConnectionTest extends TestCase {
-        
+
     public void testSlowConnection() throws Exception {
-        
+
         int timeout = 1000;
         URI tcpUri = new URI("tcp://localhost:61616?soTimeout=" + timeout + "&trace=true&connectionTimeout="
+ timeout + "&wireFormat.maxInactivityDurationInitalDelay=" + timeout);
-        
+
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri
+ ")");
         final Connection connection = cf.createConnection();
-        
+
         MockBroker broker = new MockBroker();
         broker.start();
-        
+
         new Thread(new Runnable() {
             public void run() {
                 try { connection.start(); } catch (Throwable ignored) {}
             }
         }).start();
-        
-        Thread.sleep(timeout * 5);
-        
+
         int count = 0;
-        for (Thread thread : Thread.getAllStackTraces().keySet()) {
-            if (thread.getName().contains("ActiveMQ Transport")) { count++; }
-        }
-        
+        assertTrue("Transport count: " + count + ", expected <= 1", Wait.waitFor(new Wait.Condition(){
+            public boolean isSatisified() throws Exception {
+                int count = 0;
+                for (Thread thread : Thread.getAllStackTraces().keySet()) {
+                    if (thread.getName().contains("ActiveMQ Transport")) { count++; }
+                }
+                return count == 1;
+        }}));
+
         broker.interrupt();
         broker.join();
-        
-        assertTrue("Transport count: " + count + ", expected <= 1", count <= 1);  
     
-    }   
-    
+    }
+
     class MockBroker extends Thread {
-        
+
         public void run() {
-            
+
             List<Socket> inProgress = new ArrayList<Socket>();
             ServerSocketFactory factory = ServerSocketFactory.getDefault();
             ServerSocket ss = null;
-            
+
             try {
                 ss = factory.createServerSocket(61616);
-                
+
                 while (!interrupted()) {
                     inProgress.add(ss.accept());    // eat socket
                 }
@@ -77,10 +79,10 @@ public class SlowConnectionTest extends 
                 e.printStackTrace();
             } finally {
                 try { ss.close(); } catch (IOException ignored) {}
-                for (Socket s : inProgress) {               
+                for (Socket s : inProgress) {
                     try { s.close(); } catch (IOException ignored) {}
-                }               
-            }           
+                }
+            }
         }
     }
 }



Mime
View raw message