ensure broker stop ocurrs after subs connected and add defensive check to close identified by one failure scenario

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1296396 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2012-03-02 19:15:45 +00:00
parent d2f8eded57
commit ac54a611f3
2 changed files with 16 additions and 6 deletions

View File

@ -964,7 +964,10 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
// so that in progress operations can notice and unblock.
List<TransportConnectionState> connectionStates = listConnectionStates();
for (TransportConnectionState cs : connectionStates) {
cs.getContext().getStopping().set(true);
ConnectionContext connectionContext = cs.getContext();
if (connectionContext != null) {
connectionContext.getStopping().set(true);
}
}
try {
DefaultThreadPools.getDefaultTaskRunnerFactory().execute(new Runnable() {

View File

@ -172,8 +172,9 @@ public class DurableConsumerTest extends CombinationTestSupport{
Thread publisherThread = new Thread(new MessagePublisher());
publisherThread.start();
final List<SimpleTopicSubscriber> list = new ArrayList<SimpleTopicSubscriber>();
for (int i = 0; i < 100; i++) {
final int numSubs = 100;
final List<SimpleTopicSubscriber> list = new ArrayList<SimpleTopicSubscriber>(numSubs);
for (int i = 0; i < numSubs; i++) {
final int id = i;
Thread thread = new Thread(new Runnable(){
@ -185,8 +186,14 @@ public class DurableConsumerTest extends CombinationTestSupport{
thread.start();
}
Thread.sleep(5000);
Wait.waitFor(new Wait.Condition(){
@Override
public boolean isSatisified() throws Exception {
return numSubs == list.size();
}
});
broker.stop();
broker = createBroker(false);
configurePersistence(broker);
@ -195,7 +202,7 @@ public class DurableConsumerTest extends CombinationTestSupport{
for (SimpleTopicSubscriber s:list) {
s.closeConnection();
}
assertEquals(0, exceptions.size());
assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
}
// makes heavy use of threads and can demonstrate https://issues.apache.org/activemq/browse/AMQ-2028