Author: tabish
Date: Fri Aug 24 20:39:23 2012
New Revision: 1377095
URL: http://svn.apache.org/viewvc?rev=1377095&view=rev
Log:
fix and test for: https://issues.apache.org/jira/browse/AMQ-3992
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java
(with props)
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java?rev=1377095&r1=1377094&r2=1377095&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
Fri Aug 24 20:39:23 2012
@@ -145,7 +145,11 @@ public abstract class PrefetchSubscripti
// perhaps we should inform the caller that we are no longer
valid to dispatch to?
return;
}
- enqueueCounter++;
+
+ // Don't increment for the pullTimeout control message.
+ if (!node.equals(QueueMessageReference.NULL_MESSAGE)) {
+ enqueueCounter++;
+ }
pending.addMessageLast(node);
}
dispatchPending();
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java?rev=1377095&view=auto
==============================================================================
---
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java
(added)
+++
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java
Fri Aug 24 20:39:23 2012
@@ -0,0 +1,107 @@
+/**
+ * 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.assertEquals;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.management.ObjectName;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.BrokerView;
+import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AMQ3992Test {
+
+ private static final transient Logger LOG =
LoggerFactory.getLogger(AMQ3992Test.class);
+ private static BrokerService brokerService;
+ private static String BROKER_ADDRESS = "tcp://localhost:0";
+
+ private String connectionUri;
+
+ @Before
+ public void setUp() throws Exception {
+ brokerService = new BrokerService();
+ brokerService.setPersistent(false);
+ brokerService.setUseJmx(true);
+ brokerService.setDeleteAllMessagesOnStartup(true);
+ connectionUri =
brokerService.addConnector(BROKER_ADDRESS).getPublishableConnectString();
+ brokerService.start();
+ brokerService.waitUntilStarted();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ brokerService.stop();
+ brokerService.waitUntilStopped();
+ }
+
+ @Test
+ public void testDurableConsumerEnqueueCountWithZeroPrefetch() throws
Exception {
+
+ ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(connectionUri);
+ connectionFactory.getPrefetchPolicy().setAll(0);
+
+ Connection connection = connectionFactory.createConnection();
+ connection.setClientID(getClass().getName());
+ connection.start();
+
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createTopic("DurableTopic");
+
+ MessageConsumer consumer = session.createDurableSubscriber((Topic)
destination, "EnqueueSub");
+
+ BrokerView view = brokerService.getAdminView();
+ view.getDurableTopicSubscribers();
+
+ ObjectName subName = view.getDurableTopicSubscribers()[0];
+
+ DurableSubscriptionViewMBean sub = (DurableSubscriptionViewMBean)
+ brokerService.getManagementContext().newProxyInstance(subName,
DurableSubscriptionViewMBean.class, true);
+
+ assertEquals(0, sub.getEnqueueCounter());
+
+ LOG.info("Enqueue counter for sub before pull requests: " +
sub.getEnqueueCounter());
+
+ // Trigger some pull Timeouts.
+ consumer.receive(500);
+ consumer.receive(500);
+ consumer.receive(500);
+ consumer.receive(500);
+ consumer.receive(500);
+
+ // Let them all timeout.
+ Thread.sleep(600);
+
+ LOG.info("Enqueue counter for sub after pull requests: " +
sub.getEnqueueCounter());
+ assertEquals(0, sub.getEnqueueCounter());
+
+ consumer.close();
+ session.close();
+ connection.close();
+ }
+}
Propchange:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3992Test.java
------------------------------------------------------------------------------
svn:eol-style = native