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.TransportListener;
|
||||||
import org.apache.activemq.transport.mock.MockTransport;
|
import org.apache.activemq.transport.mock.MockTransport;
|
||||||
import org.apache.activemq.util.ServiceStopper;
|
import org.apache.activemq.util.ServiceStopper;
|
||||||
|
import org.apache.activemq.util.Wait;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ReconnectTest extends TestCase {
|
public class ReconnectTest extends TestCase {
|
||||||
|
|
||||||
public static final int MESSAGES_PER_ITTERATION = 10;
|
public static final int MESSAGES_PER_ITTERATION = 10;
|
||||||
|
@ -153,13 +151,11 @@ public class ReconnectTest extends TestCase {
|
||||||
fail("Worker " + name + " got Exception: " + error);
|
fail("Worker " + name + " got Exception: " + error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReconnects() throws Exception {
|
public void testReconnects() throws Exception {
|
||||||
|
|
||||||
for (int k = 1; k < 10; k++) {
|
for (int k = 1; k < 10; k++) {
|
||||||
|
|
||||||
LOG.info("Test run: " + k);
|
LOG.info("Test run: " + k);
|
||||||
|
|
||||||
// Wait for at least one iteration to occur...
|
// Wait for at least one iteration to occur...
|
||||||
|
@ -185,26 +181,20 @@ public class ReconnectTest extends TestCase {
|
||||||
workers[i].failConnection();
|
workers[i].failConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
long start;
|
assertTrue("Timed out waiting for all connections to be interrupted.", Wait.waitFor(new Wait.Condition(){
|
||||||
// Wait for the connections to get interrupted...
|
public boolean isSatisified() throws Exception {
|
||||||
start = System.currentTimeMillis();
|
LOG.debug("Test run waiting for connections to get interrupted.. at: " + interruptedCount.get());
|
||||||
while (interruptedCount.get() < WORKER_COUNT) {
|
return 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);
|
|
||||||
}
|
}
|
||||||
|
}, TimeUnit.SECONDS.toMillis(60)));
|
||||||
|
|
||||||
// Wait for the connections to re-establish...
|
// Wait for the connections to re-establish...
|
||||||
start = System.currentTimeMillis();
|
assertTrue("Timed out waiting for all connections to be resumed.", Wait.waitFor(new Wait.Condition(){
|
||||||
while (resumedCount.get() < WORKER_COUNT) {
|
public boolean isSatisified() throws Exception {
|
||||||
if( System.currentTimeMillis()-start > 1000*60 ) {
|
LOG.debug("Test run waiting for connections to get resumed.. at: " + resumedCount.get());
|
||||||
fail("Timed out waiting for all connections to be resumed.");
|
return resumedCount.get() >= WORKER_COUNT;
|
||||||
}
|
|
||||||
LOG.info("Test run "+k+": Waiting for connections to get resumed.. at: " + resumedCount.get());
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
}
|
||||||
|
}, TimeUnit.SECONDS.toMillis(60)));
|
||||||
|
|
||||||
// Reset the counters..
|
// Reset the counters..
|
||||||
interruptedCount.set(0);
|
interruptedCount.set(0);
|
||||||
|
@ -214,9 +204,7 @@ public class ReconnectTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,13 +215,11 @@ public class ReconnectTest extends TestCase {
|
||||||
TransportConnector connector = bs.addConnector("tcp://localhost:0");
|
TransportConnector connector = bs.addConnector("tcp://localhost:0");
|
||||||
bs.start();
|
bs.start();
|
||||||
tcpUri = connector.getConnectUri();
|
tcpUri = connector.getConnectUri();
|
||||||
|
|
||||||
workers = new Worker[WORKER_COUNT];
|
workers = new Worker[WORKER_COUNT];
|
||||||
for (int i = 0; i < WORKER_COUNT; i++) {
|
for (int i = 0; i < WORKER_COUNT; i++) {
|
||||||
workers[i] = new Worker("" + i);
|
workers[i] = new Worker("" + i);
|
||||||
workers[i].start();
|
workers[i].start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,5 +229,4 @@ public class ReconnectTest extends TestCase {
|
||||||
}
|
}
|
||||||
new ServiceStopper().stop(bs);
|
new ServiceStopper().stop(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue