Repository: activemq Updated Branches: refs/heads/activemq-5.12.x 77cd22ce6 -> eccbd8715
https://issues.apache.org/jira/browse/AMQ-6000 Fix and test, wakeup queue dispatch when resume is called. (cherry picked from commit 078a101cf735ae23ebf96b3bbe3f53003dccc0c7) Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/7875e978 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/7875e978 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/7875e978 Branch: refs/heads/activemq-5.12.x Commit: 7875e978cdea617b22b95d40755b8f761a8be1f7 Parents: 77cd22c Author: Timothy Bish <tabish...@gmail.com> Authored: Tue Nov 10 15:38:16 2015 -0500 Committer: Timothy Bish <tabish...@gmail.com> Committed: Fri Nov 13 11:34:25 2015 -0500 ---------------------------------------------------------------------- .../apache/activemq/broker/region/Queue.java | 9 +- .../org/apache/activemq/bugs/AMQ6000Test.java | 138 +++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/7875e978/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index c9823e1..868dfbc 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -49,7 +49,13 @@ import javax.jms.ResourceAllocationException; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.ProducerBrokerExchange; -import org.apache.activemq.broker.region.cursors.*; +import org.apache.activemq.broker.region.cursors.OrderedPendingList; +import org.apache.activemq.broker.region.cursors.PendingList; +import org.apache.activemq.broker.region.cursors.PendingMessageCursor; +import org.apache.activemq.broker.region.cursors.PrioritizedPendingList; +import org.apache.activemq.broker.region.cursors.QueueDispatchPendingList; +import org.apache.activemq.broker.region.cursors.StoreQueueCursor; +import org.apache.activemq.broker.region.cursors.VMPendingMessageCursor; import org.apache.activemq.broker.region.group.CachedMessageGroupMapFactory; import org.apache.activemq.broker.region.group.MessageGroupMap; import org.apache.activemq.broker.region.group.MessageGroupMapFactory; @@ -1644,6 +1650,7 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index public void resumeDispatch() { dispatchSelector.resume(); + wakeup(); } public boolean isDispatchPaused() { http://git-wip-us.apache.org/repos/asf/activemq/blob/7875e978/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6000Test.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6000Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6000Test.java new file mode 100644 index 0000000..f7f7911 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ6000Test.java @@ -0,0 +1,138 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.bugs; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.broker.region.policy.PolicyEntry; +import org.apache.activemq.broker.region.policy.PolicyMap; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test for AMQ-6000 issue with pause / resume feature. + */ +public class AMQ6000Test { + + private static Logger LOG = LoggerFactory.getLogger(AMQ5921Test.class); + + private ActiveMQConnection connection; + private BrokerService broker; + private String connectionUri; + + @Rule + public TestName name = new TestName(); + + @Before + public void setUp() throws Exception { + broker = new BrokerService(); + broker.setUseJmx(true); + broker.setPersistent(false); + + PolicyMap policyMap = new PolicyMap(); + PolicyEntry defaultEntry = new PolicyEntry(); + defaultEntry.setExpireMessagesPeriod(0); + defaultEntry.setUseCache(false); + policyMap.setDefaultEntry(defaultEntry); + + broker.setDestinationPolicy(policyMap); + broker.addConnector("tcp://localhost:0"); + broker.start(); + broker.waitUntilStarted(); + + connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString(); + + connection = createConnection(); + } + + @After + public void tearDown() throws Exception { + if (connection != null) { + try { + connection.close(); + } catch (Exception e) {} + } + + if (broker != null) { + broker.stop(); + broker.waitUntilStopped(); + } + } + + @Test(timeout = 30000) + public void testResumeNotDispatching() throws Exception { + sendMessage(); + + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination = session.createQueue(name.getMethodName()); + + QueueViewMBean queueView = getProxyToQueue(name.getMethodName()); + LOG.info("Pausing Queue"); + queueView.pause(); + + MessageConsumer consumer = session.createConsumer(destination); + assertNull(consumer.receive(100)); + + LOG.info("Resuming Queue"); + queueView.resume(); + + assertNotNull(consumer.receive(2000)); + } + + protected QueueViewMBean getProxyToQueue(String name) throws MalformedObjectNameException, JMSException { + ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName="+name); + QueueViewMBean proxy = (QueueViewMBean) broker.getManagementContext() + .newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true); + return proxy; + } + + protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { + return new ActiveMQConnectionFactory(connectionUri); + } + + protected ActiveMQConnection createConnection() throws Exception { + return (ActiveMQConnection) createConnectionFactory().createConnection(); + } + + private void sendMessage() throws Exception { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Destination destination = session.createQueue(name.getMethodName()); + MessageProducer producer = session.createProducer(destination); + producer.send(session.createMessage()); + session.close(); + } +}