activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r985993 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/ main/java/org/apache/activemq/broker/region/policy/ test/java/org/apache/activemq/broker/region/ test/java/org/apache/activemq/bugs/
Date Mon, 16 Aug 2010 15:38:56 GMT
Author: gtully
Date: Mon Aug 16 15:38:56 2010
New Revision: 985993

URL: http://svn.apache.org/viewvc?rev=985993&view=rev
Log:
resolve https://issues.apache.org/activemq/browse/AMQ-2870 - have durable sub ack an unmatched
message straight away

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java 
 (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Subscription.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/SimpleDispatchPolicy.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/StrictOrderDispatchPolicy.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/region/QueueDuplicatesFromStoreTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractSubscription.java
Mon Aug 16 15:38:56 2010
@@ -233,6 +233,10 @@ public abstract class AbstractSubscripti
         return getDispatchedQueueSize() - info.getPrefetchSize();
     }
 
+    public void unmatched(MessageReference node) throws IOException {
+        // only durable topic subs have something to do here
+    }
+
     protected void doAddRecoveredMessage(MessageReference message) throws Exception {
         add(message);
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/DurableTopicSubscription.java
Mon Aug 16 15:38:56 2010
@@ -32,6 +32,7 @@ import org.apache.activemq.command.Messa
 import org.apache.activemq.command.MessageAck;
 import org.apache.activemq.command.MessageDispatch;
 import org.apache.activemq.command.MessageId;
+import org.apache.activemq.filter.MessageEvaluationContext;
 import org.apache.activemq.store.TopicMessageStore;
 import org.apache.activemq.usage.SystemUsage;
 import org.apache.activemq.usage.Usage;
@@ -71,6 +72,16 @@ public class DurableTopicSubscription ex
     public void gc() {
     }
 
+    /**
+     * store will have a pending ack for all durables, irrespective of the selector
+     * so we need to ack if node is un-matched
+     */
+    public void unmatched(MessageReference node) throws IOException {
+        MessageAck ack = new MessageAck();
+        ack.setMessageID(node.getMessageId());
+        node.getRegionDestination().acknowledge(this.getContext(), this, ack, node);
+    }
+
     public void add(ConnectionContext context, Destination destination) throws Exception
{
         super.add(context, destination);
         // do it just once per destination
@@ -270,13 +281,6 @@ public class DurableTopicSubscription ex
         setSlowConsumer(false);
     }
 
-    /**
-     * @param usageManager
-     * @param oldPercentUsage
-     * @param newPercentUsage
-     * @see org.apache.activemq.usage.UsageListener#onMemoryUseChanged(org.apache.activemq.usage.SystemUsage,
-     *      int, int)
-     */
     public void onUsageChanged(Usage usage, int oldPercentUsage, int newPercentUsage) {
         if (oldPercentUsage > newPercentUsage && oldPercentUsage >= 90) {
             try {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Subscription.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Subscription.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Subscription.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Subscription.java
Mon Aug 16 15:38:56 2010
@@ -229,4 +229,6 @@ public interface Subscription extends Su
 	public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark);
 
     boolean isSlowConsumer();
+
+    void unmatched(MessageReference node) throws IOException;
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/RoundRobinDispatchPolicy.java
Mon Aug 16 15:38:56 2010
@@ -56,6 +56,7 @@ public class RoundRobinDispatchPolicy im
 
                 // Only dispatch to interested subscriptions
                 if (!sub.matches(node, msgContext)) {
+                    sub.unmatched(node);
                     continue;
                 }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/SimpleDispatchPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/SimpleDispatchPolicy.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/SimpleDispatchPolicy.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/SimpleDispatchPolicy.java
Mon Aug 16 15:38:56 2010
@@ -41,6 +41,7 @@ public class SimpleDispatchPolicy implem
             }
             // Only dispatch to interested subscriptions
             if (!sub.matches(node, msgContext)) {
+                sub.unmatched(node);
                 continue;
             }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/StrictOrderDispatchPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/StrictOrderDispatchPolicy.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/StrictOrderDispatchPolicy.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/StrictOrderDispatchPolicy.java
Mon Aug 16 15:38:56 2010
@@ -51,6 +51,7 @@ public class StrictOrderDispatchPolicy i
 
                 // Only dispatch to interested subscriptions
                 if (!sub.matches(node, msgContext)) {
+                    sub.unmatched(node);
                     continue;
                 }
 

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/region/QueueDuplicatesFromStoreTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/region/QueueDuplicatesFromStoreTest.java?rev=985993&r1=985992&r2=985993&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/region/QueueDuplicatesFromStoreTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/region/QueueDuplicatesFromStoreTest.java
Mon Aug 16 15:38:56 2010
@@ -297,6 +297,9 @@ public class QueueDuplicatesFromStoreTes
             public boolean isSlowConsumer() {
                 return false;
             }
+
+            public void unmatched(MessageReference node) throws IOException {
+            }
         };
 
         queue.addSubscription(contextNotInTx, subscription);

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java?rev=985993&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java Mon
Aug 16 15:38:56 2010
@@ -0,0 +1,201 @@
+/**
+ * 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 java.util.Properties;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TopicSubscriber;
+import junit.framework.Test;
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.BrokerView;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.store.PersistenceAdapter;
+import org.apache.activemq.util.IntrospectionSupport;
+import org.apache.activemq.util.Wait;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class AMQ2870Test extends org.apache.activemq.TestSupport {
+
+    static final Log LOG = LogFactory.getLog(AMQ2870Test.class);
+    BrokerService broker = null;
+    ActiveMQTopic topic;
+
+    ActiveMQConnection consumerConnection = null, producerConnection = null;
+    Session producerSession;
+    MessageProducer producer;
+    final int minPercentUsageForStore = 10;
+    String data;
+
+    public static Test suite() {
+        return suite(AMQ2870Test.class);
+    }
+    
+    public void initCombosForTestSize() throws Exception {
+        this.addCombinationValues("defaultPersistenceAdapter",
+                new Object[]{ PersistenceAdapterChoice.KahaDB, PersistenceAdapterChoice.AMQ});
+    }
+    
+    public void testSize() throws Exception {
+        openConsumer();
+
+        assertEquals(0, broker.getAdminView().getStorePercentUsage());
+                                                                                        
                                     Failo
+        for (int i = 0; i < 5000; i++) {
+            sendMessage(false);
+        }
+
+        final BrokerView brokerView = broker.getAdminView();
+
+        // wait for reclaim
+        assertTrue("in range with consumer",
+                Wait.waitFor(new Wait.Condition() {
+                    public boolean isSatisified() throws Exception {
+                        // usage percent updated only on send check for isFull so once
+                        // sends complete it is no longer updated till next send via a call
to isFull
+                        // this is optimal as it is only used to block producers
+                        broker.getSystemUsage().getStoreUsage().isFull();
+                        LOG.info("store precent usage: "+brokerView.getStorePercentUsage());
+                        return broker.getAdminView().getStorePercentUsage() < minPercentUsageForStore;
+                    }
+                }));
+
+
+        closeConsumer();
+
+        assertTrue("in range with closed consumer",
+                Wait.waitFor(new Wait.Condition() {
+                    public boolean isSatisified() throws Exception {
+                        broker.getSystemUsage().getStoreUsage().isFull();
+                        LOG.info("store precent usage: "+brokerView.getStorePercentUsage());
+                        return broker.getAdminView().getStorePercentUsage() < minPercentUsageForStore;
+                    }
+                }));
+
+        for (int i = 0; i < 5000; i++) {
+            sendMessage(false);
+        }
+
+        // What if i drop the subscription?
+        broker.getAdminView().destroyDurableSubscriber("cliID", "subName");
+
+        assertTrue("in range after send with consumer",
+                Wait.waitFor(new Wait.Condition() {
+                    public boolean isSatisified() throws Exception {
+                        broker.getSystemUsage().getStoreUsage().isFull();
+                        LOG.info("store precent usage: "+brokerView.getStorePercentUsage());
                       
+                        return broker.getAdminView().getStorePercentUsage() < minPercentUsageForStore;
+                    }
+                }));
+
+    }
+
+    private void openConsumer() throws Exception {
+        consumerConnection = (ActiveMQConnection) createConnection();
+        consumerConnection.setClientID("cliID");
+        consumerConnection.start();
+        Session session = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TopicSubscriber subscriber = session.createDurableSubscriber(topic, "subName", "filter=true",
false);
+
+        subscriber.setMessageListener(new MessageListener() {
+            public void onMessage(Message message) {
+                // received++;
+            }
+        });
+    }
+
+    private void closeConsumer() throws JMSException {
+        if (consumerConnection != null)
+            consumerConnection.close();
+        consumerConnection = null;
+    }
+
+    private void sendMessage(boolean filter) throws Exception {
+        if (producerConnection == null) {
+            producerConnection = (ActiveMQConnection) createConnection();
+            producerConnection.start();
+            producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            producer = producerSession.createProducer(topic);
+        }
+
+        Message message = producerSession.createMessage();
+        message.setBooleanProperty("filter", filter);
+        message.setStringProperty("data", data);
+        producer.send(message);
+    }
+
+    private void startBroker(boolean deleteMessages) throws Exception {
+        broker = new BrokerService();
+        broker.setAdvisorySupport(false);
+        broker.setBrokerName("testStoreSize");
+
+        if (deleteMessages) {
+            broker.setDeleteAllMessagesOnStartup(true);
+        }
+        setDefaultPersistenceAdapter(broker);
+        configurePersistenceAdapter(broker.getPersistenceAdapter());
+        broker.getSystemUsage().getStoreUsage().setLimit(100 * 1000 * 1000);
+        broker.start();
+    }
+
+    private void configurePersistenceAdapter(PersistenceAdapter persistenceAdapter) {
+        Properties properties = new Properties();
+        String maxFileLengthVal = String.valueOf(2 * 1024 * 1024);
+        properties.put("journalMaxFileLength", maxFileLengthVal);
+        properties.put("maxFileLength", maxFileLengthVal);
+        properties.put("cleanupInterval", "2000");
+        properties.put("checkpointInterval", "2000");
+       
+        IntrospectionSupport.setProperties(persistenceAdapter, properties);
+    }
+
+    private void stopBroker() throws Exception {
+        if (broker != null)
+            broker.stop();
+        broker = null;
+    }
+
+    protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+        return new ActiveMQConnectionFactory("vm://testStoreSize?jms.watchTopicAdvisories=false&waitForStart=5000&create=false");
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        StringBuilder sb = new StringBuilder(5000);
+        for (int i = 0; i < 5000; i++) {
+            sb.append('a');
+        }
+        data = sb.toString();
+
+        startBroker(true);
+        topic = (ActiveMQTopic) createDestination();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        stopBroker();
+        super.tearDown();
+    }
+}
\ No newline at end of file

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2870Test.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message