summaryrefslogtreecommitdiff
path: root/java/systests/src/main/java/org/apache/qpid/test/utils
diff options
context:
space:
mode:
Diffstat (limited to 'java/systests/src/main/java/org/apache/qpid/test/utils')
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java79
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java61
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java26
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java62
-rwxr-xr-x[-rw-r--r--]java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java502
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java295
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java219
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java30
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java54
9 files changed, 705 insertions, 623 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
new file mode 100644
index 0000000000..12d286f822
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
@@ -0,0 +1,79 @@
+/* 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 java.io.File;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Generates the command to start a broker by substituting the tokens
+ * in the provided broker command.
+ *
+ * The command is returned as a list so that it can be easily used by a
+ * {@link java.lang.ProcessBuilder}.
+ */
+public class BrokerCommandHelper
+{
+ private final List<String> _brokerCommandTemplateAsList;
+
+ public BrokerCommandHelper(String brokerCommandTemplate)
+ {
+ _brokerCommandTemplateAsList = new LinkedList<String>(Arrays.asList(brokerCommandTemplate.split("\\s+")));
+ }
+
+ public String[] getBrokerCommand( int port, String storePath, String storeType, File logConfigFile)
+ {
+ String[] command = new String[_brokerCommandTemplateAsList.size()];
+ int i=0;
+ for (String commandPart : _brokerCommandTemplateAsList)
+ {
+ command[i] = commandPart
+ .replace("@PORT", "" + port)
+ .replace("@STORE_PATH", storePath)
+ .replace("@STORE_TYPE", storeType)
+ .replace("@LOG_CONFIG_FILE", '"' + logConfigFile.getAbsolutePath() + '"');
+ i++;
+ }
+ return command;
+ }
+
+ private int getBrokerCommandLogOptionIndex(String logOption)
+ {
+ int logOptionIndex = _brokerCommandTemplateAsList.indexOf(logOption);
+ if(logOptionIndex == -1)
+ {
+ throw new RuntimeException("Could not find option " + logOption + " in " + _brokerCommandTemplateAsList);
+ }
+ return logOptionIndex;
+ }
+
+
+ public void removeBrokerCommandLog4JFile()
+ {
+ String logOption = "-l";
+ int logOptionIndex = getBrokerCommandLogOptionIndex(logOption);
+ if (logOptionIndex + 1 >= _brokerCommandTemplateAsList.size())
+ {
+ throw new RuntimeException("Could not find log config location");
+ }
+ _brokerCommandTemplateAsList.remove(logOptionIndex);
+ _brokerCommandTemplateAsList.remove(logOptionIndex);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
new file mode 100644
index 0000000000..f0bcea8e6e
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
@@ -0,0 +1,61 @@
+/* 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 static org.mockito.Mockito.*;
+
+import java.io.File;
+
+public class BrokerCommandHelperTest extends QpidTestCase
+{
+ private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE");
+
+ private File logConfigFile = mock(File.class);
+
+ @Override
+ public void setUp()
+ {
+ when(logConfigFile.getAbsolutePath()).thenReturn("log Config File");
+ }
+
+ public void testGetBrokerCommand()
+ {
+ String[] brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
+
+ String[] expected = { "qpid", "-p", "1", "-sp", "configFile", "-st", "json", "-l", "\"log Config File\"" };
+ assertEquals("Unexpected broker command", 9, brokerCommand.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEquals("Unexpected command part value at " + i,expected[i], brokerCommand[i] );
+ }
+ }
+
+ public void testRemoveBrokerCommandLog4JFile()
+ {
+ _brokerCommandHelper.removeBrokerCommandLog4JFile();
+ String[] brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
+
+ String[] expected = { "qpid", "-p", "1", "-sp", "configFile", "-st", "json" };
+ assertEquals("Unexpected broker command", 7, brokerCommand.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEquals("Unexpected command part value at " + i,expected[i], brokerCommand[i] );
+ }
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java b/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
index a71a4ef517..8bad73d0ea 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
@@ -20,9 +20,6 @@
*/
package org.apache.qpid.test.utils;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
import java.util.Set;
import org.apache.log4j.Logger;
@@ -82,28 +79,7 @@ public class InternalBrokerHolder implements BrokerHolder
@Override
public String dumpThreads()
{
- ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
- ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
- StringBuilder dump = new StringBuilder();
- dump.append(String.format("%n"));
- for (ThreadInfo threadInfo : threadInfos)
- {
- dump.append(threadInfo);
- }
-
- long[] deadLocks = threadMXBean.findDeadlockedThreads();
- if (deadLocks != null && deadLocks.length > 0)
- {
- ThreadInfo[] deadlockedThreads = threadMXBean.getThreadInfo(deadLocks);
- dump.append(String.format("%n"));
- dump.append("Deadlock is detected!");
- dump.append(String.format("%n"));
- for (ThreadInfo threadInfo : deadlockedThreads)
- {
- dump.append(threadInfo);
- }
- }
- return dump.toString();
+ return TestUtils.dumpThreads();
}
@Override
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java b/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
index 43b80b45fb..6e6e3271f0 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
@@ -24,7 +24,6 @@ import junit.framework.TestCase;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.management.common.JMXConnnectionFactory;
-import org.apache.qpid.management.common.mbeans.ConfigurationManagement;
import org.apache.qpid.management.common.mbeans.LoggingManagement;
import org.apache.qpid.management.common.mbeans.ManagedBroker;
import org.apache.qpid.management.common.mbeans.ManagedConnection;
@@ -32,6 +31,8 @@ import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.management.common.mbeans.ManagedQueue;
import org.apache.qpid.management.common.mbeans.ServerInformation;
import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
@@ -46,7 +47,9 @@ import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -78,7 +81,7 @@ public class JMXTestUtils
public void setUp() throws IOException, ConfigurationException, Exception
{
- _test.setConfigurationProperty("management.enabled", "true");
+ _test.getBrokerConfiguration().addJmxManagementConfiguration();
}
public void open() throws Exception
@@ -287,9 +290,7 @@ public class JMXTestUtils
public ObjectName getQueueObjectName(String virtualHostName, String queue)
{
// Get the name of the test manager
- String query = "org.apache.qpid:type=VirtualHost.Queue,VirtualHost="
- + ObjectName.quote(virtualHostName) + ",name="
- + ObjectName.quote(queue) + ",*";
+ String query = getQueueObjectNameString(virtualHostName, queue);
Set<ObjectName> objectNames = queryObjects(query);
@@ -302,32 +303,20 @@ public class JMXTestUtils
return objectName;
}
+ public String getQueueObjectNameString(String virtualHostName, String queue) {
+ return "org.apache.qpid:type=VirtualHost.Queue,VirtualHost="
+ + ObjectName.quote(virtualHostName) + ",name="
+ + ObjectName.quote(queue) + ",*";
+ }
+
/**
- * Retrive the ObjectName for the given Exchange on a VirtualHost.
- *
- * This is then used to create a proxy to the ManagedExchange MBean.
- *
- * @param virtualHostName the VirtualHost the Exchange is on
- * @param exchange the Exchange to retireve e.g. 'direct'
- * @return the ObjectName for the given Exchange on the VirtualHost
+ * Generate the ObjectName for the given Exchange on a VirtualHost.
*/
- @SuppressWarnings("static-access")
- public ObjectName getExchangeObjectName(String virtualHostName, String exchange)
+ public String getExchangeObjectName(String virtualHostName, String exchange)
{
- // Get the name of the test manager
- String query = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
+ return "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
+ ObjectName.quote(virtualHostName) + ",name="
+ ObjectName.quote(exchange) + ",*";
-
- Set<ObjectName> objectNames = queryObjects(query);
-
- _test.assertNotNull("Null ObjectName Set returned", objectNames);
- _test.assertEquals("Incorrect number of exchange with name '" + exchange + "' returned", 1, objectNames.size());
-
- // We have verified we have only one value in objectNames so return it
- ObjectName objectName = objectNames.iterator().next();
- _test.getLogger().info("Loading: " + objectName);
- return objectName;
}
@SuppressWarnings("static-access")
@@ -343,7 +332,7 @@ public class JMXTestUtils
return getManagedObject(managedClass, objectName);
}
- public boolean isManagedObjectExist(String query)
+ public boolean doesManagedObjectExist(String query)
{
return !queryObjects(query).isEmpty();
}
@@ -373,9 +362,20 @@ public class JMXTestUtils
return getManagedObject(ManagedBroker.class, getVirtualHostManagerObjectName(virtualHost));
}
+ @SuppressWarnings("static-access")
public ManagedExchange getManagedExchange(String exchangeName)
{
- ObjectName objectName = getExchangeObjectName("test", exchangeName);
+ String query = getExchangeObjectName("test", exchangeName);
+
+ Set<ObjectName> objectNames = queryObjects(query);
+
+ _test.assertNotNull("Null ObjectName Set returned", objectNames);
+ _test.assertEquals("Incorrect number of exchange with name '" + exchangeName + "' returned", 1, objectNames.size());
+
+ // We have verified we have only one value in objectNames so return an mbean proxy for it
+ ObjectName objectName = objectNames.iterator().next();
+ _test.getLogger().info("Loading: " + objectName);
+
return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, ManagedExchange.class, false);
}
@@ -391,12 +391,6 @@ public class JMXTestUtils
return getManagedObject(LoggingManagement.class, objectName);
}
- public ConfigurationManagement getConfigurationManagement() throws MalformedObjectNameException
- {
- ObjectName objectName = new ObjectName("org.apache.qpid:type=ConfigurationManagement,name=ConfigurationManagement");
- return getManagedObject(ConfigurationManagement.class, objectName);
- }
-
public UserManagement getUserManagement() throws MalformedObjectNameException
{
ObjectName objectName = new ObjectName("org.apache.qpid:type=UserManagement,name=UserManagement");
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
index aa909a6674..d36f57171f 100644..100755
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
@@ -19,18 +19,17 @@ package org.apache.qpid.test.utils;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.PrintStream;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.Destination;
@@ -45,32 +44,34 @@ import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;
import javax.jms.Topic;
+import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQTopic;
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.ProtocolInclusion;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.store.MemoryMessageStore;
import org.apache.qpid.server.store.MessageStoreConstants;
+import org.apache.qpid.server.store.MessageStoreCreator;
+import org.apache.qpid.server.store.MessageStoreFactory;
import org.apache.qpid.server.store.derby.DerbyMessageStore;
import org.apache.qpid.url.URLSyntaxException;
import org.apache.qpid.util.FileUtils;
-import org.apache.qpid.util.LogMonitor;
/**
* Qpid base class for system testing test cases.
@@ -80,7 +81,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public enum BrokerType
{
EXTERNAL /** Test case relies on a Broker started independently of the test-suite */,
- INTERNAL /** Test case starts an embedded broker within this JVM */,
+ INTERNAL /** Test case starts an embedded broker within this JVM */,
SPAWNED /** Test case spawns a new broker as a separate process */
}
@@ -88,9 +89,9 @@ public class QpidBrokerTestCase extends QpidTestCase
public static final String GUEST_PASSWORD = "guest";
protected final static String QpidHome = System.getProperty("QPID_HOME");
- protected File _configFile = new File(System.getProperty("broker.config"));
- protected File _logConfigFile = new File(System.getProperty("log4j.configuration"));
-
+ private final File _configFile = new File(System.getProperty("broker.config"));
+ private File _logConfigFile;
+ protected final String _brokerStoreType = System.getProperty("broker.config-store-type", "json");
protected static final Logger _logger = Logger.getLogger(QpidBrokerTestCase.class);
protected static final int LOGMONITOR_TIMEOUT = 5000;
@@ -98,7 +99,7 @@ public class QpidBrokerTestCase extends QpidTestCase
private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>();
- private XMLConfiguration _testConfiguration = new XMLConfiguration();
+ private Map<Integer, TestBrokerConfiguration> _brokerConfigurations;
private XMLConfiguration _testVirtualhosts = new XMLConfiguration();
protected static final String INDEX = "index";
@@ -106,24 +107,31 @@ public class QpidBrokerTestCase extends QpidTestCase
private static final String DEFAULT_INITIAL_CONTEXT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
+ private static Map<String, String> supportedStoresClassToTypeMapping = new HashMap<String, String>();
+
static
{
- String initialContext = System.getProperty(InitialContext.INITIAL_CONTEXT_FACTORY);
+ String initialContext = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
if (initialContext == null || initialContext.length() == 0)
{
- System.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT);
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT);
+ }
+
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ Collection<MessageStoreFactory> factories = messageStoreCreator.getFactories();
+ for (MessageStoreFactory messageStoreFactory : factories)
+ {
+ supportedStoresClassToTypeMapping.put(messageStoreFactory.createMessageStore().getClass().getName(), messageStoreFactory.getType());
}
}
// system properties
private static final String TEST_VIRTUALHOSTS = "test.virtualhosts";
- private static final String TEST_CONFIG = "test.config";
private static final String BROKER_LANGUAGE = "broker.language";
protected static final String BROKER_TYPE = "broker.type";
private static final String BROKER_COMMAND = "broker.command";
private static final String BROKER_CLEAN_BETWEEN_TESTS = "broker.clean.between.tests";
- private static final String BROKER_EXISTING_QPID_WORK = "broker.existing.qpid.work";
private static final String BROKER_VERSION = "broker.version";
protected static final String BROKER_READY = "broker.ready";
private static final String BROKER_STOPPED = "broker.stopped";
@@ -131,8 +139,14 @@ 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";
- public static final String BROKER_PROTOCOL_EXCLUDES = "broker.protocol.excludes";
- public static final String BROKER_PROTOCOL_INCLUDES = "broker.protocol.includes";
+ public static final String PROFILE_USE_SSL = "profile.use_ssl";
+
+ public static final int DEFAULT_PORT_VALUE = 5672;
+ public static final int DEFAULT_SSL_PORT_VALUE = 5671;
+ public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
+ public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
+ public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080;
+ public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443;
// values
protected static final String JAVA = "java";
@@ -140,15 +154,15 @@ public class QpidBrokerTestCase extends QpidTestCase
protected static final String QPID_HOME = "QPID_HOME";
- 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 DEFAULT_PORT = Integer.getInteger("test.port", DEFAULT_PORT_VALUE);
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_REGISTRYSERVER);
- public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", ServerConfiguration.DEFAULT_SSL_PORT);
+ public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", DEFAULT_JMXPORT_REGISTRYSERVER);
+ public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", DEFAULT_SSL_PORT_VALUE);
protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA);
protected BrokerType _brokerType = BrokerType.valueOf(System.getProperty(BROKER_TYPE, "").toUpperCase());
- protected String _brokerCommand = System.getProperty(BROKER_COMMAND);
+
+ protected BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper(System.getProperty(BROKER_COMMAND));
private Boolean _brokerCleanBetweenTests = Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS);
private final AmqpProtocolVersion _brokerVersion = AmqpProtocolVersion.valueOf(System.getProperty(BROKER_VERSION, ""));
protected String _output = System.getProperty(TEST_OUTPUT, System.getProperty("java.io.tmpdir"));
@@ -190,14 +204,67 @@ public class QpidBrokerTestCase extends QpidTestCase
}
private MessageType _messageType = MessageType.TEXT;
- public QpidBrokerTestCase(String name)
- {
- super(name);
- }
-
public QpidBrokerTestCase()
{
super();
+ _brokerConfigurations = new HashMap<Integer, TestBrokerConfiguration>();
+ initialiseLogConfigFile();
+ }
+
+ public TestBrokerConfiguration getBrokerConfiguration(int port)
+ {
+ int actualPort = getPort(port);
+
+ synchronized (_brokerConfigurations)
+ {
+ TestBrokerConfiguration configuration = _brokerConfigurations.get(actualPort);
+ if (configuration == null)
+ {
+ configuration = createBrokerConfiguration(actualPort);
+ }
+ return configuration;
+ }
+ }
+
+ public TestBrokerConfiguration getBrokerConfiguration()
+ {
+ return getBrokerConfiguration(DEFAULT_PORT);
+ }
+
+ public TestBrokerConfiguration createBrokerConfiguration(int port)
+ {
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = new TestBrokerConfiguration(System.getProperty(_brokerStoreType), _configFile.getAbsolutePath());
+ synchronized (_brokerConfigurations)
+ {
+ _brokerConfigurations.put(actualPort, configuration);
+ }
+ if (actualPort != DEFAULT_PORT)
+ {
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort);
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort));
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET);
+ }
+ return configuration;
+ }
+
+ private void initialiseLogConfigFile()
+ {
+ try
+ {
+ _logger.info("About to initialise log config file from system property: " + LOG4J_CONFIG_FILE_PATH);
+
+ URI uri = new URI("file", LOG4J_CONFIG_FILE_PATH, null);
+ _logConfigFile = new File(uri);
+ if(!_logConfigFile.exists())
+ {
+ throw new RuntimeException("Log config file " + _logConfigFile.getAbsolutePath() + " does not exist");
+ }
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException("Couldn't create URI from log4.configuration: " + LOG4J_CONFIG_FILE_PATH, e);
+ }
}
public Logger getLogger()
@@ -289,16 +356,6 @@ public class QpidBrokerTestCase extends QpidTestCase
fail("Unable to test without config file:" + _configFile);
}
- String existingQpidWorkPath = System.getProperty(BROKER_EXISTING_QPID_WORK);
- if(existingQpidWorkPath != null && !existingQpidWorkPath.equals(""))
- {
-
- String qpidWork = getQpidWork(_brokerType, getPort());
- File existing = new File(existingQpidWorkPath);
- cleanBrokerWork(qpidWork);
- FileUtils.copyRecursive(existing, new File(qpidWork));
- }
-
startBroker();
}
@@ -322,7 +379,7 @@ public class QpidBrokerTestCase extends QpidTestCase
{
Set<Integer> ports = new HashSet<Integer>();
int managementPort = getManagementPort(mainPort);
- int connectorServerPort = managementPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET;
+ int connectorServerPort = managementPort + JMXPORT_CONNECTORSERVER_OFFSET;
ports.add(mainPort);
ports.add(managementPort);
@@ -354,37 +411,33 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- protected String getBrokerCommand(int port) throws MalformedURLException
+ public void startBroker() throws Exception
{
- final int sslPort = port-1;
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
+ startBroker(0);
+ }
- return _brokerCommand
- .replace("@PORT", "" + port)
- .replace("@SSL_PORT", "" + sslPort)
- .replace("@MPORT", "" + getManagementPort(port))
- .replace("@CONFIG_FILE", _configFile.toString())
- .replace("@LOG_CONFIG_FILE", _logConfigFile.toString())
- .replace("@EXCLUDES", protocolExcludesList)
- .replace("@INCLUDES", protocolIncludesList);
+ public void startBroker(int port) throws Exception
+ {
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = getBrokerConfiguration(actualPort);
+ startBroker(actualPort, configuration, _testVirtualhosts);
}
- public void startBroker() throws Exception
+
+ protected File getBrokerCommandLog4JFile()
{
- startBroker(0);
+ return _logConfigFile;
}
- public void startBroker(int port) throws Exception
+ protected void setBrokerCommandLog4JFile(File file)
{
- startBroker(port, _testConfiguration, _testVirtualhosts);
+ _logConfigFile = file;
+ _logger.info("Modified log config file to: " + file);
}
- public void startBroker(int port, XMLConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
+ public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
{
port = getPort(port);
-
- // Save any configuration changes that have been made
String testConfig = saveTestConfiguration(port, testConfiguration);
String virtualHostsConfig = saveTestVirtualhosts(port, virtualHosts);
@@ -397,28 +450,20 @@ public class QpidBrokerTestCase extends QpidTestCase
if (_brokerType.equals(BrokerType.INTERNAL) && !existingInternalBroker())
{
- setConfigurationProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false));
- testConfig = saveTestConfiguration(port, testConfiguration);
- _logger.info("Set test.config property to: " + testConfig);
_logger.info("Set test.virtualhosts property to: " + virtualHostsConfig);
- setSystemProperty(TEST_CONFIG, testConfig);
setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
-
+ setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false");
BrokerOptions options = new BrokerOptions();
- options.setConfigFile(_configFile.getAbsolutePath());
- options.addPort(port);
-
- addExcludedPorts(port, DEFAULT_SSL_PORT, options);
- addIncludedPorts(port, DEFAULT_SSL_PORT, options);
- options.setJmxPortRegistryServer(getManagementPort(port));
+ options.setConfigurationStoreType(_brokerStoreType);
+ options.setConfigurationStoreLocation(testConfig);
//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(_logConfigFile.getAbsolutePath());
Broker broker = new Broker();
- _logger.info("starting internal broker (same JVM)");
+ _logger.info("Starting internal broker (same JVM)");
broker.startup(options);
_brokers.put(port, new InternalBrokerHolder(broker, System.getProperty("QPID_WORK"), portsUsedByBroker));
@@ -427,9 +472,10 @@ public class QpidBrokerTestCase extends QpidTestCase
{
// Add the port to QPID_WORK to ensure unique working dirs for multi broker tests
final String qpidWork = getQpidWork(_brokerType, port);
- String cmd = getBrokerCommand(port);
- _logger.info("starting external broker: " + cmd);
- ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+"));
+
+ String[] cmd = _brokerCommandHelper.getBrokerCommand(port, testConfig, _brokerStoreType, _logConfigFile);
+ _logger.info("Starting spawn broker using command: " + StringUtils.join(cmd, ' '));
+ ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Map<String, String> processEnv = pb.environment();
String qpidHome = System.getProperty(QPID_HOME);
@@ -459,28 +505,28 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
+ String qpidOpts = "";
- // Add default test logging levels that are used by the log4j-test
- // Use the convenience methods to push the current logging setting
- // in to the external broker's QPID_OPTS string.
- if (System.getProperty("amqj.protocol.logging.level") != null)
+ // a synchronized hack to avoid adding into QPID_OPTS the values
+ // of JVM properties "test.virtualhosts" and "test.config" set by a concurrent startup process
+ synchronized (_propertiesSetForBroker)
{
+ // Add default test logging levels that are used by the log4j-test
+ // Use the convenience methods to push the current logging setting
+ // in to the external broker's QPID_OPTS string.
setSystemProperty("amqj.protocol.logging.level");
- }
- if (System.getProperty("root.logging.level") != null)
- {
setSystemProperty("root.logging.level");
- }
-
- // set test.config and test.virtualhosts
- String qpidOpts = " -D" + TEST_CONFIG + "=" + testConfig + " -D" + TEST_VIRTUALHOSTS + "=" + virtualHostsConfig;
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES);
+ setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
- // Add all the specified system properties to QPID_OPTS
- if (!_propertiesSetForBroker.isEmpty())
- {
- for (String key : _propertiesSetForBroker.keySet())
+ // Add all the specified system properties to QPID_OPTS
+ if (!_propertiesSetForBroker.isEmpty())
{
- qpidOpts += " -D" + key + "=" + _propertiesSetForBroker.get(key);
+ for (String key : _propertiesSetForBroker.keySet())
+ {
+ qpidOpts += " -D" + key + "=" + _propertiesSetForBroker.get(key);
+ }
}
}
if (processEnv.containsKey("QPID_OPTS"))
@@ -489,9 +535,6 @@ public class QpidBrokerTestCase extends QpidTestCase
}
processEnv.put("QPID_OPTS", qpidOpts);
- _logger.info("Set test.config property to: " + testConfig);
- _logger.info("Set test.virtualhosts property to: " + virtualHostsConfig);
-
// cpp broker requires that the work directory is created
createBrokerWork(qpidWork);
@@ -505,9 +548,15 @@ public class QpidBrokerTestCase extends QpidTestCase
p.start();
+ SpawnedBrokerHolder holder = new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker);
if (!p.await(30, TimeUnit.SECONDS))
{
_logger.info("broker failed to become ready (" + p.getReady() + "):" + p.getStopLine());
+ String threadDump = holder.dumpThreads();
+ if (!threadDump.isEmpty())
+ {
+ _logger.info("the result of a try to capture thread dump:" + threadDump);
+ }
//Ensure broker has stopped
process.destroy();
cleanBrokerWork(qpidWork);
@@ -528,65 +577,7 @@ public class QpidBrokerTestCase extends QpidTestCase
// this is expect if the broker started successfully
}
- _brokers.put(port, new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker));
- }
- }
-
- private void addExcludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
-
- if (protocolExcludesList.equals(""))
- {
- return;
- }
- 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);
- }
- }
-
- protected String getProtocolExcludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_EXCLUDES,"").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private String getProtocolIncludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_INCLUDES, "").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private void addIncludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
-
- if (protocolIncludesList.equals(""))
- {
- return;
- }
- final String[] toks = protocolIncludesList.split("\\s");
-
- if(toks.length % 2 != 0)
- {
- throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolIncludesList + "'");
- }
- for (int i = 0; i < toks.length; i=i+2)
- {
- String includeArg = toks[i];
- final int includedPort = Integer.parseInt(toks[i+1]);
- options.addIncludedPort(ProtocolInclusion.lookup(includeArg), includedPort);
-
- _logger.info("Adding protocol inclusion " + includeArg + " " + includedPort);
+ _brokers.put(port, holder);
}
}
@@ -620,7 +611,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public String getTestConfigFile(int port)
{
- return _output + "/" + getTestQueueName() + "-" + port + "-config.xml";
+ return _output + "/" + getTestQueueName() + "-" + port + "-config";
}
public String getTestVirtualhostsFile(int port)
@@ -633,44 +624,33 @@ public class QpidBrokerTestCase extends QpidTestCase
return file.replace(System.getProperty(QPID_HOME,"QPID_HOME") + "/","");
}
- protected void saveTestConfiguration() throws ConfigurationException
+ protected String getPathRelativeToWorkingDirectory(String file)
{
- String relative = saveTestConfiguration(getPort(), _testConfiguration);
- _logger.info("Set test.config property to: " + relative);
- setSystemProperty(TEST_CONFIG, relative);
+ File configLocation = new File(file);
+ File workingDirectory = new File(System.getProperty("user.dir"));
+ return configLocation.getAbsolutePath().replace(workingDirectory.getAbsolutePath(), "").substring(1);
}
- protected String saveTestConfiguration(int port, XMLConfiguration testConfiguration) throws ConfigurationException
+ protected String saveTestConfiguration(int port, TestBrokerConfiguration testConfiguration)
{
- // Specify the test config file
String testConfig = getTestConfigFile(port);
- String relative = relativeToQpidHome(testConfig);
-
- _logger.info("Saving test virtualhosts file at: " + testConfig);
-
- // Create the file if configuration does not exist
- if (testConfiguration.isEmpty())
+ String relative = getPathRelativeToWorkingDirectory(testConfig);
+ if (!testConfiguration.isSaved())
{
- testConfiguration.addProperty("__ignore", "true");
+ _logger.info("Saving test broker configuration at: " + testConfig);
+ testConfiguration.save(new File(testConfig));
+ testConfiguration.setSaved(true);
}
- testConfiguration.save(testConfig);
return relative;
}
- protected void saveTestVirtualhosts() throws ConfigurationException
- {
- String relative = saveTestVirtualhosts(getPort(), _testVirtualhosts);
- _logger.info("Set test.virtualhosts property to: " + relative);
- setSystemProperty(TEST_VIRTUALHOSTS, relative);
- }
-
protected String saveTestVirtualhosts(int port, XMLConfiguration virtualHostConfiguration) throws ConfigurationException
{
// Specify the test virtualhosts file
String testVirtualhosts = getTestVirtualhostsFile(port);
String relative = relativeToQpidHome(testVirtualhosts);
- _logger.info("Set test.virtualhosts property to: " + testVirtualhosts);
+ _logger.info("Path to virtualhosts configuration: " + testVirtualhosts);
// Create the file if configuration does not exist
if (virtualHostConfiguration.isEmpty())
@@ -818,57 +798,41 @@ public class QpidBrokerTestCase extends QpidTestCase
}
/**
- * Attempt to set the Java Broker to use the BDBMessageStore for persistence
- * Falling back to the DerbyMessageStore if
- *
- * @param virtualhost - The virtualhost to modify
+ * Creates a new virtual host within the test virtualhost file.
+ * @param brokerPort broker port
+ * @param virtualHostName virtual host name
*
- * @throws ConfigurationException - when reading/writing existing configuration
- * @throws IOException - When creating a temporary file.
+ * @throws ConfigurationException
*/
- protected void makeVirtualHostPersistent(String virtualhost)
- throws ConfigurationException, IOException
+ protected void createTestVirtualHost(int brokerPort, String virtualHostName) throws ConfigurationException
{
- Class<?> storeClass = null;
- try
+ String storeClassName = getTestProfileMessageStoreClassName();
+
+ _testVirtualhosts.setProperty("virtualhost.name(-1)", virtualHostName);
+ _testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store.class", storeClassName);
+
+ String storeDir = null;
+
+ if (System.getProperty("profile", "").startsWith("java-dby-mem"))
{
- // Try and lookup the BDB class
- storeClass = Class.forName("org.apache.qpid.server.store.berkeleydb.BDBMessageStore");
+ storeDir = DerbyMessageStore.MEMORY_STORE_LOCATION;
}
- catch (ClassNotFoundException e)
+ else if (!MEMORY_STORE_CLASS_NAME.equals(storeClassName))
{
- // No BDB store, we'll use Derby instead.
- storeClass = DerbyMessageStore.class;
+ storeDir = "${QPID_WORK}" + File.separator + virtualHostName + "-store";
}
+ if (storeDir != null)
+ {
+ _testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, storeDir);
+ }
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".store.class",
- storeClass.getName());
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY,
- "${QPID_WORK}/" + virtualhost);
- }
-
- /**
- * 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
- {
- // Call save Configuration to be sure we have saved the test specific
- // file. As the optional status
- saveTestConfiguration();
- saveTestVirtualhosts();
-
- ServerConfiguration configuration = new ServerConfiguration(_configFile);
- // Don't need to configuration.configure() here as we are just pulling
- // values directly by String.
- return configuration.getConfig().getString(property);
+ // add new virtual host configuration to the broker store
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, virtualHostName);
+ attributes.put(VirtualHost.CONFIG_PATH, System.getProperty("broker.virtualhosts-config"));
+ int port = getPort(brokerPort);
+ getBrokerConfiguration(port).addHostConfiguration(attributes);
}
/**
@@ -884,10 +848,8 @@ public class QpidBrokerTestCase extends QpidTestCase
* @param value the new value
*
* @throws ConfigurationException when loading the current config file
- * @throws IOException when writing the new config file
*/
- public void setConfigurationProperty(String property, String value)
- throws ConfigurationException, IOException
+ public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException
{
// Choose which file to write the property to based on prefix.
if (property.startsWith("virtualhosts"))
@@ -896,7 +858,7 @@ public class QpidBrokerTestCase extends QpidTestCase
}
else
{
- _testConfiguration.setProperty(property, value);
+ throw new ConfigurationException("Cannot set broker configuration as property");
}
}
@@ -914,11 +876,13 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setBrokerOnlySystemProperty(String property, String value)
{
- if (!_propertiesSetForBroker.containsKey(property))
+ synchronized (_propertiesSetForBroker)
{
- _propertiesSetForBroker.put(property, value);
+ if (!_propertiesSetForBroker.containsKey(property))
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
}
-
}
/**
@@ -931,7 +895,11 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property)
{
- setSystemProperty(property, System.getProperty(property));
+ String value = System.getProperty(property);
+ if (value != null)
+ {
+ setSystemProperty(property, value);
+ }
}
/**
@@ -939,7 +907,7 @@ public class QpidBrokerTestCase extends QpidTestCase
*
* When the test run is complete the value will be reverted.
*
- * The values set using this method will also be propogated to the external
+ * The values set using this method will also be propagated to the external
* Java Broker via a -D value defined in QPID_OPTS.
*
* If the value should not be set on the broker then use
@@ -950,9 +918,18 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property, String value)
{
- // Record the value for the external broker
- _propertiesSetForBroker.put(property, value);
-
+ synchronized(_propertiesSetForBroker)
+ {
+ // Record the value for the external broker
+ if (value == null)
+ {
+ _propertiesSetForBroker.remove(property);
+ }
+ else
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
+ }
//Set the value for the test client vm aswell.
setTestClientSystemProperty(property, value);
}
@@ -1073,7 +1050,7 @@ public class QpidBrokerTestCase extends QpidTestCase
_logger.info("get ConnectionFactory");
if (_connectionFactory == null)
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (Boolean.getBoolean(PROFILE_USE_SSL))
{
_connectionFactory = getConnectionFactory("default.ssl");
}
@@ -1092,7 +1069,7 @@ public class QpidBrokerTestCase extends QpidTestCase
*
* @return A connection factory
*
- * @throws Exception if there is an error getting the tactory
+ * @throws Exception if there is an error getting the factory
*/
public AMQConnectionFactory getConnectionFactory(String factoryName) throws NamingException
{
@@ -1104,6 +1081,22 @@ public class QpidBrokerTestCase extends QpidTestCase
return getConnection(GUEST_USERNAME, GUEST_PASSWORD);
}
+ public Connection getConnectionWithOptions(Map<String, String> options)
+ throws URLSyntaxException, NamingException, JMSException
+ {
+ ConnectionURL curl = new AMQConnectionURL(getConnectionFactory().getConnectionURLString());
+ for(Map.Entry<String,String> entry : options.entrySet())
+ {
+ curl.setOption(entry.getKey(), entry.getValue());
+ }
+ curl = new AMQConnectionURL(curl.toString());
+
+ curl.setUsername(GUEST_USERNAME);
+ curl.setPassword(GUEST_PASSWORD);
+ return getConnection(curl);
+ }
+
+
public Connection getConnection(ConnectionURL url) throws JMSException
{
_logger.info(url.getURL());
@@ -1363,11 +1356,6 @@ public class QpidBrokerTestCase extends QpidTestCase
_messageSize = byteSize;
}
- public ConnectionURL getConnectionURL() throws NamingException
- {
- return getConnectionFactory().getConnectionURL();
- }
-
public BrokerDetails getBroker()
{
try
@@ -1390,31 +1378,6 @@ public class QpidBrokerTestCase extends QpidTestCase
return null;
}
- /**
- * Reloads the broker security configuration using the ApplicationRegistry (InVM brokers) or the
- * ConfigurationManagementMBean via the JMX interface (Standalone brokers, management must be
- * enabled before calling the method).
- */
- public void reloadBrokerSecurityConfig() throws Exception
- {
- JMXTestUtils jmxu = new JMXTestUtils(this);
- jmxu.open();
-
- try
- {
- ConfigurationManagement configMBean = jmxu.getConfigurationManagement();
- configMBean.reloadSecurityConfiguration();
- }
- finally
- {
- jmxu.close();
- }
-
- LogMonitor _monitor = new LogMonitor(_outputFile);
- assertTrue("The expected server security configuration reload did not occur",
- _monitor.waitForMessage(ServerConfiguration.SECURITY_CONFIG_RELOADED, LOGMONITOR_TIMEOUT));
- }
-
protected int getFailingPort()
{
return FAILING_PORT;
@@ -1430,13 +1393,14 @@ public class QpidBrokerTestCase extends QpidTestCase
_testVirtualhosts = testVirtualhosts;
}
- public XMLConfiguration getTestConfiguration()
+ public String getTestProfileMessageStoreType()
{
- return _testConfiguration;
+ final String storeClass = getTestProfileMessageStoreClassName();
+ if (storeClass == null)
+ {
+ return MemoryMessageStore.TYPE;
+ }
+ return supportedStoresClassToTypeMapping.get(storeClass);
}
- public void setTestConfiguration(XMLConfiguration testConfiguration)
- {
- _testConfiguration = testConfiguration;
- }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java
deleted file mode 100644
index 72003ed7d7..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- *
- * 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.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.JMSAMQException;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.Connection;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-/**
- * @todo This was originally cut and paste from the client module leading to a duplicate class, then altered very
- * slightly. To avoid the duplicate class the name was altered slightly to have 'Helper' on the end in order
- * to distinguish it from the original. Delete this class and use the original instead, just upgrade it to
- * provide the new features needed.
- */
-public class QpidClientConnectionHelper implements ExceptionListener
-{
-
- private static final Logger _logger = Logger.getLogger(QpidClientConnectionHelper.class);
-
- private boolean transacted = true;
- private int ackMode = Session.CLIENT_ACKNOWLEDGE;
- private Connection connection;
-
- private String virtualHost;
- private String brokerlist;
- private int prefetch;
- protected Session session;
- protected boolean connected;
-
- public QpidClientConnectionHelper(String broker)
- {
- super();
- setVirtualHost("/test");
- setBrokerList(broker);
- setPrefetch(5000);
- }
-
- public void connect() throws JMSException
- {
- if (!connected)
- {
- /*
- * amqp://[user:pass@][clientid]/virtualhost?
- * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
- * [&failover='method[?option='value'[&option='value']]']
- * [&option='value']"
- */
- String brokerUrl = "amqp://guest:guest@" + virtualHost + "?brokerlist='" + brokerlist + "'";
- try
- {
- AMQConnectionFactory factory = new AMQConnectionFactory(new AMQConnectionURL(brokerUrl));
- _logger.info("connecting to Qpid :" + brokerUrl);
- connection = factory.createConnection();
-
- // register exception listener
- connection.setExceptionListener(this);
-
- session = ((AMQConnection) connection).createSession(transacted, ackMode, prefetch);
-
- _logger.info("starting connection");
- connection.start();
-
- connected = true;
- }
- catch (URLSyntaxException e)
- {
- throw new JMSAMQException("URL syntax error in [" + brokerUrl + "]: " + e.getMessage(), e);
- }
- }
- }
-
- public void disconnect() throws JMSException
- {
- if (connected)
- {
- session.commit();
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected");
- }
- }
-
- public void disconnectWithoutCommit() throws JMSException
- {
- if (connected)
- {
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected without commit");
- }
- }
-
- public String getBrokerList()
- {
- return brokerlist;
- }
-
- public void setBrokerList(String brokerlist)
- {
- this.brokerlist = brokerlist;
- }
-
- public String getVirtualHost()
- {
- return virtualHost;
- }
-
- public void setVirtualHost(String virtualHost)
- {
- this.virtualHost = virtualHost;
- }
-
- public void setPrefetch(int prefetch)
- {
- this.prefetch = prefetch;
- }
-
- /** override as necessary */
- public void onException(JMSException exception)
- {
- _logger.info("ExceptionListener event: error " + exception.getErrorCode() + ", message: " + exception.getMessage());
- }
-
- public boolean isConnected()
- {
- return connected;
- }
-
- public Session getSession()
- {
- return session;
- }
-
- /**
- * Put a String as a text messages, repeat n times. A null payload will result in a null message.
- *
- * @param queueName The queue name to put to
- * @param payload the content of the payload
- * @param copies the number of messages to put
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public void put(String queueName, String payload, int copies, int deliveryMode) throws JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("putting to queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageProducer sender = session.createProducer(queue);
-
- sender.setDeliveryMode(deliveryMode);
-
- for (int i = 0; i < copies; i++)
- {
- Message m = session.createTextMessage(payload + i);
- m.setIntProperty("index", i + 1);
- sender.send(m);
- }
-
- session.commit();
- sender.close();
- _logger.info("put " + copies + " copies");
- }
-
- /**
- * GET the top message on a queue. Consumes the message. Accepts timeout value.
- *
- * @param queueName The quename to get from
- * @param readTimeout The timeout to use
- *
- * @return the content of the text message if any
- *
- * @throws javax.jms.JMSException any exception that occured
- */
- public Message getNextMessage(String queueName, long readTimeout) throws JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
-
- Message message = consumer.receive(readTimeout);
- session.commit();
- consumer.close();
-
- Message result;
-
- // all messages we consume should be TextMessages
- if (message instanceof TextMessage)
- {
- result = ((TextMessage) message);
- }
- else if (null == message)
- {
- result = null;
- }
- else
- {
- _logger.info("warning: received non-text message");
- result = message;
- }
-
- return result;
- }
-
- /**
- * GET the top message on a queue. Consumes the message.
- *
- * @param queueName The Queuename to get from
- *
- * @return The string content of the text message, if any received
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public Message getNextMessage(String queueName) throws JMSException
- {
- return getNextMessage(queueName, 0);
- }
-
- /**
- * Completely clears a queue. For readTimeout behaviour see Javadocs for javax.jms.MessageConsumer.
- *
- * @param queueName The Queue name to consume from
- * @param readTimeout The timeout for each consume
- *
- * @throws javax.jms.JMSException Any exception that occurs during the consume
- * @throws InterruptedException If the consume thread was interrupted during a consume.
- */
- public void consume(String queueName, int readTimeout) throws JMSException, InterruptedException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("consuming queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
- int messagesReceived = 0;
-
- _logger.info("consuming...");
- while ((consumer.receive(readTimeout)) != null)
- {
- messagesReceived++;
- }
-
- session.commit();
- consumer.close();
- _logger.info("consumed: " + messagesReceived);
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
new file mode 100644
index 0000000000..80f8010678
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
@@ -0,0 +1,219 @@
+/*
+ *
+ * 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 java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class TestBrokerConfiguration
+{
+ public static final String ENTRY_NAME_HTTP_PORT = "http";
+ public static final String ENTRY_NAME_AMQP_PORT = "amqp";
+ public static final String ENTRY_NAME_RMI_PORT = "rmi";
+ public static final String ENTRY_NAME_JMX_PORT = "jmx";
+ public static final String ENTRY_NAME_VIRTUAL_HOST = "test";
+ public static final String ENTRY_NAME_AUTHENTICATION_PROVIDER = "plain";
+ public static final String ENTRY_NAME_EXTERNAL_PROVIDER = "external";
+ public static final String ENTRY_NAME_SSL_PORT = "sslPort";
+ public static final String ENTRY_NAME_HTTP_MANAGEMENT = "MANAGEMENT-HTTP";
+ public static final String MANAGEMENT_HTTP_PLUGIN_TYPE = "MANAGEMENT-HTTP";
+ public static final String ENTRY_NAME_JMX_MANAGEMENT = "MANAGEMENT-JMX";
+ public static final String MANAGEMENT_JMX_PLUGIN_TYPE = "MANAGEMENT-JMX";
+ public static final String ENTRY_NAME_ANONYMOUS_PROVIDER = "anonymous";
+
+ private JsonConfigurationEntryStore _store;
+ private boolean _saved;
+
+ public TestBrokerConfiguration(String storeType, String intialStoreLocation)
+ {
+ // TODO: add support for DERBY store
+ _store = new JsonConfigurationEntryStore();
+ _store.open(JsonConfigurationEntryStore.IN_MEMORY, intialStoreLocation);
+ }
+
+ public boolean setBrokerAttribute(String name, Object value)
+ {
+ return setObjectAttribute(_store.getRootEntry(), name, value);
+ }
+
+ public boolean setObjectAttribute(String objectName, String attributeName, Object value)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttribute(entry, attributeName, value);
+ }
+
+ public boolean setObjectAttributes(String objectName, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttributes(entry, attributes);
+ }
+
+ public boolean save(File configFile)
+ {
+ _store.copyTo(configFile.getAbsolutePath());
+ return true;
+ }
+
+ public UUID[] removeObjectConfiguration(String name)
+ {
+ ConfigurationEntry entry = findObjectByName(name);
+ if (entry != null)
+ {
+ return _store.remove(entry.getId());
+ }
+ return null;
+ }
+
+ public UUID addObjectConfiguration(String name, String type, Map<String, Object> attributes)
+ {
+ UUID id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ addObjectConfiguration(id, type, attributes);
+ return id;
+ }
+
+ public UUID addJmxManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_JMX_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_JMX_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_JMX_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHttpManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_HTTP_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_HTTP_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addPortConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(Port.NAME);
+ return addObjectConfiguration(name, Port.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHostConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(VirtualHost.NAME);
+ return addObjectConfiguration(name, VirtualHost.class.getSimpleName(), attributes);
+ }
+
+ public UUID addAuthenticationProviderConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(AuthenticationProvider.NAME);
+ return addObjectConfiguration(name, AuthenticationProvider.class.getSimpleName(), attributes);
+ }
+
+ private boolean setObjectAttributes(ConfigurationEntry entry, Map<String, Object> attributes)
+ {
+ Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes());
+ newAttributes.putAll(attributes);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes,
+ entry.getChildrenIds(), _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ private ConfigurationEntry findObjectByName(String objectName)
+ {
+ ConfigurationEntry root = _store.getRootEntry();
+ return findObjectByName(root, objectName);
+ }
+
+ private ConfigurationEntry findObjectByName(ConfigurationEntry entry, String objectName)
+ {
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null)
+ {
+ String name = (String) attributes.get("name");
+ if (objectName.equals(name))
+ {
+ return entry;
+ }
+ }
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ for (UUID uuid : childrenIds)
+ {
+ ConfigurationEntry child = _store.getEntry(uuid);
+ ConfigurationEntry result = findObjectByName(child, objectName);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), _store);
+ ConfigurationEntry root = _store.getRootEntry();
+ Set<UUID> childrenIds = new HashSet<UUID>(root.getChildrenIds());
+ childrenIds.add(id);
+ ConfigurationEntry newRoot = new ConfigurationEntry(root.getId(), root.getType(), root.getAttributes(), childrenIds,
+ _store);
+ _store.save(newRoot, entry);
+ }
+
+ private boolean setObjectAttribute(ConfigurationEntry entry, String attributeName, Object value)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes());
+ attributes.put(attributeName, value);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, entry.getChildrenIds(),
+ _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ public boolean isSaved()
+ {
+ return _saved;
+ }
+
+ public void setSaved(boolean saved)
+ {
+ _saved = saved;
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
new file mode 100644
index 0000000000..9d5be775dc
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
@@ -0,0 +1,30 @@
+/*
+ * 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 TestSSLConstants
+{
+ String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks";
+ String KEYSTORE_PASSWORD = "password";
+ String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
+ String TRUSTSTORE_PASSWORD = "password";
+
+ String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks";
+ String BROKER_KEYSTORE_PASSWORD = "password";
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java
new file mode 100644
index 0000000000..c651d3ec7f
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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 java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+public class TestUtils
+{
+ public static String dumpThreads()
+ {
+ ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
+ StringBuilder dump = new StringBuilder();
+ dump.append(String.format("%n"));
+ for (ThreadInfo threadInfo : threadInfos)
+ {
+ dump.append(threadInfo);
+ }
+
+ long[] deadLocks = threadMXBean.findDeadlockedThreads();
+ if (deadLocks != null && deadLocks.length > 0)
+ {
+ ThreadInfo[] deadlockedThreads = threadMXBean.getThreadInfo(deadLocks);
+ dump.append(String.format("%n"));
+ dump.append("Deadlock is detected!");
+ dump.append(String.format("%n"));
+ for (ThreadInfo threadInfo : deadlockedThreads)
+ {
+ dump.append(threadInfo);
+ }
+ }
+ return dump.toString();
+ }
+}