Make the test more tolerant of slow machines by replacing fixed length

sleep with a Wait condition.
This commit is contained in:
Timothy Bish 2014-08-18 19:44:50 -04:00
parent aae7aeaf39
commit 858ab40203
1 changed files with 18 additions and 9 deletions

View File

@ -37,6 +37,7 @@ import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -202,15 +203,17 @@ public class AMQ4368Test {
}
@Test
public void testENTMQ220() throws InterruptedException, JMSException {
public void testENTMQ220() throws Exception {
LOG.info("Start test.");
CountDownLatch producer1Started = new CountDownLatch(1);
CountDownLatch producer2Started = new CountDownLatch(1);
CountDownLatch listener1Started = new CountDownLatch(1);
ProducingClient producer1 = new ProducingClient("1", producer1Started);
ProducingClient producer2 = new ProducingClient("2", producer2Started);
ConsumingClient listener1 = new ConsumingClient("subscriber-1", listener1Started);
final ProducingClient producer1 = new ProducingClient("1", producer1Started);
final ProducingClient producer2 = new ProducingClient("2", producer2Started);
final ConsumingClient listener1 = new ConsumingClient("subscriber-1", listener1Started);
final AtomicLong lastSize = new AtomicLong();
try {
producer1.start();
@ -221,13 +224,19 @@ public class AMQ4368Test {
producer2Started.await(15, TimeUnit.SECONDS);
listener1Started.await(15, TimeUnit.SECONDS);
long lastSize = listener1.size.get();
lastSize.set(listener1.size.get());
for (int i = 0; i < 10; i++) {
Thread.sleep(2000);
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return listener1.size.get() > lastSize.get();
}
});
long size = listener1.size.get();
LOG.info("Listener 1: consumed: " + (size - lastSize));
assertTrue("No messages received on iteration: " + i, size > lastSize);
lastSize = size;
LOG.info("Listener 1: consumed: " + (size - lastSize.get()));
assertTrue("No messages received on iteration: " + i, size > lastSize.get());
lastSize.set(size);
}
} finally {
LOG.info("Stopping clients");