diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:43:12 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-06 09:43:12 +0000 |
| commit | c1dd3ceae904404af5e36bbddfd5a043e397fffe (patch) | |
| tree | b22222734b7722c974e9d83495755e2497ff2073 /qpid/java | |
| parent | fff1166174f6b2aeb7ebfe14eee9007093423869 (diff) | |
| download | qpid-python-c1dd3ceae904404af5e36bbddfd5a043e397fffe.tar.gz | |
QPID-2002 : Completion of BrokerLoggingTest, the shutdown tests have been excluded due to QPID-2031. An update to the LogMessages.vm templates and ApplicationRegistry was requried. This is because BrokerMessages is loaded before the ApplicationRegistry is initialised. As a result the NullApplicationRegistry is created which should not be used. The AR is loaded to discover the current Locale. There were a couple of options here. Either always use the Default Locale and have the AR loading set that or add the ability to check if the AR has been configured. I chose the latter as knowing if an AR exists may be useful for our testing framework.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@801575 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
8 files changed, 1040 insertions, 47 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java index 34125ae25a..ff604bdc82 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -52,6 +52,7 @@ import org.apache.qpid.server.protocol.AMQPFastProtocolHandler; import org.apache.qpid.server.protocol.AMQPProtocolProvider; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import org.apache.qpid.server.transport.QpidAcceptor; import java.io.File; import java.io.IOException; @@ -71,7 +72,7 @@ public class Main private static final String DEFAULT_CONFIG_FILE = "etc/config.xml"; - private static final String DEFAULT_LOG_CONFIG_FILENAME = "log4j.xml"; + public static final String DEFAULT_LOG_CONFIG_FILENAME = "log4j.xml"; public static final String QPID_HOME = "QPID_HOME"; private static final int IPV4_ADDRESS_LENGTH = 4; @@ -273,6 +274,11 @@ public class Main ApplicationRegistry.initialise(config); + // We have already loaded the BrokerMessages class by this point so we + // need to refresh the locale setting incase we had a different value in + // the configuration. + BrokerMessages.reload(); + // AR.initialise() sets its own actor so we now need to set the actor // for the remainder of the startup CurrentActor.set(new BrokerActor(config.getRootMessageLogger())); @@ -292,6 +298,8 @@ public class Main _brokerLogger.info("Starting Qpid Broker " + QpidProperties.getReleaseVersion() + " build: " + QpidProperties.getBuildVersion()); + CurrentActor.get().message(BrokerMessages.BRK_1001(QpidProperties.getReleaseVersion(),QpidProperties.getBuildVersion())); + ByteBuffer.setUseDirectBuffers(serverConfig.getEnableDirectBuffers()); // the MINA default is currently to use the pooled allocator although this may change in future @@ -400,7 +408,7 @@ public class Main bindAddress = new InetSocketAddress(InetAddress.getByAddress(parseIP(bindAddr)), port); } - bind(acceptor, bindAddress, handler, sconfig); + bind(new QpidAcceptor(acceptor,"TCP"), bindAddress, handler, sconfig); //fixme qpid.AMQP should be using qpidproperties to get value _brokerLogger.info("Qpid.AMQP listening on non-SSL address " + bindAddress); @@ -412,7 +420,7 @@ public class Main try { - bind(acceptor, new InetSocketAddress(config.getSSLPort()), handler, sconfig); + bind(new QpidAcceptor(acceptor, "TCP/SSL"), new InetSocketAddress(config.getSSLPort()), handler, sconfig); //fixme qpid.AMQP should be using qpidproperties to get value _brokerLogger.info("Qpid.AMQP listening on SSL port " + config.getSSLPort()); @@ -427,6 +435,9 @@ public class Main //fixme qpid.AMQP should be using qpidproperties to get value _brokerLogger.info("Qpid Broker Ready :" + QpidProperties.getReleaseVersion() + " build: " + QpidProperties.getBuildVersion()); + + CurrentActor.get().message(BrokerMessages.BRK_1004()); + } catch (Exception e) { @@ -446,9 +457,11 @@ public class Main * * @throws IOException from the acceptor.bind command */ - private void bind(IoAcceptor acceptor, InetSocketAddress bindAddress, AMQPFastProtocolHandler handler, SocketAcceptorConfig sconfig) throws IOException + private void bind(QpidAcceptor acceptor, InetSocketAddress bindAddress, AMQPFastProtocolHandler handler, SocketAcceptorConfig sconfig) throws IOException { - acceptor.bind(bindAddress, handler, sconfig); + acceptor.getIoAcceptor().bind(bindAddress, handler, sconfig); + + CurrentActor.get().message(BrokerMessages.BRK_1002(acceptor.toString(), bindAddress.getPort())); ApplicationRegistry.getInstance().addAcceptor(bindAddress, acceptor); } @@ -491,6 +504,7 @@ public class Main { if (logConfigFile.exists() && logConfigFile.canRead()) { + CurrentActor.get().message(BrokerMessages.BRK_1007(logConfigFile.getAbsolutePath())); System.out.println("Configuring logger using configuration file " + logConfigFile.getAbsolutePath()); if (logWatchTime > 0) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index edad8e53aa..b6137e83de 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -26,7 +26,6 @@ import java.util.Map; import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; -import org.apache.mina.common.IoAcceptor; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.plugins.PluginManager; @@ -36,7 +35,9 @@ import org.apache.qpid.server.security.auth.manager.AuthenticationManager; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import org.apache.qpid.server.logging.RootMessageLogger; +import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.transport.QpidAcceptor; /** * An abstract application registry that provides access to configuration information and handles the @@ -58,7 +59,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry public static final String DEFAULT_APPLICATION_REGISTRY = "org.apache.qpid.server.util.NullApplicationRegistry"; public static String _APPLICATION_REGISTRY = DEFAULT_APPLICATION_REGISTRY; - protected final Map<InetSocketAddress, IoAcceptor> _acceptors = new HashMap<InetSocketAddress, IoAcceptor>(); + protected final Map<InetSocketAddress, QpidAcceptor> _acceptors = new HashMap<InetSocketAddress, QpidAcceptor>(); protected ManagedObjectRegistry _managedObjectRegistry; @@ -115,6 +116,16 @@ public abstract class ApplicationRegistry implements IApplicationRegistry } } + public static boolean isConfigured() + { + return isConfigured(DEFAULT_INSTANCE); + } + + public static boolean isConfigured(int instanceID) + { + return _instanceMap.containsKey(instanceID); + } + /** * Method to cleanly shutdown the default registry running in this JVM */ @@ -236,6 +247,8 @@ public abstract class ApplicationRegistry implements IApplicationRegistry } // _pluginManager.close(); + + CurrentActor.get().message(BrokerMessages.BRK_1005()); } private void unbind() @@ -244,8 +257,9 @@ public abstract class ApplicationRegistry implements IApplicationRegistry { for (InetSocketAddress bindAddress : _acceptors.keySet()) { - IoAcceptor acceptor = _acceptors.get(bindAddress); - acceptor.unbind(bindAddress); + QpidAcceptor acceptor = _acceptors.get(bindAddress); + acceptor.getIoAcceptor().unbind(bindAddress); + CurrentActor.get().message(BrokerMessages.BRK_1003(acceptor.toString(), bindAddress.getPort())); } } } @@ -255,7 +269,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry return _configuration; } - public void addAcceptor(InetSocketAddress bindAddress, IoAcceptor acceptor) + public void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor) { synchronized (_acceptors) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java index 7d17639f22..ddb3fce5d2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java @@ -34,6 +34,7 @@ import org.apache.qpid.server.security.access.ACLManager; import org.apache.qpid.server.security.access.ACLPlugin; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import org.apache.qpid.server.logging.RootMessageLogger; +import org.apache.qpid.server.transport.QpidAcceptor; import org.apache.mina.common.IoAcceptor; public interface IApplicationRegistry @@ -77,6 +78,6 @@ public interface IApplicationRegistry * @param bindAddress The address that the acceptor has been bound with * @param acceptor The acceptor in use */ - void addAcceptor(InetSocketAddress bindAddress, IoAcceptor acceptor); + void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java new file mode 100644 index 0000000000..61cc7cdeb6 --- /dev/null +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java @@ -0,0 +1,44 @@ +/* + * + * 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.server.transport; + +import org.apache.mina.common.IoAcceptor; + +public class QpidAcceptor +{ + IoAcceptor _acceptor; + String _protocol; + public QpidAcceptor(IoAcceptor acceptor, String protocol) + { + _acceptor = acceptor; + _protocol = protocol; + } + + public IoAcceptor getIoAcceptor() + { + return _acceptor; + } + + public String toString() + { + return _protocol; + } +} diff --git a/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm b/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm index 10be2299e9..e2fe7ec3c2 100644 --- a/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm +++ b/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm @@ -45,7 +45,21 @@ public class ${type.name}Messages static { - Locale currentLocale = ApplicationRegistry.getInstance().getConfiguration().getLocale(); + reload(); + } + + public static void reload() + { + Locale currentLocale; + + if (ApplicationRegistry.isConfigured()) + { + currentLocale = ApplicationRegistry.getInstance().getConfiguration().getLocale(); + } + else + { + currentLocale = Locale.getDefault(); + } _messages = ResourceBundle.getBundle("org.apache.qpid.server.logging.messages.LogMessages", currentLocale); @@ -54,6 +68,7 @@ public class ${type.name}Messages _formatter.setLocale(currentLocale); } + ## ## The list stored under key 'list' in the 'type' HashMap contains all the ## log messages that this class should contain. So for each entry in the list 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 210702ff75..ed3c3790ec 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 @@ -1,31 +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.server.logging; +/* +* +* 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.server.logging; -import org.apache.qpid.test.utils.QpidTestCase; +import junit.framework.AssertionFailedError; +import org.apache.qpid.server.Main; +import org.apache.qpid.transport.ConnectionException; import org.apache.qpid.util.LogMonitor; import java.io.File; +import java.io.IOException; +import java.net.Socket; import java.util.List; +/** + * Broker Test Suite + * + * The Broker test suite validates that the follow log messages as specified in the Functional Specification. + * + * BRK-1001 : Startup : Version: <Version> Build: <Build> + * BRK-1002 : Starting : Listening on <Transport> port <Port> + * BRK-1003 : Shuting down : <Transport> port <Port> + * BRK-1004 : Ready + * BRK-1005 : Stopped + * BRK-1006 : Using configuration : <path> + * BRK-1007 : Using logging configuration : <path> + * + * These messages should only occur during startup. The tests need to verify the order of messages. In the case of the BRK-1002 and BRK-1003 the respective ports should only be available between the two log messages. + */ public class BrokerLoggingTest extends AbstractTestLogging { LogMonitor _monitor; @@ -69,34 +88,883 @@ public class BrokerLoggingTest extends AbstractTestLogging */ public void testBrokerStartupConfiguration() throws Exception { - // This logging model only applies to the Java broker + // 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()) + { + startBroker(); + + String configFilePath = _configFile.toString(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + String log = getLog(results.get(0)); + + //1 + validateMessageID("BRK-1006", log); + + //2 + results = _monitor.findMatches("BRK-1006"); + assertEquals("More than one configuration message found.", + 1, results.size()); + + //3 + assertTrue("Config file details not correctly logged", + log.endsWith(configFilePath)); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported. + * Input: + * No custom -l value should be provided on the command line so that the default value is correctly reported. + * Output: + * + * <date> MESSAGE BRK-1007 : Using logging configuration : <$QPID_HOME>/etc/log4j.xml + * + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs before the BRK-1001 startup message. + * 3. The log4j file is the full path to the file specified on the commandline. + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupDefaultLog4j() 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. if (isJavaBroker() && isExternalBroker()) { + String TESTID = "BRK-1007"; + +// _monitor = new LogMonitor(new File(System.getProperty("QPID_WORK") + "/log/qpid.log")); + + //Remove test Log4j config from the commandline + _broker = _broker.substring(0, _broker.indexOf("-l")); + startBroker(); + // Ensure broker has fully started up. + getConnection(); + String configFilePath = _configFile.toString(); List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation - // Validation + assertTrue("BRKer message not logged", results.size() > 0); - assertTrue("BRKer message not logged", results.size() > 0); + boolean validation = false; + for (String rawLog : results) + { + // We don't care about messages after we have our log config + if (validation) + { + break; + } - String log = getLog(results.get(0)); + String log = getLog(rawLog); - //1 - validateMessageID("BRK-1006",log); + // Ensure we do not have a BRK-1001 message before + if (!getMessageID(log).equals(TESTID)) + { + assertFalse(getMessageID(log).equals("BRK-1001")); + continue; + } - //2 - results = _monitor.findMatches("BRK-1006"); - assertEquals("More than one configuration message found.", - 1, results.size()); + //1 + validateMessageID(TESTID, log); - //3 - assertTrue("Config file details not correctly logged", - log.endsWith(configFilePath)); + //2 + assertEquals("More than one log4j configuration message found.", + 1, _monitor.findMatches(TESTID).size()); + //3 + String defaultLog4j = _configFile.getParent() + "/" + Main.DEFAULT_LOG_CONFIG_FILENAME; + assertTrue("Log4j file(" + defaultLog4j + ") details not correctly logged:" + getMessageString(log), + getMessageString(log).endsWith(defaultLog4j)); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + + if (results.size() == 0) + { + System.err.println("Monitored file contents:"); + System.err.println(_monitor.readFile()); + } + + throw afe; + } + } + } + + /** + * Description: + * On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported. The broker must also be capable of correctly recognising the command line property to specify the custom logging configuration. + * Input: + * The value of -l specified on the command line. + * Output: + * + * <date> MESSAGE BRK-1007 : Using logging configuration : <log4j file> + * + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This should occur before the BRK-1001 : Startup message + * 3. The log4j file is the full path to the file specified on the commandline. + * + * @throws Exception caused by broker startup + */ + 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. + if (isJavaBroker() && isExternalBroker()) + { + // Get custom -l value used during testing for the broker startup + String customLog4j = _broker.substring(_broker.indexOf("-l") + 2); + + String TESTID = "BRK-1007"; + + startBroker(); + + // Ensure broker has fully started up. + getConnection(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + for (String rawLog : results) + { + // We don't care about messages after we have our log config + if (validation) + { + break; + } + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1001 message before + if (!getMessageID(log).equals(TESTID)) + { + assertFalse(getMessageID(log).equals("BRK-1001")); + continue; + } + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one log4j configuration message found.", + 1, _monitor.findMatches(TESTID).size()); + + //3 + assertTrue("Log4j file details not correctly logged:" + getMessageString(log), + getMessageString(log).endsWith(customLog4j)); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + + if (results.size() == 0) + { + System.err.println("Monitored file contents:"); + System.err.println(_monitor.readFile()); + } + + throw afe; + } } } + /** + * Description: On startup the broker reports the broker version number and svn build revision. This information is retrieved from the resource 'qpidversion.properties' which is located via the classloader. + * Input: The 'qpidversion.properties' file located on the classpath. + * Output: + * + * <date> MESSAGE BRK-1001 : Startup : qpid Version: 0.6 Build: 767150 + * + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs before any BRK-1002 listening messages are reported. + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupStartup() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1001"; + + startBroker(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + for (String rawLog : results) + { + if (validation) + { + //Stop checking once we have got to our startup test + break; + } + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1002 message + if (!getMessageID(log).equals(TESTID)) + { + assertFalse(getMessageID(log).equals("BRK-1002")); + continue; + } + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one startup message found.", + 1, _monitor.findMatches(TESTID).size()); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. + * Input: + * The default configuration with no SSL + * Output: + * + * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 + * + * Constraints: + * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs after the BRK-1001 startup message + * 3. Using the default configuration a single BRK-1002 will be printed showing values TCP / 5672 + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupListeningTCPDefault() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1002"; + + startBroker(); + + // Ensure broker has fully started up. + getConnection(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + boolean foundBRK1001 = false; + for (String rawLog : results) + { + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1002 message + if (!getMessageID(log).equals(TESTID)) + { + if (getMessageID(log).equals("BRK-1001")) + { + foundBRK1001 = true; + } + continue; + } + + assertTrue("BRK-1001 not logged before this message", foundBRK1001); + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one listen message found.", + 1, _monitor.findMatches(TESTID).size()); + + //3 + String message = getMessageString(log); + assertTrue("Expected Listen log not correct" + message, + message.endsWith("Listening on TCP port " + getPort())); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. + * Input: + * The default configuration with SSL enabled + * Output: + * + * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 + * <date> MESSAGE BRK-1002 : Starting : Listening on TCP/SSL port 8672 + * + * Constraints: + * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs after the BRK-1001 startup message + * 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified) + * 1. One showing values TCP / 5672 + * 2. One showing values TCP/SSL / 5672 + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupListeningTCPSSL() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1002"; + + // Enable SSL on the connection + setConfigurationProperty("connector.ssl.enabled", "true"); + setConfigurationProperty("connector.ssl.sslOnly", "false"); + setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath")); + setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword")); + + Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.sslport")); + + startBroker(); + + // Ensure broker has fully started up. + getConnection(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + boolean foundBRK1001 = false; + for (String rawLog : results) + { + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1002 message + if (!getMessageID(log).equals(TESTID)) + { + if (getMessageID(log).equals("BRK-1001")) + { + foundBRK1001 = true; + } + continue; + } + + assertTrue("BRK-1001 not logged before this message", foundBRK1001); + + //1 + validateMessageID(TESTID, log); + + //2 + List<String> listenMessages = _monitor.findMatches(TESTID); + assertEquals("Two listen messages should be found.", + 2, listenMessages .size()); + + //3 + String message = getMessageString(getLog(listenMessages .get(0))); + assertTrue("Expected Listen log not correct" + message, + message.endsWith("Listening on TCP port " + getPort())); + + // Check second, ssl, listen. + message = getMessageString(getLog(listenMessages .get(1))); + assertTrue("Expected Listen log not correct" + message, + message.endsWith("Listening on TCP/SSL port " + sslPort)); + + //4 Test ports open + testSocketOpen(getPort()); + testSocketOpen(sslPort); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * The final message the broker will print when it has performed all initialisation and listener startups will be to log the BRK-1004 Ready message + * Input: + * No input, all successful broker startups will show BRK-1004 messages. + * Output: + * + * 2009-07-09 15:50:20 +0100 MESSAGE BRK-1004 : Ready + * + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs after the BRK-1001 startup message + * 3. This must be the last message the broker prints after startup. Currently, if there is no further interaction with the broker then there should be no more logging. + * + * @throws Exception caused by broker startup + */ + public void testBrokerStartupReady() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1004"; + + startBroker(); + + //Ensure the broker has fully started up. + getConnection(); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + boolean foundBRK1001 = false; + for (String rawLog : results) + { + assertFalse("More broker log statements present after ready message", validation); + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1002 message + if (!getMessageID(log).equals(TESTID)) + { + if (getMessageID(log).equals("BRK-1001")) + { + foundBRK1001 = true; + } + continue; + } + + assertTrue("BRK-1001 not logged before this message", foundBRK1001); + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one ready message found.", + 1, _monitor.findMatches(TESTID).size()); + + //3 + assertEquals("Ready message not present", "Ready", getMessageString(log)); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * On startup the broker may listen on a number of ports and protocols. Each of these must then report a shutting down message as they stop listening. + * Input: + * The default configuration with no SSL + * Output: + * + * <date> MESSAGE BRK-1003 : Shutting down : TCP port 5672 + * + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. Only TCP is reported with the default configuration with no SSL. + * 3. The default port is correct + * 4. The port is not accessible after this message + * + * @throws Exception caused by broker startup + */ + public void testBrokerShutdownListeningTCPDefault() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1003"; + + startBroker(); + + stopBroker(); + + //Give broker time to shutdown and flush log + checkSocketClosed(getPort()); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + boolean foundBRK1001 = false; + for (String rawLog : results) + { + String log = getLog(rawLog); + + // Ensure we do not have a BRK-1002 message + if (!getMessageID(log).equals(TESTID)) + { + if (getMessageID(log).equals("BRK-1001")) + { + foundBRK1001 = true; + } + continue; + } + + assertTrue("BRK-1001 not logged before this message", foundBRK1001); + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one listen message found.", + 1, _monitor.findMatches(TESTID).size()); + + //3 + String message = getMessageString(log); + assertTrue("Expected shutdown log not correct" + message, + message.endsWith("TCP port " + getPort())); + + //4 + checkSocketClosed(getPort()); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. + * Input: + * The default configuration with SSL enabled + * Output: + * + * <date> MESSAGE BRK-1002 : Starting : Listening on TCP port 5672 + * <date> MESSAGE BRK-1002 : Starting : Listening on TCP/SSL port 8672 + * + * Constraints: + * Additional broker configuration will occur between the Startup(BRK-1001) and Starting(BRK-1002) messages depending on what VirtualHosts are configured. + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This occurs after the BRK-1001 startup message + * 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified) + * 1. One showing values TCP / 5672 + * 2. One showing values TCP/SSL / 5672 + * + * @throws Exception caused by broker startup + */ + public void testBrokerShutdownListeningTCPSSL() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1003"; + + // Enable SSL on the connection + setConfigurationProperty("connector.ssl.enabled", "true"); + setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath")); + setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword")); + + Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.sslport")); + + startBroker(); + +// //Clear any startup messages as we don't need them for validation +// _monitor.reset(); + //Stop the broker to get the log messages for testing + stopBroker(); + + //Give broker time to shutdown and flush log + checkSocketClosed(getPort()); + + List<String> results = _monitor.findMatches(TESTID); + try + { + // Validation + + assertTrue(TESTID + " messages not logged", results.size() > 0); + + String log = getLog(results.get(0)); + + //1 + validateMessageID(TESTID, log); + + //2 + List<String> listenMessages = _monitor.findMatches(TESTID); + assertEquals("Two shutdown messages should be found.", + 2, listenMessages.size()); + + //3 + String message = getMessageString(getLog(listenMessages.get(0))); + assertTrue("Expected shutdown log not correct" + message, + message.endsWith("TCP port " + getPort())); + + // Check second, ssl, listen. + message = getMessageString(getLog(listenMessages.get(1))); + assertTrue("Expected shutdown log not correct" + message, + message.endsWith("TCP/SSL port " + sslPort)); + + //4 + //Test Port closed + checkSocketClosed(getPort()); + //Test SSL Port closed + checkSocketClosed(sslPort); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + throw afe; + } + } + } + + /** + * Description: + * Input: + * No input, all clean broker shutdowns will show BRK-1005 messages. + * Output: + * + * <date> MESSAGE BRK-1005 : Stopped + * + * Constraints: + * This is the LAST message the broker will log. + * Validation Steps: + * + * 1. The BRK ID is correct + * 2. This is the last message the broker will log. + * + * @throws Exception caused by broker startup + */ + public void testBrokerShutdownStopped() 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. + if (isJavaBroker() && isExternalBroker()) + { + String TESTID = "BRK-1005"; + + startBroker(); + + getConnection().close(); + + stopBroker(); + + // Ensure the broker has shutdown before retreving results + checkSocketClosed(getPort()); + + List<String> results = _monitor.findMatches("BRK-"); + try + { + // Validation + + assertTrue("BRKer message not logged", results.size() > 0); + + boolean validation = false; + for (String rawLog : results) + { + assertFalse("More broker log statements present after ready message", validation); + String log = getLog(rawLog); + + // Ignore all logs until we get to the test id. + if (!getMessageID(log).equals(TESTID)) + { + continue; + } + + //1 + validateMessageID(TESTID, log); + + //2 + assertEquals("More than one ready message found.", + 1, _monitor.findMatches(TESTID).size()); + + //3 + assertEquals("Stopped message not present", "Stopped", getMessageString(log)); + + validation = true; + } + + assertTrue("Validation not performed: " + TESTID + " not logged", validation); + } + catch (AssertionFailedError afe) + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + + System.err.println("Monitored file contents:"); + System.err.println(_monitor.readFile()); + + throw afe; + } + } + } + + private void checkSocketClosed(int port) + { + try + { + Socket socket = new Socket((String) null, port); + fail("Socket not closed on port:" + port); + } + catch (ConnectionException e) + { + //normal path + } + catch (IOException e) + { + if (!e.getMessage().equals("Connection refused")) + { + fail("Socket not closed on port:" + port + ":" + e.getMessage()); + // Keep stack trace for diagnosis. + e.printStackTrace(System.err); + } + } + } + + private void testSocketOpen(int port) + { + try + { + Socket socket = new Socket((String) null, port); + socket.close(); + } + catch (IOException e) + { + fail("Unable to open and close socket to port:" + port + ". Due to:" + e.getMessage()); + } + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index b9b1eadb0c..4c73e70bc2 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; +import org.apache.commons.configuration.Configuration; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.AMQConnection; @@ -55,6 +56,7 @@ import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.store.DerbyMessageStore; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry; +import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.jms.ConnectionURL; @@ -340,6 +342,15 @@ public class QpidTestCase extends TestCase startBroker(0); } + /** + * Get the Port that is use by the current broker + * @return the current port + */ + protected int getPort() + { + return getPort(0); + } + private int getPort(int port) { if (_broker.equals(VM)) @@ -549,6 +560,22 @@ public class QpidTestCase extends TestCase } /** + * Get a property value from the current configuration file. + * + * @param property the property to lookup + * + * @return the requested String Value + * + * @throws org.apache.commons.configuration.ConfigurationException + * + */ + protected String getConfigurationStringProperty(String property) throws ConfigurationException + { + ServerConfiguration configuration = new ServerConfiguration(_configFile); + return configuration.getConfig().getString(property); + } + + /** * Set a configuration Property for this test run. * * This creates a new configuration based on the current configuration diff --git a/qpid/java/test-profiles/Excludes b/qpid/java/test-profiles/Excludes index a3a61b51db..8899417fe3 100644 --- a/qpid/java/test-profiles/Excludes +++ b/qpid/java/test-profiles/Excludes @@ -5,3 +5,13 @@ org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskValidNoSize org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskInvalid org.apache.qpid.server.queue.QueueCreateTest#testCreateFlowToDiskInvalidSize +// +// QPID-2031 : Broker is not cleanly shutdown by QpidTestCase +// +org.apache.qpid.server.logging.BrokerLoggingTest#testBrokerShutdownListeningTCPDefault +org.apache.qpid.server.logging.BrokerLoggingTest#testBrokerShutdownListeningTCPSSL +org.apache.qpid.server.logging.BrokerLoggingTest#testBrokerShutdownStopped +org.apache.qpid.server.logging.MemoryMessageStoreLoggingTest#testMessageStoreClose + +// Disabled as Derby seems to open a very large number of files which are not closed potentially due to QPID-2031 +org.apache.qpid.server.logging.DerbyMessageStoreLoggingTest#* |
