diff options
| author | Robert Gemmell <robbie@apache.org> | 2011-07-07 15:12:26 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2011-07-07 15:12:26 +0000 |
| commit | aa709d3871daac1a0cd36fb52e2e3bc90074113c (patch) | |
| tree | 8b7fbb235aeb6a203775e40b8375b57077b58594 /qpid/java/systests | |
| parent | 8e19ee98e29a6c3a3311b7fa77d7f5c626a00b91 (diff) | |
| download | qpid-python-aa709d3871daac1a0cd36fb52e2e3bc90074113c.tar.gz | |
QPID-2815: refactor broker startup to present a clean interface interface for starting the broker within an existing application
Applied patch by Keith Wall and myself
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1143870 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests')
13 files changed, 282 insertions, 74 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java index 29b4dd82a7..b50643583e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/MultipleJCAProviderRegistrationTest.java @@ -40,7 +40,7 @@ public class MultipleJCAProviderRegistrationTest extends QpidBrokerTestCase public void setUp() throws Exception { - _broker = VM; + _brokerType = VM; super.setUp(); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java index df8c6e74cd..7cc5d5995a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsConfigurationTest.java @@ -55,7 +55,7 @@ public class MessageStatisticsConfigurationTest extends MessageStatisticsTestCas assertEquals("Incorrect vhost data", 0, vhost.getTotalDataReceived()); assertFalse("Vhost statistics should not be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -83,7 +83,7 @@ public class MessageStatisticsConfigurationTest extends MessageStatisticsTestCas assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 0, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 0, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -111,7 +111,7 @@ public class MessageStatisticsConfigurationTest extends MessageStatisticsTestCas assertEquals("Incorrect vhost data", 0, vhost.getTotalDataReceived()); assertFalse("Vhost statistics should not be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 0, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 0, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -139,7 +139,7 @@ public class MessageStatisticsConfigurationTest extends MessageStatisticsTestCas assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -167,7 +167,7 @@ public class MessageStatisticsConfigurationTest extends MessageStatisticsTestCas assertEquals("Incorrect vhost data", 1000, vhost.getTotalDataReceived()); assertTrue("Vhost statistics should be enabled", vhost.isStatisticsEnabled()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 5, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 1000, _jmxUtils.getServerInformation().getTotalDataReceived()); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java index 50ca51b18a..f1953d1eba 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/MessageStatisticsTest.java @@ -66,7 +66,7 @@ public class MessageStatisticsTest extends MessageStatisticsTestCase assertEquals("Incorrect connection total", 45, total); assertEquals("Incorrect connection data", 4500, data); } - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total", 45, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server data", 4500, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -147,7 +147,7 @@ public class MessageStatisticsTest extends MessageStatisticsTestCase assertEquals("Incorrect active connection total", 20, total); assertEquals("Incorrect active connection data", 2000, data); } - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total", 30, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server data", 3000, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -187,7 +187,7 @@ public class MessageStatisticsTest extends MessageStatisticsTestCase assertApprox("Incorrect dev vhost peak messages", 0.2d, 2.0d, dev.getPeakMessageReceiptRate()); assertApprox("Incorrect dev vhost peak data", 0.2d, 20.0d, dev.getPeakDataReceiptRate()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertApprox("Incorrect server peak messages", 0.2d, 2.0d, _jmxUtils.getServerInformation().getPeakMessageReceiptRate()); assertApprox("Incorrect server peak data", 0.2d, 20.0d, _jmxUtils.getServerInformation().getPeakDataReceiptRate()); @@ -211,7 +211,7 @@ public class MessageStatisticsTest extends MessageStatisticsTestCase assertEquals("Incorrect dev vhost total messages", 10, dev.getTotalMessagesReceived()); assertEquals("Incorrect dev vhost total data", 100, dev.getTotalDataReceived()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 20, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 200, _jmxUtils.getServerInformation().getTotalDataReceived()); @@ -224,7 +224,7 @@ public class MessageStatisticsTest extends MessageStatisticsTestCase assertEquals("Incorrect dev vhost total messages", 10, dev.getTotalMessagesReceived()); assertEquals("Incorrect dev vhost total data", 100, dev.getTotalDataReceived()); - if (!_broker.equals(VM)) + if (!_brokerType.equals(VM)) { assertEquals("Incorrect server total messages", 20, _jmxUtils.getServerInformation().getTotalMessagesReceived()); assertEquals("Incorrect server total data", 200, _jmxUtils.getServerInformation().getTotalDataReceived()); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java index f9227c53ba..27b4de0a8e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java @@ -70,13 +70,13 @@ public class BrokerStartupTest extends AbstractTestLogging { // This logging startup code only occurs when you run a Java broker, // that broker must be started via Main so not an InVM broker. - if (isJavaBroker() && isExternalBroker()) + if (isJavaBroker() && isExternalBroker() && !isInternalBroker()) { //Remove test Log4j config from the commandline - _broker = _broker.substring(0, _broker.indexOf("-l")); + _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l")); // Add an invalid value - _broker += " -l invalid"; + _brokerCommand += " -l invalid"; // The broker has a built in default log4j configuration set up // so if the the broker cannot load the -l value it will use default diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java index 8fd2c085c3..9155b84365 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -21,6 +21,8 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; + +import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.Main; import org.apache.qpid.transport.ConnectionException; import org.apache.qpid.util.LogMonitor; @@ -151,12 +153,12 @@ public class BrokerLoggingTest extends AbstractTestLogging { // This logging startup code only occurs when you run a Java broker, // that broker must be started via Main so not an InVM broker. - if (isJavaBroker() && isExternalBroker()) + if (isJavaBroker() && isExternalBroker() && !isInternalBroker()) { String TESTID = "BRK-1007"; //Remove test Log4j config from the commandline - _broker = _broker.substring(0, _broker.indexOf("-l")); + _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l")); startBroker(); @@ -203,7 +205,7 @@ public class BrokerLoggingTest extends AbstractTestLogging 1, findMatches(TESTID).size()); //3 - String defaultLog4j = _configFile.getParent() + "/" + Main.DEFAULT_LOG_CONFIG_FILENAME; + String defaultLog4j = System.getProperty(QPID_HOME) + "/" + BrokerOptions.DEFAULT_LOG_CONFIG_FILE; assertTrue("Log4j file(" + defaultLog4j + ") details not correctly logged:" + getMessageString(log), getMessageString(log).endsWith(defaultLog4j)); @@ -240,12 +242,11 @@ public class BrokerLoggingTest extends AbstractTestLogging */ public void testBrokerStartupCustomLog4j() throws Exception { - // This logging startup code only occurs when you run a Java broker, - // that broker must be started via Main so not an InVM broker. + // This logging startup code only occurs when you run a Java broker if (isJavaBroker() && isExternalBroker()) { // Get custom -l value used during testing for the broker startup - String customLog4j = _broker.substring(_broker.indexOf("-l") + 2); + String customLog4j = _brokerCommand.substring(_brokerCommand.indexOf("-l") + 2); String TESTID = "BRK-1007"; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java index a5aec3edce..ce6cc60ffd 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java @@ -80,7 +80,7 @@ public class NoLocalAfterRecoveryTest extends QpidBrokerTestCase implements Conn // Due to the problem with SingleServer delaying on all connection // attempts. So using a high retry value. - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { // Local testing suggests InVM restart takes under a second details.setProperty(BrokerDetails.OPTIONS_RETRY, "5"); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java index f40e95885d..be4a865ff6 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java @@ -85,7 +85,7 @@ public class FirewallConfigTest extends QpidBrokerTestCase public void testVhostAllowBrokerDeny() throws Exception { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { //No point running this test with an InVM broker as the //firewall plugin only functions for TCP connections. @@ -125,7 +125,7 @@ public class FirewallConfigTest extends QpidBrokerTestCase public void testVhostDenyBrokerAllow() throws Exception { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { //No point running this test with an InVM broker as the //firewall plugin only functions for TCP connections. @@ -277,7 +277,7 @@ public class FirewallConfigTest extends QpidBrokerTestCase private void testFirewall(boolean initial, boolean inVhost, Runnable restartOrReload) throws Exception { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { // No point running this test in a vm broker return; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java index 637f43fb2c..5fb06dfbb4 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java @@ -102,7 +102,7 @@ public class TransactionTimeoutTestCase extends QpidBrokerTestCase implements Ex super.setUp(); // Connect to broker - String broker = _broker.equals(VM) ? ("vm://:" + DEFAULT_VM_PORT) : ("tcp://localhost:" + DEFAULT_PORT); + String broker = _brokerType.equals(VM) ? ("vm://:" + DEFAULT_VM_PORT) : ("tcp://localhost:" + DEFAULT_PORT); ConnectionURL url = new AMQConnectionURL("amqp://guest:guest@clientid/test?brokerlist='" + broker + "'&maxprefetch='1'"); _con = (AMQConnection) getConnection(url); _con.setExceptionListener(this); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerHolder.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerHolder.java new file mode 100644 index 0000000000..8345803d56 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerHolder.java @@ -0,0 +1,26 @@ +/* + * + * 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.test.utils; + +public interface BrokerHolder +{ + void shutdown(); +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java index d3b429e315..1832a7641e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java @@ -34,24 +34,10 @@ public class FailoverBaseCase extends QpidBrokerTestCase { protected static final Logger _logger = LoggerFactory.getLogger(FailoverBaseCase.class); - public static int FAILING_VM_PORT = 2; - public static int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt")); public static final long DEFAULT_FAILOVER_TIME = 10000L; protected int failingPort; - protected int getFailingPort() - { - if (_broker.equals(VM)) - { - return FAILING_VM_PORT; - } - else - { - return FAILING_PORT; - } - } - protected void setUp() throws java.lang.Exception { super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java new file mode 100644 index 0000000000..340f00fed8 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.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.qpid.test.utils; + +import org.apache.log4j.Logger; +import org.apache.qpid.server.Broker; + +public class InternalBrokerHolder implements BrokerHolder +{ + private static final Logger LOGGER = Logger.getLogger(InternalBrokerHolder.class); + private final Broker _broker; + + public InternalBrokerHolder(final Broker broker) + { + if(broker == null) + { + throw new IllegalArgumentException("Broker must not be null"); + } + + _broker = broker; + } + + public void shutdown() + { + LOGGER.info("Shutting down Broker instance"); + + _broker.shutdown(); + + LOGGER.info("Broker instance shutdown"); + } + +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java index a5d1f4821f..66c8a60c36 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java @@ -25,6 +25,7 @@ import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.PrintStream; import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -62,6 +63,9 @@ import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.jms.ConnectionURL; import org.apache.qpid.management.common.mbeans.ConfigurationManagement; +import org.apache.qpid.server.Broker; +import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.ProtocolExclusion; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; @@ -107,7 +111,8 @@ public class QpidBrokerTestCase extends QpidTestCase // system properties private static final String BROKER_LANGUAGE = "broker.language"; - private static final String BROKER = "broker"; + private static final String BROKER_TYPE = "broker.type"; + private static final String BROKER_COMMAND = "broker.command"; private static final String BROKER_CLEAN = "broker.clean"; private static final String BROKER_CLEAN_BETWEEN_TESTS = "broker.clean.between.tests"; private static final String BROKER_EXISTING_QPID_WORK = "broker.existing.qpid.work"; @@ -118,12 +123,15 @@ public class QpidBrokerTestCase extends QpidTestCase private static final String BROKER_LOG_INTERLEAVE = "broker.log.interleave"; private static final String BROKER_LOG_PREFIX = "broker.log.prefix"; private static final String BROKER_PERSITENT = "broker.persistent"; + private static final String BROKER_PROTOCOL_EXCLUDES = "broker.protocols.excludes"; + // values protected static final String JAVA = "java"; protected static final String CPP = "cpp"; protected static final String VM = "vm"; protected static final String EXTERNAL = "external"; + protected static final String INTERNAL = "internal"; private static final String VERSION_08 = "0-8"; private static final String VERSION_010 = "0-10"; @@ -131,16 +139,19 @@ public class QpidBrokerTestCase extends QpidTestCase public static final int DEFAULT_VM_PORT = 1; public static final int DEFAULT_PORT = Integer.getInteger("test.port", ServerConfiguration.DEFAULT_PORT); + public static final int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt")); public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", ServerConfiguration.DEFAULT_JMXPORT); public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.sslport", ServerConfiguration.DEFAULT_SSL_PORT); protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA); - protected String _broker = System.getProperty(BROKER, VM); + protected String _brokerType = System.getProperty(BROKER_TYPE, INTERNAL); + protected String _brokerCommand = System.getProperty(BROKER_COMMAND); private String _brokerClean = System.getProperty(BROKER_CLEAN, null); private Boolean _brokerCleanBetweenTests = Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS); private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08); protected String _output = System.getProperty(TEST_OUTPUT); protected Boolean _brokerPersistent = Boolean.getBoolean(BROKER_PERSITENT); + private String _brokerProtocolExcludes = System.getProperty(BROKER_PROTOCOL_EXCLUDES); protected static String _brokerLogPrefix = System.getProperty(BROKER_LOG_PREFIX,"BROKER: "); protected static boolean _interleaveBrokerLog = Boolean.getBoolean(BROKER_LOG_INTERLEAVE); @@ -149,7 +160,7 @@ public class QpidBrokerTestCase extends QpidTestCase protected PrintStream _brokerOutputStream; - protected Map<Integer, Process> _brokers = new HashMap<Integer, Process>(); + protected Map<Integer, BrokerHolder> _brokers = new HashMap<Integer, BrokerHolder>(); protected InitialContext _initialContext; protected AMQConnectionFactory _connectionFactory; @@ -291,7 +302,7 @@ public class QpidBrokerTestCase extends QpidTestCase cleanBroker(); File existing = new File(existingQpidWorkPath); - File qpidWork = new File(getQpidWork(_broker, getPort())); + File qpidWork = new File(getQpidWork(_brokerType, getPort())); FileUtils.copyRecursive(existing, qpidWork); } @@ -395,11 +406,6 @@ public class QpidBrokerTestCase extends QpidTestCase } } - public void startBroker() throws Exception - { - startBroker(0); - } - /** * Return the management portin use by the broker on this main port * @@ -409,7 +415,7 @@ public class QpidBrokerTestCase extends QpidTestCase */ protected int getManagementPort(int mainPort) { - return mainPort + (DEFAULT_MANAGEMENT_PORT - (_broker.equals(VM) ? DEFAULT_VM_PORT : DEFAULT_PORT)); + return mainPort + (DEFAULT_MANAGEMENT_PORT - (_brokerType.equals(VM) ? DEFAULT_VM_PORT : DEFAULT_PORT)); } /** @@ -424,11 +430,11 @@ public class QpidBrokerTestCase extends QpidTestCase protected int getPort(int port) { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { return port == 0 ? DEFAULT_VM_PORT : port; } - else if (!_broker.equals(EXTERNAL)) + else if (!_brokerType.equals(EXTERNAL)) { return port == 0 ? DEFAULT_PORT : port; } @@ -440,11 +446,18 @@ public class QpidBrokerTestCase extends QpidTestCase protected String getBrokerCommand(int port) throws MalformedURLException { - return _broker + final String protocolExcludesList = _brokerProtocolExcludes.replace("@PORT", "" + port); + return _brokerCommand .replace("@PORT", "" + port) .replace("@SSL_PORT", "" + (port - 1)) .replace("@MPORT", "" + getManagementPort(port)) - .replace("@CONFIG_FILE", _configFile.toString()); + .replace("@CONFIG_FILE", _configFile.toString()) + .replace("@EXCLUDES", protocolExcludesList); + } + + public void startBroker() throws Exception + { + startBroker(0); } public void startBroker(int port) throws Exception @@ -455,8 +468,12 @@ public class QpidBrokerTestCase extends QpidTestCase saveTestConfiguration(); saveTestVirtualhosts(); - Process process = null; - if (_broker.equals(VM)) + if(_brokers.get(port) != null) + { + throw new IllegalStateException("There is already an existing broker running on port " + port); + } + + if (_brokerType.equals(VM)) { setConfigurationProperty("management.jmxport", String.valueOf(getManagementPort(port))); setConfigurationProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false)); @@ -483,10 +500,33 @@ public class QpidBrokerTestCase extends QpidTestCase } TransportConnection.createVMBroker(port); } - else if (!_broker.equals(EXTERNAL)) + else if (_brokerType.equals(INTERNAL) && !existingInternalBroker()) + { + setConfigurationProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false)); + saveTestConfiguration(); + + BrokerOptions options = new BrokerOptions(); + options.setConfigFile(_configFile.getAbsolutePath()); + options.addPort(port); + + addExcludedPorts(port, options); + + options.setJmxPort(getManagementPort(port)); + + //Set the log config file, relying on the log4j.configuration system property + //set on the JVM by the JUnit runner task in module.xml. + options.setLogConfigFile(new URL(System.getProperty("log4j.configuration")).getFile()); + + Broker broker = new Broker(); + _logger.info("starting internal broker (same JVM)"); + broker.startup(options); + + _brokers.put(port, new InternalBrokerHolder(broker)); + } + else if (!_brokerType.equals(EXTERNAL)) { String cmd = getBrokerCommand(port); - _logger.info("starting broker: " + cmd); + _logger.info("starting external broker: " + cmd); ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+")); pb.redirectErrorStream(true); @@ -502,7 +542,7 @@ public class QpidBrokerTestCase extends QpidTestCase // DON'T change PNAME, qpid.stop needs this value. env.put("QPID_PNAME", "-DPNAME=QPBRKR -DTNAME=\"" + _testName + "\""); // Add the port to QPID_WORK to ensure unique working dirs for multi broker tests - env.put("QPID_WORK", getQpidWork(_broker, port)); + env.put("QPID_WORK", getQpidWork(_brokerType, port)); // Use the environment variable to set amqj.logging.level for the broker @@ -554,8 +594,7 @@ public class QpidBrokerTestCase extends QpidTestCase env.put("QPID_OPTS", QPID_OPTS); } } - - process = pb.start(); + Process process = pb.start();; Piper p = new Piper(process.getInputStream(), _brokerOutputStream, @@ -576,6 +615,7 @@ public class QpidBrokerTestCase extends QpidTestCase try { + //test that the broker is still running and hasn't exited unexpectedly int exit = process.exitValue(); _logger.info("broker aborted: " + exit); cleanBroker(); @@ -583,11 +623,43 @@ public class QpidBrokerTestCase extends QpidTestCase } catch (IllegalThreadStateException e) { - // this is expect if the broker started succesfully + // this is expect if the broker started successfully + } + + _brokers.put(port, new SpawnedBrokerHolder(process)); + } + } + + private void addExcludedPorts(int port, BrokerOptions options) + { + final String protocolExcludesList = _brokerProtocolExcludes.replace("@PORT", "" + port); + final String[] toks = protocolExcludesList.split("\\s"); + + if(toks.length % 2 != 0) + { + throw new IllegalArgumentException("Must be an even number of tokens in " + protocolExcludesList); + } + for (int i = 0; i < toks.length; i=i+2) + { + String excludeArg = toks[i]; + final int excludedPort = Integer.parseInt(toks[i+1]); + options.addExcludedPort(ProtocolExclusion.lookup(excludeArg), excludedPort); + + _logger.info("Adding protocol exclusion " + excludeArg + " " + excludedPort); + } + } + + private boolean existingInternalBroker() + { + for(BrokerHolder holder : _brokers.values()) + { + if(holder instanceof InternalBrokerHolder) + { + return true; } } - _brokers.put(port, process); + return false; } private String getQpidWork(String broker, int port) @@ -682,14 +754,12 @@ public class QpidBrokerTestCase extends QpidTestCase port = getPort(port); _logger.info("stopping broker: " + getBrokerCommand(port)); - Process process = _brokers.remove(port); - if (process != null) + BrokerHolder broker = _brokers.remove(port); + if (broker != null) { - process.destroy(); - process.waitFor(); - _logger.info("broker exited: " + process.exitValue()); + broker.shutdown(); } - else if (_broker.equals(VM)) + else if (_brokerType.equals(VM)) { TransportConnection.killVMBroker(port); ApplicationRegistry.remove(); @@ -940,7 +1010,7 @@ public class QpidBrokerTestCase extends QpidTestCase protected boolean isJavaBroker() { - return _brokerLanguage.equals("java") || _broker.equals("vm"); + return _brokerLanguage.equals("java") || _brokerType.equals("vm"); } protected boolean isCppBroker() @@ -950,9 +1020,14 @@ public class QpidBrokerTestCase extends QpidTestCase protected boolean isExternalBroker() { - return !_broker.equals("vm"); + return !_brokerType.equals("vm"); } - + + protected boolean isInternalBroker() + { + return _brokerType.equals(INTERNAL); + } + protected boolean isBrokerStorePersistent() { return _brokerPersistent; @@ -1024,7 +1099,7 @@ public class QpidBrokerTestCase extends QpidTestCase */ public AMQConnectionFactory getConnectionFactory(String factoryName) throws NamingException { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { factoryName += ".vm"; } @@ -1070,7 +1145,7 @@ public class QpidBrokerTestCase extends QpidTestCase { _logger.info("get Connection"); Connection con; - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { con = new AMQConnection("vm://:1", username, password, id, "test"); } @@ -1335,7 +1410,7 @@ public class QpidBrokerTestCase extends QpidTestCase */ public void reloadBrokerSecurityConfig() throws Exception { - if (_broker.equals(VM)) + if (_brokerType.equals(VM)) { ApplicationRegistry.getInstance().getConfiguration().reparseConfigFileSecuritySections(); } @@ -1360,4 +1435,16 @@ public class QpidBrokerTestCase extends QpidTestCase } } + + protected int getFailingPort() + { + if (_brokerType.equals(VM)) + { + throw new RuntimeException("VM is not supported for Failover testing"); + } + else + { + return FAILING_PORT; + } + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java new file mode 100644 index 0000000000..65239bbe02 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java @@ -0,0 +1,58 @@ +/* + * + * 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.test.utils; + +import org.apache.log4j.Logger; + +public class SpawnedBrokerHolder implements BrokerHolder +{ + private static final Logger LOGGER = Logger.getLogger(SpawnedBrokerHolder.class); + + private final Process _process; + + public SpawnedBrokerHolder(final Process process) + { + if(process == null) + { + throw new IllegalArgumentException("Process must not be null"); + } + + _process = process; + } + + public void shutdown() + { + LOGGER.info("Destroying broker process"); + + _process.destroy(); + + try + { + _process.waitFor(); + LOGGER.info("broker exited: " + _process.exitValue()); + } + catch (InterruptedException e) + { + LOGGER.error("Interrupted whilst waiting for process destruction"); + Thread.currentThread().interrupt(); + } + } +} |
