ARTEMIS-1052 adding a test for expiry and AMQP

This closes #1106
This commit is contained in:
Jiri Danek 2017-03-20 10:38:05 +01:00 committed by Clebert Suconic
parent 9385ce4872
commit 7ac27df7a0
1 changed files with 43 additions and 0 deletions

View File

@ -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<AddressSettings> 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();