https://issues.apache.org/jira/browse/AMQ-5710 - rework fix to resolve some unit test regressions, change now confined to rar usecase

This commit is contained in:
gtully 2015-04-09 16:49:44 +01:00
parent 69767a2f2f
commit b29eb384b8
2 changed files with 51 additions and 10 deletions

View File

@ -1572,7 +1572,10 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
* connection.
*/
public void cleanup() throws JMSException {
doCleanup(false);
}
public void doCleanup(boolean removeConnection) throws JMSException {
if (advisoryConsumer != null && !isTransportFailed()) {
advisoryConsumer.dispose();
advisoryConsumer = null;
@ -1587,13 +1590,21 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
c.dispose();
}
if (userSpecifiedClientID) {
info.setClientId(null);
userSpecifiedClientID = false;
if (removeConnection) {
if (isConnectionInfoSentToBroker) {
if (!transportFailed.get() && !closing.get()) {
syncSendPacket(info.createRemoveCommand());
}
isConnectionInfoSentToBroker = false;
}
if (userSpecifiedClientID) {
info.setClientId(null);
userSpecifiedClientID = false;
}
clientIDSet = false;
}
clientIDSet = false;
stop();
started.set(false);
}
/**
@ -1983,7 +1994,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
ServiceSupport.dispose(ActiveMQConnection.this.transport);
brokerInfoReceived.countDown();
try {
cleanup();
doCleanup(true);
} catch (JMSException e) {
LOG.warn("Exception during connection cleanup, " + e, e);
}

View File

@ -29,7 +29,7 @@ public class ConnectionCleanupTest extends TestCase {
private ActiveMQConnection connection;
protected void setUp() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
connection = (ActiveMQConnection)factory.createConnection();
}
@ -50,18 +50,48 @@ public class ConnectionCleanupTest extends TestCase {
try {
connection.setClientID("test");
// fail("Should have received JMSException");
fail("Should have received JMSException");
} catch (JMSException e) {
}
connection.cleanup();
connection.doCleanup(true);
connection.setClientID("test");
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
connection.setClientID("test");
// fail("Should have received JMSException");
fail("Should have received JMSException");
} catch (JMSException e) {
}
}
public void testChangeClientIDDenied() throws JMSException {
connection.setClientID("test");
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
connection.setClientID("test");
fail("Should have received JMSException");
} catch (JMSException e) {
}
connection.cleanup();
try {
connection.setClientID("test");
fail("Should have received JMSException");
} catch (JMSException e) {
}
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
connection.setClientID("test");
fail("Should have received JMSException");
} catch (JMSException e) {
}
}