NO-JIRA Fixing intermittent failure on AutoDeleteJmsDestinationTest
This commit is contained in:
parent
d809976e4e
commit
6e611d8c14
|
@ -25,6 +25,7 @@ import javax.jms.TextMessage;
|
|||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
|
||||
import org.apache.activemq.artemis.core.postoffice.Binding;
|
||||
import org.apache.activemq.artemis.core.server.Queue;
|
||||
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
||||
import org.apache.activemq.artemis.tests.util.JMSTestBase;
|
||||
|
@ -37,51 +38,63 @@ public class AutoDeleteJmsDestinationTest extends JMSTestBase {
|
|||
@Test
|
||||
public void testAutoDeleteQueue() throws Exception {
|
||||
Connection connection = cf.createConnection();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
try {
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
javax.jms.Queue queue = ActiveMQJMSClient.createQueue("test");
|
||||
javax.jms.Queue queue = ActiveMQJMSClient.createQueue("test");
|
||||
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
|
||||
final int numMessages = 100;
|
||||
final int numMessages = 100;
|
||||
|
||||
for (int i = 0; i < numMessages; i++) {
|
||||
TextMessage mess = session.createTextMessage("msg" + i);
|
||||
producer.send(mess);
|
||||
}
|
||||
for (int i = 0; i < numMessages; i++) {
|
||||
TextMessage mess = session.createTextMessage("msg" + i);
|
||||
producer.send(mess);
|
||||
}
|
||||
|
||||
producer.close();
|
||||
producer.close();
|
||||
|
||||
MessageConsumer messageConsumer = session.createConsumer(queue);
|
||||
connection.start();
|
||||
final MessageConsumer messageConsumer = session.createConsumer(queue);
|
||||
connection.start();
|
||||
|
||||
for (int i = 0; i < numMessages - 1; i++) {
|
||||
Message m = messageConsumer.receive(5000);
|
||||
for (int i = 0; i < numMessages - 1; i++) {
|
||||
Message m = messageConsumer.receive(5000);
|
||||
Assert.assertNotNull(m);
|
||||
}
|
||||
|
||||
Wait.waitFor(() -> {
|
||||
Binding binding = server.getPostOffice().getBinding(new SimpleString("test"));
|
||||
if (binding == null) {
|
||||
return false;
|
||||
}
|
||||
return binding.getBindable() != null;
|
||||
});
|
||||
// ensure the queue is still there
|
||||
Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString("test")).getBindable();
|
||||
Wait.assertEquals(1, q::getMessageCount);
|
||||
Assert.assertEquals(numMessages, q.getMessagesAdded());
|
||||
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final MessageConsumer messageConsumer2 = session.createConsumer(queue);
|
||||
messageConsumer.close();
|
||||
Message m = messageConsumer2.receive(5000);
|
||||
Assert.assertNotNull(m);
|
||||
|
||||
connection.close();
|
||||
|
||||
SimpleString qname = new SimpleString("test");
|
||||
Wait.waitFor(() -> server.getPostOffice().getBinding(qname) == null);
|
||||
|
||||
// ensure the queue was removed
|
||||
Assert.assertNull(server.getPostOffice().getBinding(new SimpleString("test")));
|
||||
|
||||
// make sure the JMX control was removed for the JMS queue
|
||||
assertNull(server.getManagementService().getResource("test"));
|
||||
|
||||
messageConsumer2.close();
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
session.close();
|
||||
|
||||
// ensure the queue is still there
|
||||
Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString("test")).getBindable();
|
||||
Assert.assertEquals(1, q.getMessageCount());
|
||||
Assert.assertEquals(numMessages, q.getMessagesAdded());
|
||||
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
messageConsumer = session.createConsumer(queue);
|
||||
Message m = messageConsumer.receive(5000);
|
||||
Assert.assertNotNull(m);
|
||||
|
||||
connection.close();
|
||||
|
||||
SimpleString qname = new SimpleString("test");
|
||||
Wait.waitFor(() -> server.getPostOffice().getBinding(qname) == null);
|
||||
|
||||
// ensure the queue was removed
|
||||
Assert.assertNull(server.getPostOffice().getBinding(new SimpleString("test")));
|
||||
|
||||
// make sure the JMX control was removed for the JMS queue
|
||||
assertNull(server.getManagementService().getResource("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue