Add test to show this is working as it should.
This commit is contained in:
Timothy Bish 2014-07-15 14:33:23 -04:00
parent 8f4079b438
commit 6ac3138daf
1 changed files with 38 additions and 0 deletions

View File

@ -16,6 +16,15 @@
*/ */
package org.apache.activemq.broker.region; package org.apache.activemq.broker.region;
import java.util.concurrent.TimeUnit;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.EmbeddedBrokerTestSupport; import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
@ -28,6 +37,7 @@ import org.apache.activemq.util.Wait.Condition;
public class DestinationGCTest extends EmbeddedBrokerTestSupport { public class DestinationGCTest extends EmbeddedBrokerTestSupport {
ActiveMQQueue queue = new ActiveMQQueue("TEST"); ActiveMQQueue queue = new ActiveMQQueue("TEST");
ActiveMQQueue otherQueue = new ActiveMQQueue("TEST-OTHER");
@Override @Override
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
@ -44,6 +54,34 @@ public class DestinationGCTest extends EmbeddedBrokerTestSupport {
return broker; return broker;
} }
public void testDestinationGCWithActiveConsumers() throws Exception {
assertEquals(1, broker.getAdminView().getQueues().length);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?create=false");
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createProducer(otherQueue).close();
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
}
});
connection.start();
TimeUnit.SECONDS.sleep(5);
assertTrue("After GC runs there should be one Queue.", Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getQueues().length == 1;
}
}));
connection.close();
}
public void testDestinationGc() throws Exception { public void testDestinationGc() throws Exception {
assertEquals(1, broker.getAdminView().getQueues().length); assertEquals(1, broker.getAdminView().getQueues().length);
assertTrue("After GC runs the Queue should be empty.", Wait.waitFor(new Condition() { assertTrue("After GC runs the Queue should be empty.", Wait.waitFor(new Condition() {