make test more tolerant to slower machines, resolve intermittent failure

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@798852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2009-07-29 10:46:38 +00:00
parent 6f3c99991d
commit 763e331318
2 changed files with 12 additions and 6 deletions

View File

@ -26,6 +26,7 @@ import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.Message; import org.apache.activemq.command.Message;
import org.apache.activemq.command.ProducerInfo; import org.apache.activemq.command.ProducerInfo;
import org.apache.activemq.command.SessionInfo; import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.util.Wait;
public class DemandForwardingBridgeTest extends NetworkTestSupport { public class DemandForwardingBridgeTest extends NetworkTestSupport {
@ -53,7 +54,7 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
destination = createDestinationInfo(connection1, connectionInfo1, destinationType); destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
// Start a consumer on a remote broker // Start a consumer on a remote broker
StubConnection connection2 = createRemoteConnection(); final StubConnection connection2 = createRemoteConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo(); ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2); SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
connection2.send(connectionInfo2); connection2.send(connectionInfo2);
@ -73,11 +74,14 @@ public class DemandForwardingBridgeTest extends NetworkTestSupport {
// Now create remote consumer that should cause message to move to this // Now create remote consumer that should cause message to move to this
// remote consumer. // remote consumer.
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination); ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
connection2.send(consumerInfo2); connection2.request(consumerInfo2);
// Make sure the message was delivered via the remote. // Make sure the message was delivered via the remote.
m = receiveMessage(connection2); assertTrue("message was received", Wait.waitFor(new Wait.Condition() {
assertNotNull(m); public boolean isSatisified() throws Exception {
return receiveMessage(connection2) != null;
}
}));
} }
public void initCombosForTestAddConsumerThenSend() { public void initCombosForTestAddConsumerThenSend() {

View File

@ -32,9 +32,11 @@ public class Wait {
public static boolean waitFor(final Condition condition, final long duration) throws Exception { public static boolean waitFor(final Condition condition, final long duration) throws Exception {
final long expiry = System.currentTimeMillis() + duration; final long expiry = System.currentTimeMillis() + duration;
while (!condition.isSatisified() && System.currentTimeMillis() < expiry) { boolean conditionSatisified = condition.isSatisified();
while (!conditionSatisified && System.currentTimeMillis() < expiry) {
Thread.sleep(1000); Thread.sleep(1000);
conditionSatisified = condition.isSatisified();
} }
return condition.isSatisified(); return conditionSatisified;
} }
} }