From 53fff528a71193e3af8b7c2dfb5b63dd509fac83 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Fri, 18 May 2012 19:30:26 +0000 Subject: [PATCH] Apply patch for: https://issues.apache.org/jira/browse/AMQ-3817 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1340219 13f79535-47bb-0310-9956-ffa450edef68 --- .../broker/util/TraceBrokerPathPlugin.java | 1 + .../util/TraceBrokerPathPluginTest.java | 129 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 activemq-core/src/test/java/org/apache/activemq/broker/util/TraceBrokerPathPluginTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/util/TraceBrokerPathPlugin.java b/activemq-core/src/main/java/org/apache/activemq/broker/util/TraceBrokerPathPlugin.java index 18fee04dcc..82608a52b3 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/util/TraceBrokerPathPlugin.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/util/TraceBrokerPathPlugin.java @@ -58,6 +58,7 @@ public class TraceBrokerPathPlugin extends BrokerPluginSupport { brokerStamp += "," + getBrokerName(); } messageDispatch.getMessage().setProperty(getStampProperty(), brokerStamp); + messageDispatch.getMessage().setMarshalledProperties(null); } } catch (IOException ioe) { LOG.warn("Setting broker property failed " + ioe, ioe); diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/util/TraceBrokerPathPluginTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/util/TraceBrokerPathPluginTest.java new file mode 100644 index 0000000000..35e9cdb840 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/broker/util/TraceBrokerPathPluginTest.java @@ -0,0 +1,129 @@ +/** + * 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.broker.util; + +import javax.jms.Connection; +import javax.jms.DeliveryMode; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import junit.framework.TestCase; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerPlugin; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests TraceBrokerPathPlugin by creating two brokers linked by a network connector, and checking to see if the consuming end receives the expected value in the trace property + * @author Raul Kripalani + * + */ +public class TraceBrokerPathPluginTest extends TestCase { + + BrokerService brokerA; + BrokerService brokerB; + TransportConnector tcpConnectorA; + TransportConnector tcpConnectorB; + MessageProducer producer; + MessageConsumer consumer; + Connection connectionA; + Connection connectionB; + Session sessionA; + Session sessionB; + String queue = "TEST.FOO"; + String traceProperty = "BROKER_PATH"; + + @Before + public void setUp() throws Exception { + TraceBrokerPathPlugin tbppA = new TraceBrokerPathPlugin(); + tbppA.setStampProperty(traceProperty); + + TraceBrokerPathPlugin tbppB = new TraceBrokerPathPlugin(); + tbppB.setStampProperty(traceProperty); + + brokerA = new BrokerService(); + brokerA.setBrokerName("brokerA"); + brokerA.setPersistent(false); + brokerA.setUseJmx(true); + brokerA.setPlugins(new BrokerPlugin[] {tbppA}); + tcpConnectorA = brokerA.addConnector("tcp://localhost:0"); + + brokerB = new BrokerService(); + brokerB.setBrokerName("brokerB"); + brokerB.setPersistent(false); + brokerB.setUseJmx(true); + brokerB.setPlugins(new BrokerPlugin[] {tbppB}); + tcpConnectorB = brokerB.addConnector("tcp://localhost:0"); + + brokerA.addNetworkConnector("static:(" + tcpConnectorB.getConnectUri().toString() + ")"); + + brokerB.start(); + brokerB.waitUntilStarted(); + brokerA.start(); + brokerA.waitUntilStarted(); + + // Initialise connection to A and MessageProducer + connectionA = new ActiveMQConnectionFactory(tcpConnectorA.getConnectUri()).createConnection(); + connectionA.start(); + sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE); + producer = sessionA.createProducer(sessionA.createQueue(queue)); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Initialise connection to B and MessageConsumer + connectionB = new ActiveMQConnectionFactory(tcpConnectorB.getConnectUri()).createConnection(); + connectionB.start(); + sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE); + consumer = sessionB.createConsumer(sessionB.createQueue(queue)); + + } + + @After + public void tearDown() throws Exception { + // Clean up + producer.close(); + consumer.close(); + sessionA.close(); + sessionB.close(); + connectionA.close(); + connectionB.close(); + brokerA.stop(); + brokerB.stop(); + } + + @Test + public void testTraceBrokerPathPlugin() throws Exception { + Message sentMessage = sessionA.createMessage(); + producer.send(sentMessage); + Message receivedMessage = consumer.receive(1000); + + // assert we got the message + assertNotNull(receivedMessage); + + // assert we got the same message ID we sent + assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID()); + + assertEquals("brokerA,brokerB", receivedMessage.getStringProperty(traceProperty)); + + } +}