You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/08/17 14:47:37 UTC

svn commit: r1374229 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/PrefetchSubscription.java test/java/org/apache/activemq/bugs/AMQ3961Test.java

Author: tabish
Date: Fri Aug 17 12:47:37 2012
New Revision: 1374229

URL: http://svn.apache.org/viewvc?rev=1374229&view=rev
Log:
fix and test for: https://issues.apache.org/jira/browse/AMQ-3961

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3961Test.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=1374229&r1=1374228&r2=1374229&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 17 12:47:37 2012
@@ -427,6 +427,8 @@ public abstract class PrefetchSubscripti
                             dispatched.remove(node);
                             node.getRegionDestination().getDestinationStatistics().getInflight().decrement();
                         }
+                        node.getRegionDestination().wakeup();
+                        dispatchPending();
                     }
 
                     @Override

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3961Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3961Test.java?rev=1374229&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3961Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3961Test.java Fri Aug 17 12:47:37 2012
@@ -0,0 +1,188 @@
+/**
+ * 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 java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jms.ConnectionConsumer;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TopicConnection;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AMQ3961Test {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(AMQ3934Test.class);
+    private static BrokerService brokerService;
+    private static String BROKER_ADDRESS = "tcp://localhost:0";
+
+    private ActiveMQConnectionFactory connectionFactory;
+    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();
+
+        connectionFactory = new ActiveMQConnectionFactory(connectionUri);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        brokerService.stop();
+        brokerService.waitUntilStopped();
+    }
+
+    public class TestServerSessionPool implements ServerSessionPool {
+
+        private TopicConnection connection;
+
+        public TestServerSessionPool(final TopicConnection connection) {
+            this.connection = connection;
+        }
+
+        @Override
+        public ServerSession getServerSession() throws JMSException {
+            final TopicSession topicSession = connection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+            return new TestServerSession(topicSession);
+        }
+    }
+
+    public class TestServerSession implements ServerSession, MessageListener {
+
+        private TopicSession session;
+
+        public TestServerSession(final TopicSession session) throws JMSException {
+            this.session = session;
+            session.setMessageListener(this);
+        }
+
+        @Override
+        public Session getSession() throws JMSException {
+            return session;
+        }
+
+        @Override
+        public void start() throws JMSException {
+            session.run();
+        }
+
+        @Override
+        public void onMessage(final Message message) {
+            synchronized (processedSessions) {
+                processedSessions.add(this);
+            }
+        }
+    }
+
+    public static final int MESSAGE_COUNT = 16;
+    private List<TestServerSession> processedSessions = new LinkedList<TestServerSession>();
+    private List<TestServerSession> committedSessions = new LinkedList<TestServerSession>();
+
+    @Test
+    public void testPrefetchInDurableSubscription() throws Exception {
+        final ActiveMQTopic topic = new ActiveMQTopic("TestTopic");
+
+        final TopicConnection initialSubConnection = connectionFactory.createTopicConnection();
+        initialSubConnection.setClientID("TestClient");
+        initialSubConnection.start();
+        final TopicSession initialSubSession = initialSubConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+        final TopicSubscriber initialSubscriber = initialSubSession.createDurableSubscriber(topic, "TestSubscriber");
+
+        initialSubscriber.close();
+        initialSubSession.close();
+        initialSubConnection.close();
+
+        final TopicConnection publisherConnection = connectionFactory.createTopicConnection();
+        publisherConnection.start();
+        final TopicSession publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+        final TopicPublisher publisher = publisherSession.createPublisher(topic);
+        for (int i = 1; i <= MESSAGE_COUNT; i++) {
+            final Message msg = publisherSession.createTextMessage("Message #" + i);
+            publisher.publish(msg);
+        }
+        publisher.close();
+        publisherSession.close();
+        publisherConnection.close();
+
+        final TopicConnection connection = connectionFactory.createTopicConnection();
+        connection.setClientID("TestClient");
+        connection.start();
+        final TestServerSessionPool pool = new TestServerSessionPool(connection);
+        final ConnectionConsumer connectionConsumer = connection.createDurableConnectionConsumer(topic, "TestSubscriber", null, pool, 1);
+        while (true) {
+            int lastMsgCount = 0;
+            int msgCount = 0;
+            do {
+                lastMsgCount = msgCount;
+                Thread.sleep(200L);
+                synchronized (processedSessions) {
+                    msgCount = processedSessions.size();
+                }
+            } while (lastMsgCount < msgCount);
+
+            if (lastMsgCount == 0) {
+                break;
+            }
+
+            final LinkedList<TestServerSession> collected;
+            synchronized (processedSessions) {
+                collected = new LinkedList<TestServerSession>(processedSessions);
+                processedSessions.clear();
+            }
+
+            final Iterator<TestServerSession> sessions = collected.iterator();
+            while (sessions.hasNext()) {
+                final TestServerSession session = sessions.next();
+                committedSessions.add(session);
+                session.getSession().commit();
+                session.getSession().close();
+            }
+        }
+
+        connectionConsumer.close();
+        final TopicSession finalSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+        finalSession.unsubscribe("TestSubscriber");
+        finalSession.close();
+        connection.close();
+        assertEquals(MESSAGE_COUNT, committedSessions.size());
+    }
+}

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