From 5ec818183416dfabda752afdae59497a002bcafc Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Fri, 13 Feb 2009 15:12:14 +0000 Subject: QPID-1662 : Converted Thread.sleep in to an awaitNanos() git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@744141 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/server/queue/TimeToLiveTest.java | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'java') diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java b/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java index 834222fcc2..289ca0b1b0 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/queue/TimeToLiveTest.java +++ b/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(); + } } -- cgit v1.2.1