diff options
author | Martin Ritchie <ritchiem@apache.org> | 2009-02-13 15:12:14 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2009-02-13 15:12:14 +0000 |
commit | 53af5c535c9bc90d803393009ac1bf01efd38eac (patch) | |
tree | abc6220c060f1d0aea799f1feb6306e4dcabcc83 | |
parent | a8874f55a3b17ac94f38e6697bdb4bed72e7ee6c (diff) | |
download | qpid-python-53af5c535c9bc90d803393009ac1bf01efd38eac.tar.gz |
QPID-1662 : Converted Thread.sleep in to an awaitNanos()
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@744141 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java index 834222fcc2..289ca0b1b0 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java @@ -36,6 +36,8 @@ import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; import org.apache.qpid.test.utils.QpidTestCase; +import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.locks.Condition; public class TimeToLiveTest extends QpidTestCase { @@ -88,13 +90,29 @@ public class TimeToLiveTest extends QpidTestCase producer.send(nextMessage(String.valueOf(msg), false, producerSession, producer)); consumer = clientSession.createConsumer(queue); - try - { - // Sleep to ensure TTL reached - Thread.sleep(TIME_TO_LIVE); - } - catch (InterruptedException e) + + // Ensure we sleep the required amount of time. + ReentrantLock waitLock = new ReentrantLock(); + Condition wait = waitLock.newCondition(); + final long MILLIS = 1000000L; + long waitTime = TIME_TO_LIVE * MILLIS; + while (waitTime > 0) { + try + { + waitLock.lock(); + + waitTime = wait.awaitNanos(waitTime); + } + catch (InterruptedException e) + { + //Stop if we are interrupted + fail(e.getMessage()); + } + finally + { + waitLock.unlock(); + } } |