From 5bf2329ee73b92cdf8371f615b303b6703a582ff Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Mon, 15 Feb 2010 19:43:54 +0000 Subject: [PATCH] resolve https://issues.apache.org/activemq/browse/AMQ-2607 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@910315 13f79535-47bb-0310-9956-ffa450edef68 --- .../transport/vm/VMTransportFactory.java | 2 +- .../vm/VMTransportBrokerNameTest.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 activemq-core/src/test/java/org/apache/activemq/transport/vm/VMTransportBrokerNameTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java index 1cffafce79..f1c03c72ce 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java @@ -68,7 +68,7 @@ public class VMTransportFactory extends TransportFactory { host = "localhost"; } if (brokerData.getPath() != null) { - host = data.getPath(); + host = brokerData.getPath(); } options = data.getParameters(); location = new URI("vm://" + host); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/vm/VMTransportBrokerNameTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/vm/VMTransportBrokerNameTest.java new file mode 100644 index 0000000000..ac0539317a --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/transport/vm/VMTransportBrokerNameTest.java @@ -0,0 +1,50 @@ +/** + * 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.transport.vm; + +import java.net.URI; + +import javax.jms.Connection; + +import junit.framework.TestCase; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerRegistry; + +public class VMTransportBrokerNameTest extends TestCase { + + private static final String MY_BROKER = "myBroker"; + final String vmUrl = "vm:(broker:(tcp://localhost:61616)/" + MY_BROKER + "?persistent=false)"; + + public void testBrokerName() throws Exception { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(new URI(vmUrl)); + ActiveMQConnection c1 = (ActiveMQConnection) cf.createConnection(); + assertTrue("Transport has name in it: " + c1.getTransport(), c1.getTransport().toString().contains(MY_BROKER)); + + // verify Broker is there with name + ActiveMQConnectionFactory cfbyName = new ActiveMQConnectionFactory(new URI("vm://" + MY_BROKER + "?create=false")); + Connection c2 = cfbyName.createConnection(); + + assertNotNull(BrokerRegistry.getInstance().lookup(MY_BROKER)); + assertEquals(BrokerRegistry.getInstance().findFirst().getBrokerName(), MY_BROKER); + assertEquals(BrokerRegistry.getInstance().getBrokers().size(), 1); + + c1.close(); + c2.close(); + } +}