servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r405329 - /incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java
Date Tue, 09 May 2006 07:47:13 GMT
Author: gnodet
Date: Tue May  9 00:47:11 2006
New Revision: 405329

URL: http://svn.apache.org/viewcvs?rev=405329&view=rev
Log:
Fix timing issues with ExchangeCompletedListener

Modified:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java?rev=405329&r1=405328&r2=405329&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/ExchangeCompletedListener.java
Tue May  9 00:47:11 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.servicemix.tck;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -26,22 +27,52 @@
 import org.apache.servicemix.jbi.event.ExchangeEvent;
 import org.apache.servicemix.jbi.event.ExchangeListener;
 
-import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
-
 public class ExchangeCompletedListener extends Assert implements ExchangeListener {
 
-    private Map exchanges = new ConcurrentHashMap();
-    
+    private Map exchanges = new HashMap();
+
+    private long timeout;
+
+    public ExchangeCompletedListener() {
+        this(1000);
+    }
+
+    public ExchangeCompletedListener(long timeout) {
+        this.timeout = timeout;
+    }
+
     public void exchangeSent(ExchangeEvent event) {
-        exchanges.put(event.getExchange().getExchangeId(), event.getExchange());
+        synchronized (exchanges) {
+            exchanges.put(event.getExchange().getExchangeId(), event.getExchange());
+            exchanges.notify();
+        }
     }
-    
+
     public void assertExchangeCompleted() throws Exception {
-        Thread.sleep(50);
-        for (Iterator it = exchanges.values().iterator(); it.hasNext();) {
-            MessageExchange me = (MessageExchange) it.next();
-            assertTrue("Exchange is ACTIVE", me.getStatus() != ExchangeStatus.ACTIVE);
+        long start = System.currentTimeMillis();
+        MessageExchange active = null;
+        while (true) {
+            synchronized (exchanges) {
+                for (Iterator it = exchanges.values().iterator(); it.hasNext();) {
+                    active = null;
+                    MessageExchange me = (MessageExchange) it.next();
+                    if (me.getStatus() == ExchangeStatus.ACTIVE) {
+                        active = me;
+                        break;
+                    }
+                }
+                if (active == null) {
+                    break;
+                }
+                long remain = timeout - (System.currentTimeMillis() - start);
+                if (remain < 0) {
+                    assertTrue("Exchange is ACTIVE", active.getStatus() != ExchangeStatus.ACTIVE);
+                } else {
+                    exchanges.wait(remain);
+                }
+            }
         }
+        while (System.currentTimeMillis() - start < 1000);
     }
 
 }



Mime
View raw message