From 6ac3138daff50b8ba0620d31f5b36d83d0316540 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Tue, 15 Jul 2014 14:33:23 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5222 Add test to show this is working as it should. --- .../broker/region/DestinationGCTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/DestinationGCTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/DestinationGCTest.java index 71055a966c..17bf2b242f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/DestinationGCTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/DestinationGCTest.java @@ -16,6 +16,15 @@ */ 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.broker.BrokerService; import org.apache.activemq.broker.region.policy.PolicyEntry; @@ -28,6 +37,7 @@ import org.apache.activemq.util.Wait.Condition; public class DestinationGCTest extends EmbeddedBrokerTestSupport { ActiveMQQueue queue = new ActiveMQQueue("TEST"); + ActiveMQQueue otherQueue = new ActiveMQQueue("TEST-OTHER"); @Override protected BrokerService createBroker() throws Exception { @@ -44,6 +54,34 @@ public class DestinationGCTest extends EmbeddedBrokerTestSupport { 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 { assertEquals(1, broker.getAdminView().getQueues().length); assertTrue("After GC runs the Queue should be empty.", Wait.waitFor(new Condition() {