diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java index 46e3b95fe3..3c4e915943 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/SendingAndReceivingTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.artemis.tests.integration.amqp; import javax.jms.Connection; import javax.jms.ConnectionFactory; +import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Queue; @@ -26,8 +27,11 @@ import javax.jms.TextMessage; import java.util.Random; import java.util.Set; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.settings.HierarchicalRepository; +import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.qpid.jms.JmsConnectionFactory; import org.junit.After; @@ -91,6 +95,45 @@ public class SendingAndReceivingTest extends ActiveMQTestBase { } } + @Test(timeout = 60000) + public void testSendMessageThenAllowToExpireUsingTimeToLive() throws Exception { + AddressSettings as = new AddressSettings(); + as.setExpiryAddress(SimpleString.toSimpleString("DLQ")); + HierarchicalRepository repos = server.getAddressSettingsRepository(); + repos.addMatch("exampleQueue", as); + + Connection connection = null; + ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:61616"); + + try { + connection = connectionFactory.createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + String address = "exampleQueue"; + Queue queue = session.createQueue(address); + + MessageProducer sender = session.createProducer(queue); + sender.setTimeToLive(10); + + Message message = session.createMessage(); + sender.send(message); + connection.start(); + + MessageConsumer consumer = session.createConsumer(queue); + Message m = consumer.receive(5000); + Assert.assertNull(m); + consumer.close(); + + consumer = session.createConsumer(session.createQueue("DLQ")); + m = consumer.receive(5000); + Assert.assertNotNull(m); + consumer.close(); + } finally { + if (connection != null) { + connection.close(); + } + } + } + private static String createMessage(int messageSize) { final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Random rnd = new Random();