https://issues.apache.org/activemq/browse/AMQ-2861 - composite destinations and cursor memory usage

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@982317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-08-04 16:15:31 +00:00
parent 0af6b063e7
commit 6dffe4debe
2 changed files with 91 additions and 0 deletions

View File

@ -86,6 +86,7 @@ public class CompositeDestinationBroker extends BrokerFilter {
for (int i = 0; i < destinations.length; i++) {
if (i != 0) {
message = message.copy();
message.setMemoryUsage(null);
}
message.setOriginalDestination(destination);
message.setDestination(destinations[i]);

View File

@ -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);
}
}