Author: dejanb
Date: Wed Aug  4 16:15:31 2010
New Revision: 982317

URL: http://svn.apache.org/viewvc?rev=982317&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-2861 - composite destinations and 
cursor memory usage

Added:
    
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/CompositeMessageCursorUsageTest.java
Modified:
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/CompositeDestinationBroker.java

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/CompositeDestinationBroker.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/CompositeDestinationBroker.java?rev=982317&r1=982316&r2=982317&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/CompositeDestinationBroker.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/CompositeDestinationBroker.java
 Wed Aug  4 16:15:31 2010
@@ -86,6 +86,7 @@ public class CompositeDestinationBroker 
             for (int i = 0; i < destinations.length; i++) {
                 if (i != 0) {
                     message = message.copy();
+                    message.setMemoryUsage(null);
                 }
                 message.setOriginalDestination(destination);
                 message.setDestination(destinations[i]);

Added: 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/CompositeMessageCursorUsageTest.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/CompositeMessageCursorUsageTest.java?rev=982317&view=auto
==============================================================================
--- 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/CompositeMessageCursorUsageTest.java
 (added)
+++ 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/CompositeMessageCursorUsageTest.java
 Wed Aug  4 16:15:31 2010
@@ -0,0 +1,90 @@
+/**
+ * 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.usage;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.QueueViewMBean;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.core.MessageCreator;
+
+public class CompositeMessageCursorUsageTest extends TestCase {
+    
+    BrokerService broker;
+    
+    public void setUp() throws Exception {
+        broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.start();
+    }
+    
+    protected void tearDown() throws Exception {
+        broker.stop();
+    }
+
+    public void testCompositeMessageUsage() throws Exception {
+
+        String compositeQueue = "compositeA,compositeB";
+
+        ActiveMQConnectionFactory cf = new 
ActiveMQConnectionFactory("vm://localhost");
+        JmsTemplate jt = new JmsTemplate(cf);
+
+        jt.send(compositeQueue, new MessageCreator() {
+            public Message createMessage(Session session) throws JMSException {
+                TextMessage tm = session.createTextMessage();
+                tm.setText("test");
+                return tm;
+            }
+        });
+
+        jt.send("noCompositeA", new MessageCreator() {
+            public Message createMessage(Session session) throws JMSException {
+                TextMessage tm = session.createTextMessage();
+                tm.setText("test");
+                return tm;
+            }
+        });
+
+        jt.send("noCompositeB", new MessageCreator() {
+            public Message createMessage(Session session) throws JMSException {
+                TextMessage tm = session.createTextMessage();
+                tm.setText("test");
+                return tm;
+            }
+        });
+        
+        assertEquals("Cursor memory usage wrong for 'noCompositeA' queue", 
1032, getQueueView("noCompositeA").getCursorMemoryUsage());
+        assertEquals("Cursor memory usage wrong for 'noCompositeB' queue", 
1032, getQueueView("noCompositeB").getCursorMemoryUsage());
+        assertEquals("Cursor memory usage wrong for 'CompositeA' queue", 1032, 
getQueueView("compositeA").getCursorMemoryUsage());
+        assertEquals("Cursor memory usage wrong for 'CompositeB' queue", 1032, 
getQueueView("compositeB").getCursorMemoryUsage());
+        
+    }
+    
+    public QueueViewMBean getQueueView(String queueName) throws Exception {
+        ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq" + 
":Type=Queue,Destination=" + queueName + ",BrokerName=localhost");
+        return (QueueViewMBean) 
broker.getManagementContext().newProxyInstance(queueViewMBeanName, 
QueueViewMBean.class, true);
+    }
+}


Reply via email to