activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1363314 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java
Date Thu, 19 Jul 2012 12:39:17 GMT
Author: gtully
Date: Thu Jul 19 12:39:16 2012
New Revision: 1363314

URL: http://svn.apache.org/viewvc?rev=1363314&view=rev
Log:
allow the sleep time to be specified to allow finer grain return from a wait

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java?rev=1363314&r1=1363313&r2=1363314&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/Wait.java Thu Jul
19 12:39:16 2012
@@ -18,9 +18,12 @@
 package org.apache.activemq.util;
 
 
+import java.util.concurrent.TimeUnit;
+
 public class Wait {
     
     public static final long MAX_WAIT_MILLIS = 30*1000;
+    public static final int SLEEP_MILLIS = 1000;
     
     public interface Condition {
         boolean isSatisified() throws Exception;
@@ -29,12 +32,17 @@ public class Wait {
     public static boolean waitFor(Condition condition) throws Exception {
         return waitFor(condition, MAX_WAIT_MILLIS);
     }
-    
+
     public static boolean waitFor(final Condition condition, final long duration) throws
Exception {
+        return waitFor(condition, MAX_WAIT_MILLIS, SLEEP_MILLIS);
+    }
+
+    public static boolean waitFor(final Condition condition, final long duration, final int
sleepMillis) throws Exception {
+
         final long expiry = System.currentTimeMillis() + duration;
         boolean conditionSatisified = condition.isSatisified();
         while (!conditionSatisified && System.currentTimeMillis() < expiry) {
-            Thread.sleep(1000);
+            TimeUnit.MILLISECONDS.sleep(sleepMillis);
             conditionSatisified = condition.isSatisified();
         }   
         return conditionSatisified;



Mime
View raw message