mirror of https://github.com/apache/activemq.git
Use a Wait condition instead of sleeps to detect completion.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1177411 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad76330eed
commit
1878e951c6
|
@ -37,12 +37,10 @@ import org.apache.activemq.command.ActiveMQQueue;
|
|||
import org.apache.activemq.transport.TransportListener;
|
||||
import org.apache.activemq.transport.mock.MockTransport;
|
||||
import org.apache.activemq.util.ServiceStopper;
|
||||
import org.apache.activemq.util.Wait;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ReconnectTest extends TestCase {
|
||||
|
||||
public static final int MESSAGES_PER_ITTERATION = 10;
|
||||
|
@ -153,13 +151,11 @@ public class ReconnectTest extends TestCase {
|
|||
fail("Worker " + name + " got Exception: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testReconnects() throws Exception {
|
||||
|
||||
for (int k = 1; k < 10; k++) {
|
||||
|
||||
LOG.info("Test run: " + k);
|
||||
|
||||
// Wait for at least one iteration to occur...
|
||||
|
@ -185,26 +181,20 @@ public class ReconnectTest extends TestCase {
|
|||
workers[i].failConnection();
|
||||
}
|
||||
|
||||
long start;
|
||||
// Wait for the connections to get interrupted...
|
||||
start = System.currentTimeMillis();
|
||||
while (interruptedCount.get() < WORKER_COUNT) {
|
||||
if( System.currentTimeMillis()-start > 1000*60 ) {
|
||||
fail("Timed out waiting for all connections to be interrupted.");
|
||||
}
|
||||
LOG.info("Test run "+k+": Waiting for connections to get interrupted.. at: " + interruptedCount.get());
|
||||
Thread.sleep(1000);
|
||||
assertTrue("Timed out waiting for all connections to be interrupted.", Wait.waitFor(new Wait.Condition(){
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Test run waiting for connections to get interrupted.. at: " + interruptedCount.get());
|
||||
return interruptedCount.get() == WORKER_COUNT;
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(60)));
|
||||
|
||||
// Wait for the connections to re-establish...
|
||||
start = System.currentTimeMillis();
|
||||
while (resumedCount.get() < WORKER_COUNT) {
|
||||
if( System.currentTimeMillis()-start > 1000*60 ) {
|
||||
fail("Timed out waiting for all connections to be resumed.");
|
||||
}
|
||||
LOG.info("Test run "+k+": Waiting for connections to get resumed.. at: " + resumedCount.get());
|
||||
Thread.sleep(1000);
|
||||
assertTrue("Timed out waiting for all connections to be resumed.", Wait.waitFor(new Wait.Condition(){
|
||||
public boolean isSatisified() throws Exception {
|
||||
LOG.debug("Test run waiting for connections to get resumed.. at: " + resumedCount.get());
|
||||
return resumedCount.get() >= WORKER_COUNT;
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(60)));
|
||||
|
||||
// Reset the counters..
|
||||
interruptedCount.set(0);
|
||||
|
@ -214,9 +204,7 @@ public class ReconnectTest extends TestCase {
|
|||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -227,13 +215,11 @@ public class ReconnectTest extends TestCase {
|
|||
TransportConnector connector = bs.addConnector("tcp://localhost:0");
|
||||
bs.start();
|
||||
tcpUri = connector.getConnectUri();
|
||||
|
||||
workers = new Worker[WORKER_COUNT];
|
||||
for (int i = 0; i < WORKER_COUNT; i++) {
|
||||
workers[i] = new Worker("" + i);
|
||||
workers[i].start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -243,5 +229,4 @@ public class ReconnectTest extends TestCase {
|
|||
}
|
||||
new ServiceStopper().stop(bs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue