diff options
author | Martin Ritchie <ritchiem@apache.org> | 2008-05-30 14:42:38 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2008-05-30 14:42:38 +0000 |
commit | 9209d6833644d57e55a1f8c897299dd4d02cd7a3 (patch) | |
tree | b1f7d7ac99aab9b1ac5e31b98eb054c9ac1ea9a5 | |
parent | ee5af590cb289157d8c4100c7995e5d7a70a90b4 (diff) | |
download | qpid-python-9209d6833644d57e55a1f8c897299dd4d02cd7a3.tar.gz |
QPID-1103 :Changed VMTestCase to allow the creation of InVM brokers based on a configuration file. Updated ApplicationRegistry as it was not correctly utilising the set configuration and always using AR 1.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.x@661739 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 91 insertions, 13 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index 455983c6d8..b14884b717 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -189,7 +189,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry _logger.error("Unable to instantiate configuration class " + instanceType + " - ensure it has a public default constructor"); throw new IllegalArgumentException("Unable to instantiate configuration class " + instanceType + " - ensure it has a public default constructor", e); } - Configurator.configure(instance); + Configurator.configure(instance, _configuration); _configuredObjects.put(instanceType, instance); } return instance; diff --git a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java index cf5e72eebc..16dc81e82d 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java +++ b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java @@ -21,13 +21,16 @@ package org.apache.qpid.test; import junit.framework.TestCase; +import org.apache.qpid.AMQException; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.jndi.PropertiesFileInitialContextFactory; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.AMQException; +import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import org.apache.qpid.testutil.BrokerStartupException; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -37,6 +40,7 @@ import javax.jms.Session; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; +import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -60,14 +64,7 @@ public class VMTestCase extends TestCase protected void setUp() throws Exception { super.setUp(); - try - { - TransportConnection.createVMBroker(1); - } - catch (Exception e) - { - fail("Unable to create broker: " + e); - } + startVMBroker(1); InitialContextFactory factory = new PropertiesFileInitialContextFactory(); @@ -118,9 +115,7 @@ public class VMTestCase extends TestCase //Disabled // checkQueuesClean(); - TransportConnection.killVMBroker(1); - ApplicationRegistry.remove(1); - + stopVMBroker(1); super.tearDown(); } @@ -161,4 +156,58 @@ public class VMTestCase extends TestCase return ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(_virtualhost.substring(1)) .getQueueRegistry().getQueue(new AMQShortString(queueName)).getMessageCount(); } + + public void startVMBroker(int vmID) throws Exception + { + startVMBroker(vmID, null); + } + + /** FIXME: for now vmID must be unique client is responsible for this. */ + public void startVMBroker(int vmID, File configFile) + { + //If we have configuration file then load that + if (configFile != null) + { + if (!configFile.exists()) + { + System.err.println("Configuration file not found:" + configFile); + fail("Configuration file not found:" + configFile); + } + + if (System.getProperty("QPID_HOME") == null) + { + fail("QPID_HOME not set"); + } + + try + { + ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile); + + //For now disable management on all configured inVM broker. + config.getConfiguration().setProperty("management.enabled", "false"); + + ApplicationRegistry.initialise(config, vmID); + } + catch (Exception e) + { + throw new BrokerStartupException("Unable to configure broker:" + vmID + " With file:" + configFile, e); + } + } + + try + { + TransportConnection.createVMBroker(vmID); + } + catch (AMQVMBrokerCreationException e) + { + throw new BrokerStartupException("Unable to start broker:" + vmID, e); + } + } + + public void stopVMBroker(int inVMid) + { + TransportConnection.killVMBroker(inVMid); + ApplicationRegistry.remove(inVMid); + } + } diff --git a/java/systests/src/main/java/org/apache/qpid/testutil/BrokerStartupException.java b/java/systests/src/main/java/org/apache/qpid/testutil/BrokerStartupException.java new file mode 100644 index 0000000000..6ad251954d --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/testutil/BrokerStartupException.java @@ -0,0 +1,29 @@ +/* + * + * 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.qpid.testutil; + +public class BrokerStartupException extends RuntimeException +{ + public BrokerStartupException(String message, Throwable cause) + { + super(message, cause); + } +} |