Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTEMIS-2189 allow deleting temp dest when session is closed #2448

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -386,14 +386,19 @@ public void setSimpleAddress(SimpleString address) {

public void delete() throws JMSException {
if (session != null) {
if (session.getCoreSession().isClosed()) {
// Temporary queues will be deleted when the connection is closed.. nothing to be done then!
return;
}
if (isQueue()) {
session.deleteTemporaryQueue(this);
} else {
session.deleteTemporaryTopic(this);
/**
* The status of the session used to create the temporary destination is uncertain, but the JMS spec states
* that the lifetime of the temporary destination is tied to the connection so even if the originating
* session is closed the temporary destination should still be deleted. Therefore, just create a new one
* and close it after the temporary destination is deleted. This is necessary because the Core API is
* predicated on having a Core ClientSession which is encapsulated by the JMS session implementation.
*/
try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) {
if (isQueue()) {
sessionToUse.deleteTemporaryQueue(this);
} else {
sessionToUse.deleteTemporaryTopic(this);
}
}
}
}
Expand Down
Expand Up @@ -1190,6 +1190,10 @@ void deleteQueue(final SimpleString queueName) throws JMSException {
}
}

public ActiveMQConnection getConnection() {
return connection;
}

// Protected -----------------------------------------------------


Expand Down
Expand Up @@ -27,6 +27,7 @@
import javax.jms.TextMessage;
import javax.naming.NamingException;

import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.jms.tests.util.ProxyAssertSupport;
import org.junit.Test;

Expand Down Expand Up @@ -265,6 +266,126 @@ public void testTemporaryQueueDeleted() throws Exception {
}
}

@Test
public void testTemporaryQueueDeletedAfterSessionClosed() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the behaviour be checked with amqp and openwire to check impl behaviour is the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For AMQP the handling of dynamic nodes is tested here:
https://github.com/apache/activemq-artemis/blob/master/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpTempDestinationTest.java
And here:
https://github.com/apache/activemq-artemis/blob/master/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSTemporaryDestinationTest.java

For OpenWire you'd want to look for a test of the RemoveInfo command that carries a DestintionInfo object.

Other tests that are specifically targeted the JMS spec (or other) compliant behaviour of a client really belong to the project that maintains the client in question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is not with the broker but with the core client. Therefore, I'm not sure it makes sense to test other clients on this particular use-case.

servers.get(0).getActiveMQServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false));

Connection conn = null;

try {
conn = createConnection();

Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

// Make sure temporary queue cannot be used after it has been deleted

TemporaryQueue tempQueue = producerSession.createTemporaryQueue();

MessageProducer producer = producerSession.createProducer(tempQueue);

MessageConsumer consumer = consumerSession.createConsumer(tempQueue);

conn.start();

final String messageText = "This is a message";

Message m = producerSession.createTextMessage(messageText);

producer.send(m);

TextMessage m2 = (TextMessage) consumer.receive(2000);

ProxyAssertSupport.assertNotNull(m2);

ProxyAssertSupport.assertEquals(messageText, m2.getText());

consumer.close();

consumerSession.close();

producer.close();

producerSession.close();

tempQueue.delete();

producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

try {
producer = producerSession.createProducer(tempQueue);
producer.send(m);
ProxyAssertSupport.fail();
} catch (JMSException e) {
}
} finally {
if (conn != null) {
conn.close();
}
}
}

@Test
public void testTemporaryTopicDeletedAfterSessionClosed() throws Exception {
servers.get(0).getActiveMQServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false));

Connection conn = null;

try {
conn = createConnection();

Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

// Make sure temporary topic cannot be used after it has been deleted

TemporaryTopic tempTopic = producerSession.createTemporaryTopic();

MessageProducer producer = producerSession.createProducer(tempTopic);

MessageConsumer consumer = consumerSession.createConsumer(tempTopic);

conn.start();

final String messageText = "This is a message";

Message m = producerSession.createTextMessage(messageText);

producer.send(m);

TextMessage m2 = (TextMessage) consumer.receive(2000);

ProxyAssertSupport.assertNotNull(m2);

ProxyAssertSupport.assertEquals(messageText, m2.getText());

consumer.close();

consumerSession.close();

producer.close();

producerSession.close();

tempTopic.delete();

producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

try {
producer = producerSession.createProducer(tempTopic);
producer.send(m);
ProxyAssertSupport.fail();
} catch (JMSException e) {
}
} finally {
if (conn != null) {
conn.close();
}
}
}

@Test
public void testTemporaryTopicBasic() throws Exception {
Connection conn = null;
Expand Down