From 5a27bdf07e1cc77251d02d10b477b38d34413d91 Mon Sep 17 00:00:00 2001 From: gtully Date: Tue, 1 Dec 2015 14:28:07 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6068 - fix and test. Cleanup from ra managed connection needs to remove the connection info, leaving the tcp connection free for another identity. Possibly this could be conditional on having a user supplied clientId --- .../ra/ActiveMQManagedConnection.java | 2 +- .../activemq/ra/ConnectionManagerAdapter.java | 6 +-- .../activemq/ra/ManagedConnectionTest.java | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQManagedConnection.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQManagedConnection.java index 45e702897e..85c947ce7c 100755 --- a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQManagedConnection.java +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQManagedConnection.java @@ -232,7 +232,7 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi proxyConnections.clear(); try { - physicalConnection.cleanup(); + physicalConnection.doCleanup(true); } catch (JMSException e) { throw new ResourceException("Could not cleanup the ActiveMQ connection: " + e, e); } finally { diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/ConnectionManagerAdapter.java b/activemq-ra/src/test/java/org/apache/activemq/ra/ConnectionManagerAdapter.java index 9520c2a72b..278bf9c7a7 100755 --- a/activemq-ra/src/test/java/org/apache/activemq/ra/ConnectionManagerAdapter.java +++ b/activemq-ra/src/test/java/org/apache/activemq/ra/ConnectionManagerAdapter.java @@ -86,11 +86,7 @@ public class ConnectionManagerAdapter implements ConnectionManager, ConnectionEv LOG.warn("Error occured during the cleanup of a managed connection: ", e); } - try { - ((ManagedConnection)event.getSource()).destroy(); - } catch (ResourceException e) { - LOG.warn("Error occured during the destruction of a managed connection: ", e); - } + // should go back in a pool, no destroy } /** diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/ManagedConnectionTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/ManagedConnectionTest.java index 6dbe86413c..2d1e10ab97 100755 --- a/activemq-ra/src/test/java/org/apache/activemq/ra/ManagedConnectionTest.java +++ b/activemq-ra/src/test/java/org/apache/activemq/ra/ManagedConnectionTest.java @@ -33,7 +33,9 @@ import javax.jms.TopicConnectionFactory; import javax.resource.ResourceException; import javax.resource.spi.ConnectionEvent; +import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -61,6 +63,13 @@ public class ManagedConnectionTest { } + @After + public void destroyManagedConnection() throws Exception { + if (managedConnection != null) { + managedConnection.destroy(); + } + } + @Test(timeout = 60000) public void testConnectionCloseEvent() throws ResourceException, JMSException { @@ -160,6 +169,36 @@ public class ManagedConnectionTest { } } + @Test(timeout = 60000) + public void testSetClientIdAfterCleanup() throws Exception { + + connection.setClientID("test"); + try { + connection.setClientID("test"); + fail("Should have received JMSException"); + } catch (JMSException e) { + } + + ActiveMQConnection physicalConnection = (ActiveMQConnection) managedConnection.getPhysicalConnection(); + try { + physicalConnection.setClientID("testTwo"); + fail("Should have received JMSException"); + } catch (JMSException e) { + } + + // close the proxy + connection.close(); + + // can set the id on the physical connection again after cleanup + physicalConnection.setClientID("test3"); + + try { + physicalConnection.setClientID("test4"); + fail("Should have received JMSException"); + } catch (JMSException e) { + } + } + @Test(timeout = 60000) public void testSessionCloseIndependance() throws ResourceException, JMSException {