summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-01-09 18:13:14 +0000
committerAlex Rudyy <orudyy@apache.org>2013-01-09 18:13:14 +0000
commit0c5369f37f4e075fbf107bceb1d794594c2330c7 (patch)
treead8023c5991c13b4d56163a2880bafd6cc4c8e12
parent8919b7d7c60f60a91c6f38534cd75cb51488d87f (diff)
downloadqpid-python-0c5369f37f4e075fbf107bceb1d794594c2330c7.tar.gz
QPID-4390: Add configuration store factory
Use default store type if store type is not set Copy initial json configuration for json store instead of merging Remove MerginStore git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-config-qpid-4390@1430996 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerLauncher.java11
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java16
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java66
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactory.java111
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java35
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandler.java6
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java84
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java127
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java86
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java43
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java59
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory19
-rw-r--r--qpid/java/broker/src/main/resources/default.json8
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java (renamed from qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactoryTest.java)39
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java10
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandlerTest.java3
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java6
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java239
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java5
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java27
22 files changed, 336 insertions, 670 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerLauncher.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerLauncher.java
index 07b160f91d..ccb4f77cb1 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerLauncher.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerLauncher.java
@@ -31,7 +31,7 @@ import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
-import org.apache.qpid.server.configuration.ConfigurationEntryStoreFactory;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
@@ -112,13 +112,14 @@ public class BrokerLauncher
String storeType = options.getConfigurationStoreType();
//TODO: remove code below. A temporarily support for old configuration file option
- if (storeLocation == null && storeType == null && options.getConfigFile() != null)
+ if (storeLocation == null)
{
storeLocation = options.getConfigFile();
}
+
if (storeLocation == null)
{
- storeLocation = new File(qpidHome, BrokerOptions.DEFAULT_CONFIG_FILE).getAbsolutePath();
+ storeLocation = new File(qpidHome, BrokerOptions.DEFAULT_CONFIG_FILE + "." + storeType).getAbsolutePath();
}
CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation));
@@ -126,8 +127,8 @@ public class BrokerLauncher
File logConfigFile = getConfigFile(options.getLogConfigFile(), BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
configureLogging(logConfigFile, options.getLogWatchFrequency());
- ConfigurationEntryStoreFactory storeFactory = new ConfigurationEntryStoreFactory();
- ConfigurationEntryStore store = storeFactory.createStore(storeLocation, storeType, options);
+ BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator();
+ ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType, options);
_applicationRegistry = new ApplicationRegistry(store);
try
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
index ec540473d2..0223968179 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
@@ -28,7 +28,8 @@ import java.util.Set;
public class BrokerOptions
{
- public static final String DEFAULT_CONFIG_FILE = "etc/config.json";
+ public static final String DEFAULT_STORE_TYPE = "xml";
+ public static final String DEFAULT_CONFIG_FILE = "etc/config";
public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml";
public static final String QPID_HOME = "QPID_HOME";
public static final String QPID_WORK = "QPID_WORK";
@@ -50,8 +51,7 @@ public class BrokerOptions
private String _qpidHomeFolder;
private String _configurationStoreLocation;
- private String _configurationStoreType;
- private boolean _noDefaultConfiguration;
+ private String _configurationStoreType = DEFAULT_STORE_TYPE;
public void addPort(final int port)
{
@@ -212,14 +212,4 @@ public class BrokerOptions
_configurationStoreType = cofigurationStoreType;
}
- public boolean isNoDefaultConfiguration()
- {
- return _noDefaultConfiguration;
- }
-
- public void setNoDefaultConfiguration(boolean noDefault)
- {
- _noDefaultConfiguration = noDefault;
- }
-
} \ No newline at end of file
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 5a81515040..4803145f8f 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
@@ -49,9 +49,6 @@ public class Main
private static final Option OPTION_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg()
.withDescription("use given store type").withLongOpt("store-type").create("st");
- private static final Option OPTION_CONFIGURATION_STORE_NO_DEFAULTS = OptionBuilder.withType(Boolean.class)
- .withDescription("disables default configuration if set to true").withLongOpt("no-defaults").create("nd");
-
@Deprecated
private static final Option OPTION_CONFIG_FILE =
OptionBuilder.withArgName("file").hasArg().withDescription("use given configuration file").withLongOpt("config")
@@ -153,7 +150,6 @@ private static final Option OPTION_INCLUDE_0_8 =
OPTIONS.addOption(OPTION_VERSION);
OPTIONS.addOption(OPTION_CONFIGURATION_STORE_PATH);
OPTIONS.addOption(OPTION_CONFIGURATION_STORE_TYPE);
- OPTIONS.addOption(OPTION_CONFIGURATION_STORE_NO_DEFAULTS);
OPTIONS.addOption(OPTION_CONFIG_FILE);
OPTIONS.addOption(OPTION_LOG_CONFIG_FILE);
OPTIONS.addOption(OPTION_LOG_WATCH);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
new file mode 100644
index 0000000000..9ffa2ac158
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.store.CommandLineOptionsHandler;
+import org.apache.qpid.server.configuration.store.XMLConfigurationEntryStore;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class BrokerConfigurationStoreCreator
+{
+ /**
+ * Path to resource containing broker default configuration
+ */
+ public static final String INITIAL_STORE_LOCATION = "default.json";
+
+ /**
+ * Create broker configuration store for given store location, store type
+ * and command line options
+ */
+ public ConfigurationEntryStore createStore(String storeLocation, String storeType, BrokerOptions options)
+ {
+ ConfigurationEntryStore store = null;
+ if ("xml".equalsIgnoreCase(storeType))
+ {
+ store = new XMLConfigurationEntryStore(options);
+ store.open(storeLocation);
+ return store;
+ }
+ QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>();
+ Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader.instancesOf(ConfigurationStoreFactory.class);
+ for (ConfigurationStoreFactory storeFactory : configurationStoreFactories)
+ {
+ if (storeFactory.getStoreType().equals(storeType))
+ {
+ store = storeFactory.createStore();
+ break;
+ }
+ }
+ if (store == null)
+ {
+ throw new IllegalConfigurationException("Cannot create store for the type " + storeType);
+ }
+ store.open(storeLocation);
+ return new CommandLineOptionsHandler(options, store);
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
index 7dcc23a534..08736c36f1 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
@@ -24,6 +24,8 @@ import java.util.UUID;
public interface ConfigurationEntryStore
{
+ void open(String storeLocation);
+
ConfigurationEntry getRootEntry();
ConfigurationEntry getEntry(UUID id);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactory.java
deleted file mode 100644
index 1f70b4e5b9..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactory.java
+++ /dev/null
@@ -1,111 +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.server.configuration;
-
-import java.io.File;
-import java.net.URL;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.BrokerOptions;
-import org.apache.qpid.server.configuration.store.CommandLineOptionsHandler;
-import org.apache.qpid.server.configuration.store.MergingStore;
-import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
-import org.apache.qpid.server.configuration.store.XMLConfigurationEntryStore;
-
-public class ConfigurationEntryStoreFactory
-{
- /**
- * Path to resource containing broker default configuration
- */
- public static final String DEFAULTS = "default.json";
-
- /**
- * Create broker configuration store for given store location, store type
- * and command line options
- */
- public ConfigurationEntryStore createStore(String storeLocation, String storeType, BrokerOptions options)
- {
- ConfigurationEntryStoreType type = ConfigurationEntryStoreType.getType(storeType, storeLocation);
- ConfigurationEntryStore store = null;
- switch (type)
- {
- case JSON:
- store = new JsonConfigurationEntryStore(new File(storeLocation));
- break;
- case XML:
- try
- {
- return new XMLConfigurationEntryStore(new File(storeLocation), options);
- }
- catch (ConfigurationException e)
- {
- throw new IllegalConfigurationException("Unexpected error", e);
- }
- case DERBY:
- default:
- throw new IllegalConfigurationException("Unsupported store type " + type);
- }
-
- if (!options.isNoDefaultConfiguration())
- {
- URL defaultStoreLocation = ConfigurationEntryStoreFactory.class.getClassLoader().getResource(DEFAULTS);
- store = new MergingStore(store, new JsonConfigurationEntryStore(defaultStoreLocation));
- }
-
- return new CommandLineOptionsHandler(options, store);
- }
-
- public static enum ConfigurationEntryStoreType
- {
- JSON, XML, DERBY;
-
- public static ConfigurationEntryStoreType getType(String storeType, String storeLocation)
- {
- ConfigurationEntryStoreType type = null;
- if (storeType == null)
- {
- if (storeLocation != null)
- {
- // define type from file extension
- String lower = storeLocation.toLowerCase();
- if (lower.endsWith(".json"))
- {
- type = ConfigurationEntryStoreType.JSON;
- }
- else if (lower.endsWith(".xml"))
- {
- type = ConfigurationEntryStoreType.XML;
- }
- }
- if (type == null)
- {
- // default is JSON
- type = ConfigurationEntryStoreType.JSON;
- }
- }
- else
- {
- type = ConfigurationEntryStoreType.valueOf(storeType.toUpperCase());
- }
- return type;
- }
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
new file mode 100644
index 0000000000..dced38d260
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.configuration;
+
+
+public interface ConfigurationStoreFactory
+{
+ /**
+ * Returns the type of the store this factory can create
+ */
+ public String getStoreType();
+
+ /**
+ * Creates the store instance.
+ */
+ public ConfigurationEntryStore createStore();
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandler.java
index ad242250f5..0303012265 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandler.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandler.java
@@ -593,4 +593,10 @@ public class CommandLineOptionsHandler implements ConfigurationEntryStore
}
}
+
+ @Override
+ public void open(String storeLocation)
+ {
+
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
index 19f8652972..8cdf949d78 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
@@ -4,6 +4,7 @@ import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -20,9 +21,11 @@ import java.util.UUID;
import org.apache.qpid.server.configuration.ConfigurationEntry;
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.util.FileUtils;
import org.apache.qpid.util.Strings;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonNode;
@@ -45,7 +48,7 @@ public class JsonConfigurationEntryStore implements ConfigurationEntryStore
private File _storeFile;
private UUID _rootId;
- private JsonConfigurationEntryStore()
+ public JsonConfigurationEntryStore()
{
_objectMapper = new ObjectMapper();
_objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
@@ -61,30 +64,47 @@ public class JsonConfigurationEntryStore implements ConfigurationEntryStore
_rootId = brokerEntry.getId();
}
- public JsonConfigurationEntryStore(File storeFile)
+ @Override
+ public void open(String storeLocation)
{
- this();
- _storeFile = storeFile;
- if (_storeFile.exists())
+ _storeFile = new File(storeLocation);
+ if (!_storeFile.exists() || _storeFile.length() == 0)
{
- if (_storeFile.length() > 0)
- {
- URL storeURL = fileToURL(_storeFile);
- JsonNode node = load(storeURL, _objectMapper);
- ConfigurationEntry brokerEntry = toEntry(node, true, _entries);
- _rootId = brokerEntry.getId();
- }
+ copyInitialStore();
}
- else
+
+ URL storeURL = fileToURL(_storeFile);
+ JsonNode node = load(storeURL, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, true, _entries);
+ _rootId = brokerEntry.getId();
+
+ }
+
+ private void copyInitialStore()
+ {
+ InputStream in = null;
+ try
{
- createStoreFile(_storeFile);
+ in = JsonConfigurationEntryStore.class.getClassLoader().getResourceAsStream(BrokerConfigurationStoreCreator.INITIAL_STORE_LOCATION);
+ FileUtils.copy(in, _storeFile);
}
-
- if (_rootId == null)
+ catch (IOException e)
{
- _rootId = createUUID(DEFAULT_BROKER_TYPE, DEFAULT_BROKER_NAME);
- ConfigurationEntry brokerEntry = new ConfigurationEntry(_rootId, DEFAULT_BROKER_TYPE, null, null, null);
- save(brokerEntry);
+ throw new IllegalConfigurationException("Cannot create store file by copying initial store", e);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close initial store input stream", e);
+ }
+ }
}
}
@@ -163,29 +183,6 @@ public class JsonConfigurationEntryStore implements ConfigurationEntryStore
saveAsTree(_rootId, _entries, _objectMapper, file);
}
- private void createStoreFile(File storeFile)
- {
- File parent = storeFile.getParentFile();
- if (!parent.exists())
- {
- if (!parent.mkdirs())
- {
- throw new IllegalConfigurationException("Cannot create folder(s) for the store at " + _storeFile);
- }
- }
- try
- {
- if (!storeFile.createNewFile())
- {
- throw new IllegalConfigurationException("Cannot create store file at " + _storeFile);
- }
- }
- catch (IOException e)
- {
- throw new IllegalConfigurationException("Cannot write into file at " + _storeFile, e);
- }
- }
-
private URL fileToURL(File storeFile)
{
URL storeURL = null;
@@ -349,7 +346,8 @@ public class JsonConfigurationEntryStore implements ConfigurationEntryStore
}
if (fieldValues != null)
{
- attributes.put(fieldName, fieldValues);
+ Object[] array = fieldValues.toArray(new Object[fieldValues.size()]);
+ attributes.put(fieldName, array);
}
}
else if (fieldNode.isObject())
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java
deleted file mode 100644
index 749b74a7db..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java
+++ /dev/null
@@ -1,127 +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.server.configuration.store;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-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.ConfigurationEntryStore;
-
-/**
- * A store implementation which is responsible for copying the configuration
- * from the master store into a user store if the configuration entries with the
- * same name do not exist in the user store.
- */
-public class MergingStore implements ConfigurationEntryStore
-{
- private final ConfigurationEntryStore _userStore;
-
- public MergingStore(ConfigurationEntryStore userStore, ConfigurationEntryStore masterStore)
- {
- mergeAndSave(userStore, masterStore);
- _userStore = userStore;
- }
-
- @Override
- public ConfigurationEntry getRootEntry()
- {
- return _userStore.getRootEntry();
- }
-
- @Override
- public ConfigurationEntry getEntry(UUID id)
- {
- return _userStore.getEntry(id);
- }
-
- @Override
- public void save(ConfigurationEntry... entries)
- {
- _userStore.save(entries);
- }
-
- @Override
- public UUID[] remove(UUID... entryIds)
- {
- return _userStore.remove(entryIds);
- }
-
- private void mergeAndSave(ConfigurationEntryStore userStore, ConfigurationEntryStore masterStore)
- {
- ConfigurationEntry masterRoot = masterStore.getRootEntry();
- Set<UUID> masterRootChildren = masterRoot.getChildrenIds();
-
- ConfigurationEntry userRoot = userStore.getRootEntry();
- Map<String, Collection<ConfigurationEntry>> userRootChildren = userRoot.getChildren();
-
- List<ConfigurationEntry> entriesToSave = new ArrayList<ConfigurationEntry>();
- Set<UUID> userRootNewChildren = new HashSet<UUID>();
- for (UUID uuid : masterRootChildren)
- {
- ConfigurationEntry masterEntry = masterStore.getEntry(uuid);
- String masterEntryName = (String) masterEntry.getAttributes().get(ConfigurationEntry.ATTRIBUTE_NAME);
- Collection<ConfigurationEntry> userEntriesOfTheSameType = userRootChildren.get(masterEntry.getType().toString());
- boolean found = false;
- if (userEntriesOfTheSameType != null && !userEntriesOfTheSameType.isEmpty())
- {
- for (ConfigurationEntry entry : userEntriesOfTheSameType)
- {
- Map<String, Object> attributes = entry.getAttributes();
- if (attributes != null && masterEntryName.equals(attributes.get(ConfigurationEntry.ATTRIBUTE_NAME)))
- {
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- entriesToSave.add(masterEntry);
- userRootNewChildren.add(masterEntry.getId());
- }
- }
-
- Map<String, Object> userRootAttributes = userRoot.getAttributes();
- boolean noUserStoreRootAttributes = userRootAttributes == null || userRootAttributes.isEmpty();
- if (noUserStoreRootAttributes || !userRootNewChildren.isEmpty())
- {
- Set<UUID> currentUserStoreRootChildrenIds = userRoot.getChildrenIds();
- if (currentUserStoreRootChildrenIds != null)
- {
- userRootNewChildren.addAll(currentUserStoreRootChildrenIds);
- }
- Map<String, Object> newAttributes = noUserStoreRootAttributes ? masterRoot.getAttributes() : userRootAttributes;
- entriesToSave.add(new ConfigurationEntry(userRoot.getId(), userRoot.getType(), newAttributes, userRootNewChildren,
- userStore));
- }
- if (!entriesToSave.isEmpty())
- {
- userStore.save(entriesToSave.toArray(new ConfigurationEntry[entriesToSave.size()]));
- }
- }
-
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java
index e645263cdd..d4b6d18a0d 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java
@@ -73,52 +73,38 @@ public class XMLConfigurationEntryStore implements ConfigurationEntryStore
private HierarchicalConfiguration _configuration;
private Map<UUID, ConfigurationEntry> _rootChildren;
private ServerConfiguration _serverConfiguration;
-
+ private BrokerOptions _options;
private PortConfigurationHelper _portConfigurationHelper;
- public XMLConfigurationEntryStore(File configFile) throws ConfigurationException
- {
- this(new ServerConfiguration(configFile), new BrokerOptions());
- }
-
- public XMLConfigurationEntryStore(String configFile, BrokerOptions options) throws ConfigurationException
+ public XMLConfigurationEntryStore()
{
- this(new ServerConfiguration(new File(configFile)), options);
+ this(new BrokerOptions());
}
- public XMLConfigurationEntryStore(File configFile, BrokerOptions options) throws ConfigurationException
+ public XMLConfigurationEntryStore(BrokerOptions options)
{
- this(new ServerConfiguration(configFile), options);
+ _options = options;
}
- public XMLConfigurationEntryStore(ServerConfiguration config, BrokerOptions options) throws ConfigurationException
+ @Override
+ public void open(String storeLocation)
{
- _serverConfiguration = config;
- _serverConfiguration.initialise();
-
- _configuration = ConfigurationUtils.convertToHierarchical(config.getConfig());
- _rootId = UUID.randomUUID();
- _rootChildren = new HashMap<UUID, ConfigurationEntry>();
- _portConfigurationHelper = new PortConfigurationHelper(this);
-
- updateManagementPorts(_serverConfiguration, options);
-
- createKeyStoreConfig(config, _rootChildren);
- createTrustStoreConfig(config, _rootChildren);
- createGroupProviderConfig(_configuration, _rootChildren);
- createAuthenticationProviderConfig(_configuration, _rootChildren);
- createAmqpPortConfig(_serverConfiguration, _rootChildren, options);
- createManagementPortConfig(_serverConfiguration, _rootChildren, options);
- createVirtualHostConfig(_serverConfiguration, _rootChildren);
-
- // In order to avoid plugin recoverer failures for broker tests we are checking whether plugins classes are present in classpath
- Iterable<PluginFactory> factories= new QpidServiceLoader().instancesOf(PluginFactory.class);
- if (factories.iterator().hasNext())
+ try
{
- createHttpManagementConfig(_serverConfiguration, _rootChildren);
- createJmxManagementConfig(_serverConfiguration, _rootChildren);
+ _serverConfiguration = new ServerConfiguration(new File(storeLocation));
+ }
+ catch (ConfigurationException e)
+ {
+ throw new IllegalConfigurationException("Cannot create store from " + storeLocation, e);
+ }
+ try
+ {
+ openStore(_serverConfiguration, _options);
+ }
+ catch (ConfigurationException e)
+ {
+ throw new IllegalConfigurationException("Cannot open store from " + storeLocation, e);
}
- _logger.warn("Root children are: " + _rootChildren);
}
@Override
@@ -479,4 +465,34 @@ public class XMLConfigurationEntryStore implements ConfigurationEntryStore
return _serverConfiguration;
}
+ private void openStore(ServerConfiguration config, BrokerOptions options) throws ConfigurationException
+ {
+ _serverConfiguration = config;
+ _serverConfiguration.initialise();
+
+ _configuration = ConfigurationUtils.convertToHierarchical(config.getConfig());
+ _rootId = UUID.randomUUID();
+ _rootChildren = new HashMap<UUID, ConfigurationEntry>();
+ _portConfigurationHelper = new PortConfigurationHelper(this);
+
+ updateManagementPorts(_serverConfiguration, options);
+
+ createKeyStoreConfig(config, _rootChildren);
+ createTrustStoreConfig(config, _rootChildren);
+ createGroupProviderConfig(_configuration, _rootChildren);
+ createAuthenticationProviderConfig(_configuration, _rootChildren);
+ createAmqpPortConfig(_serverConfiguration, _rootChildren, options);
+ createManagementPortConfig(_serverConfiguration, _rootChildren, options);
+ createVirtualHostConfig(_serverConfiguration, _rootChildren);
+
+ // In order to avoid plugin recoverer failures for broker tests we are checking whether plugins classes are present in classpath
+ Iterable<PluginFactory> factories= new QpidServiceLoader().instancesOf(PluginFactory.class);
+ if (factories.iterator().hasNext())
+ {
+ createHttpManagementConfig(_serverConfiguration, _rootChildren);
+ createJmxManagementConfig(_serverConfiguration, _rootChildren);
+ }
+ _logger.warn("Root children are: " + _rootChildren);
+ }
+
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
new file mode 100644
index 0000000000..a2664219bc
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.configuration.store.factory;
+
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfigurationStoreFactory;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+
+public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory
+{
+ private static final String STORE_TYPE = "json";
+
+ @Override
+ public ConfigurationEntryStore createStore()
+ {
+ return new JsonConfigurationEntryStore();
+ }
+
+ @Override
+ public String getStoreType()
+ {
+ return STORE_TYPE;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
index 9b9b4cd9af..a87d7745d6 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.util;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
@@ -197,58 +198,50 @@ public class MapValueConverter
}
@SuppressWarnings("unchecked")
- public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String,Object> attributes, Class<T> clazz)
+ public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String, Object> attributes, Class<T> clazz)
{
Object obj = attributes.get(name);
- String[] items= null;
- if(obj == null)
+ Object[] items = null;
+ if (obj == null)
{
return null;
}
- else if(obj instanceof Set)
- {
- Set<?> data= (Set<?>) obj;
- items = new String[data.size()];
- int i = 0;
- boolean sameType = true;
- for (Object object : data)
- {
- items[i++] = String.valueOf(object);
- if (clazz != object.getClass())
- {
- sameType = false;
- }
- }
- if (sameType)
- {
- return (Set<T>)data;
- }
- }
- else if (obj instanceof String)
+ else if (obj instanceof Collection)
{
- items = ((String)obj).split(",");
+ Collection<?> data = (Collection<?>) obj;
+ items = data.toArray(new Object[data.size()]);
}
else if (obj instanceof String[])
{
- items = (String[])obj;
+ items = (String[]) obj;
}
else if (obj instanceof Object[])
{
- Object[] objects = (Object[])obj;
- items = new String[objects.length];
- for (int i = 0; i < objects.length; i++)
- {
- items[i] = String.valueOf(objects[i]);
- }
+ items = (Object[]) obj;
}
else
{
- throw new IllegalArgumentException("Value for attribute " + name + "["+ obj + "] cannot be converted into set of enum of " + clazz);
+ throw new IllegalArgumentException("Value for attribute " + name + "[" + obj
+ + "] cannot be converted into set of enum of " + clazz);
}
Set<T> set = new HashSet<T>();
for (int i = 0; i < items.length; i++)
{
- T item = (T)Enum.valueOf(clazz, items[i]);
+ T item = null;
+ Object value = items[i];
+ if (value instanceof String)
+ {
+ item = (T) Enum.valueOf(clazz, (String) value);
+ }
+ else if (clazz.isInstance(value))
+ {
+ item = (T) value;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert " + value + " from [" + obj + "] into enum of " + clazz
+ + " for attribute " + name);
+ }
set.add(item);
}
return set;
diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
new file mode 100644
index 0000000000..5f75a8c4c9
--- /dev/null
+++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.configuration.store.factory.JsonConfigurationStoreFactory
diff --git a/qpid/java/broker/src/main/resources/default.json b/qpid/java/broker/src/main/resources/default.json
index 12ea68b5cb..db82508b55 100644
--- a/qpid/java/broker/src/main/resources/default.json
+++ b/qpid/java/broker/src/main/resources/default.json
@@ -46,13 +46,13 @@
} ],
"ports" : [ {
"type" : "Port",
- "name" : "defaultHttpPort",
+ "name" : "8080",
"port" : 8080,
"transports" : [ "TCP" ],
"protocols" : [ "HTTP" ]
}, {
"type" : "Port",
- "name" : "defaultAmqpPort",
+ "name" : "5672",
"port" : 5672,
"tcpNoDelay" : true,
"transports" : [ "TCP" ],
@@ -63,13 +63,13 @@
"sendBufferSize" : 262144
}, {
"type" : "Port",
- "name" : "defaultJmxRmiPort",
+ "name" : "9099",
"port" : 9099,
"transports" : [ "TCP" ],
"protocols" : [ "JMX_RMI" ]
}, {
"type" : "Port",
- "name" : "defaultRmiPort",
+ "name" : "8999",
"port" : 8999,
"transports" : [ "TCP" ],
"protocols" : [ "RMI" ]
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
index b33ebd881d..62b2f75cec 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ConfigurationEntryStoreFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
@@ -21,6 +21,8 @@
package org.apache.qpid.server.configuration;
import java.io.File;
+import java.util.Set;
+import java.util.UUID;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.server.BrokerOptions;
@@ -29,10 +31,10 @@ import org.apache.qpid.server.configuration.store.XMLConfigurationEntryStore;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
-public class ConfigurationEntryStoreFactoryTest extends QpidTestCase
+public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
{
private File _userStoreLocation;
- private ConfigurationEntryStoreFactory _factory;
+ private BrokerConfigurationStoreCreator _storeCreator;
private BrokerOptions _options;
public void setUp() throws Exception
@@ -45,7 +47,7 @@ public class ConfigurationEntryStoreFactoryTest extends QpidTestCase
// set the properties in order to resolve the defaults store settings
setTestSystemProperty("QPID_HOME", TMP_FOLDER);
}
- _factory = new ConfigurationEntryStoreFactory();
+ _storeCreator = new BrokerConfigurationStoreCreator();
_userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
_options = new BrokerOptions();
}
@@ -65,34 +67,24 @@ public class ConfigurationEntryStoreFactoryTest extends QpidTestCase
}
}
- public void testCreateJsonStoreWithDefaults()
+ public void testCreateJsonStore()
{
- ConfigurationEntryStore store = _factory.createStore(_userStoreLocation.getAbsolutePath(), "json", _options);
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _options);
assertNotNull("Store was not created", store);
assertTrue("File should exists", _userStoreLocation.exists());
assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
- JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(_userStoreLocation);
- assertFalse("Unexpected children", jsonStore.getRootEntry().getChildrenIds().isEmpty());
+ JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore();
+ jsonStore.open(_userStoreLocation.getAbsolutePath());
+ Set<UUID> childrenIds = jsonStore.getRootEntry().getChildrenIds();
+ assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty());
}
- public void testCreateJsonStoreWithNoDefaults()
- {
- _options.setNoDefaultConfiguration(true);
- ConfigurationEntryStore store = _factory.createStore(_userStoreLocation.getAbsolutePath(), "json", _options);
- assertNotNull("Store was not created", store);
- assertTrue("File should exists", _userStoreLocation.exists());
- assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
- JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(_userStoreLocation);
- assertTrue("Unexpected children", jsonStore.getRootEntry().getChildrenIds().isEmpty());
- }
-
- public void testCreateDerbyStoreWithNoDefaults()
+ public void testCreateDerbyStore()
{
//TODO: Implement DERBY store
- _options.setNoDefaultConfiguration(true);
try
{
- _factory.createStore(_userStoreLocation.getAbsolutePath(), "derby", _options);
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", _options);
fail("Store is not yet supported");
}
catch(IllegalConfigurationException e)
@@ -101,13 +93,12 @@ public class ConfigurationEntryStoreFactoryTest extends QpidTestCase
}
}
- public void testCreateXmlStoreWithNoDefaults() throws Exception
+ public void testCreateXmlStore() throws Exception
{
//TODO: Remove XML store
- _options.setNoDefaultConfiguration(true);
XMLConfiguration config = new XMLConfiguration();
config.save(_userStoreLocation);
- ConfigurationEntryStore store = _factory.createStore(_userStoreLocation.getAbsolutePath(), "xml", _options);
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", _options);
assertNotNull("Store was not created", store);
assertTrue("Unexpected store type", store instanceof XMLConfigurationEntryStore);
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
index b6254a6371..9ce6ab5035 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
@@ -787,8 +787,8 @@ public class ServerConfigurationTest extends QpidTestCase
VirtualHostRegistry virtualHostRegistry = new VirtualHostRegistry();
// load configuration with recoverer
- ConfigurationEntryStore store = new XMLConfigurationEntryStore(mainFile);
-
+ ConfigurationEntryStore store = new XMLConfigurationEntryStore();
+ store.open(mainFile.getAbsolutePath());
StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
LogRecorder logRecorder = mock(LogRecorder.class);
RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
@@ -895,8 +895,9 @@ public class ServerConfigurationTest extends QpidTestCase
loadConfigurationAndReturnVirtualHostRegistry(mainFile);
fail("Different virtualhost XML configurations not allowed");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException e)
{
+ ConfigurationException ce = (ConfigurationException)e.getCause();
assertEquals("Incorrect error message", "Only one of external or embedded virtualhosts configuration allowed.", ce.getMessage());
}
}
@@ -928,8 +929,9 @@ public class ServerConfigurationTest extends QpidTestCase
loadConfigurationAndReturnVirtualHostRegistry(mainFile);
fail("Multiple virtualhost XML configurations not allowed");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException e)
{
+ ConfigurationException ce = (ConfigurationException)e.getCause();
assertEquals("Incorrect error message",
"Only one external virtualhosts configuration file allowed, multiple filenames found.",
ce.getMessage());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandlerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandlerTest.java
index af95f2e052..3d16b16b99 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandlerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/CommandLineOptionsHandlerTest.java
@@ -22,6 +22,7 @@ import org.apache.qpid.server.ProtocolExclusion;
import org.apache.qpid.server.ProtocolInclusion;
import org.apache.qpid.server.configuration.ConfigurationEntry;
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Protocol;
@@ -31,8 +32,6 @@ import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.ConnectionSettings;
-import com.sun.corba.se.pept.broker.Broker;
-
public class CommandLineOptionsHandlerTest extends QpidTestCase
{
private ConfigurationEntryStore _originalStore;
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
index eb3b390d80..539da83d85 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
@@ -43,7 +43,8 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest
_storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
- JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(_storeFile);
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(_storeFile.getAbsolutePath());
return store;
}
@@ -67,7 +68,8 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest
attributes, brokerConfigEntry.getChildrenIds(), store);
store.save(updatedBrokerEntry);
- JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore(_storeFile);
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(_storeFile.getAbsolutePath());
assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java
deleted file mode 100644
index 50e6916b0c..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java
+++ /dev/null
@@ -1,239 +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.server.configuration.store;
-
-import static org.apache.qpid.server.configuration.ConfigurationEntryStoreFactory.DEFAULTS;
-
-import java.io.File;
-import java.util.Collection;
-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.ConfigurationEntryStore;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.util.BrokerTestHelper;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.util.FileUtils;
-
-public class MergingStoreTest extends QpidTestCase
-{
- private ConfigurationEntryStore _masterStore;
- private ConfigurationEntryStore _userStore;
-
- private File _userStoreFile;
-
- public void setUp() throws Exception
- {
- super.setUp();
- setTestSystemProperty("QPID_HOME", TMP_FOLDER);
- _masterStore = new JsonConfigurationEntryStore(getClass().getClassLoader().getResource(DEFAULTS));
- _userStoreFile = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
- _userStore = createStore(_userStoreFile);
- }
-
- public void tearDown() throws Exception
- {
- try
- {
- super.tearDown();
- }
- finally
- {
- if (_userStoreFile != null)
- {
- FileUtils.delete(_userStoreFile, true);
- }
- }
- }
-
- private ConfigurationEntryStore createStore(File userStoreFile) throws Exception
- {
- return BrokerTestHelper.createTestProfileBrokerConfigurationStore(userStoreFile.getAbsolutePath());
- }
-
- public void testAllMasterEntriesAreCopiedForEmptyUserStore()
- {
- MergingStore store = new MergingStore(_userStore, _masterStore);
-
- assertStoreEntries(store, _userStore, _masterStore);
- }
-
- private void assertStoreEntries(ConfigurationEntryStore mergedStore, ConfigurationEntryStore userStore,
- ConfigurationEntryStore masterStore)
- {
- ConfigurationEntry masterRootEntry = masterStore.getRootEntry();
- ConfigurationEntry userRootEntry = userStore.getRootEntry();
- ConfigurationEntry mergedRootEntry = mergedStore.getRootEntry();
-
- Map<String, Object> masterStoreAttributes = masterRootEntry.getAttributes();
- assertFalse("Master store has no attributes defined for broker", masterStoreAttributes.isEmpty());
-
- Map<String, Object> userStoreAttributes = userRootEntry.getAttributes();
- Map<String, Object> mergedStoreAttributes = mergedRootEntry.getAttributes();
- for (Map.Entry<String, Object> attributeEntry : masterStoreAttributes.entrySet())
- {
- assertEquals("Unexpected attribute " + attributeEntry.getKey() + " in user store", attributeEntry.getValue(),
- userStoreAttributes.get(attributeEntry.getKey()));
- assertEquals("Unexpected attribute " + attributeEntry.getKey() + " in merged store", attributeEntry.getValue(),
- mergedStoreAttributes.get(attributeEntry.getKey()));
- }
-
- Set<UUID> childrenIds = masterRootEntry.getChildrenIds();
- assertFalse("Master store has no chldren", childrenIds.isEmpty());
-
- for (UUID id : childrenIds)
- {
- ConfigurationEntry masterEntry = masterStore.getEntry(id);
- ConfigurationEntry userEntry = userStore.getEntry(id);
- ConfigurationEntry mergedEntry = mergedStore.getEntry(id);
-
- assertEquals("Unexpected entry in user store", masterEntry, userEntry);
- assertEquals("Unexpected entry in merged store", masterEntry, mergedEntry);
- }
- }
-
- public void testMasterEntriesAreCopiedIntoUserStoreWhenTheyAreMissedInUserStore()
- {
- // merge all entries
- MergingStore store = new MergingStore(_userStore, _masterStore);
-
- Map<String, Collection<ConfigurationEntry>> userChildren = _userStore.getRootEntry().getChildren();
- Collection<ConfigurationEntry> ports = userChildren.get(Port.class.getSimpleName());
- assertFalse("Ports are missed in master store", ports.isEmpty());
-
- // remove ports
- for (ConfigurationEntry portEntry : ports)
- {
- _userStore.remove(portEntry.getId());
- }
-
- // merge again
- store = new MergingStore(_userStore, _masterStore);
-
- assertStoreEntries(store, _userStore, _masterStore);
- }
-
- public void testMasterEntriesAreCopiedIntoUserStoreWhenTheyAreReplacedWithEntriesWithDifferentNames()
- {
- // merge all entries
- MergingStore store = new MergingStore(_userStore, _masterStore);
-
- Map<String, Collection<ConfigurationEntry>> userChildren = _userStore.getRootEntry().getChildren();
- Collection<ConfigurationEntry> ports = userChildren.get(Port.class.getSimpleName());
- assertFalse("Ports are missed in master store", ports.isEmpty());
-
- // remove ports
- for (ConfigurationEntry portEntry : ports)
- {
- _userStore.remove(portEntry.getId());
- }
-
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(Port.NAME, getTestName());
- ConfigurationEntry port = new ConfigurationEntry(UUID.randomUUID(), Port.class.getSimpleName(), attributes, null,
- _userStore);
- _userStore.save(port);
-
- // merge again
- store = new MergingStore(_userStore, _masterStore);
-
- assertStoreEntries(store, _userStore, _masterStore);
-
- // previously added custom entry still should be in store
- ConfigurationEntry storedPortEntry = store.getEntry(port.getId());
- assertEquals("User port entry was removed", port, storedPortEntry);
- }
-
- public void testStoreEntriesAreNotReplacedIfAttributesAreModified() throws Exception
- {
- // merge all entries
- MergingStore store = new MergingStore(_userStore, _masterStore);
-
- ConfigurationEntry root = store.getRootEntry();
- Set<UUID> childrenIds = root.getChildrenIds();
- assertFalse("Cannot find chldren", childrenIds.isEmpty());
-
- Set<UUID> all = new HashSet<UUID>(childrenIds);
- all.add(root.getId());
-
- // store new attributes in map for verification
- Map<UUID, Map<String, Object>> modifiedAttributes = new HashMap<UUID, Map<String, Object>>();
- Set<ConfigurationEntry> entriesToStore = new HashSet<ConfigurationEntry>();
-
- // modify primitive attributes in all entries
- for (UUID uuid : all)
- {
- ConfigurationEntry entry = store.getEntry(uuid);
- Map<String, Object> newAttributes = new HashMap<String, Object>();
- modifiedAttributes.put(entry.getId(), newAttributes);
- ConfigurationEntry modifiedEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes,
- entry.getChildrenIds(), entry.getStore());
- entriesToStore.add(modifiedEntry);
- for (Map.Entry<String, Object> attributeEntry : entry.getAttributes().entrySet())
- {
- Object value = attributeEntry.getValue();
- String key = attributeEntry.getKey();
- if (!key.equals("name"))
- {
- if (value instanceof String)
- {
- value = (String) value + "_Modified";
- }
- else if (value instanceof Number)
- {
- value = ((Number) value).intValue() + 10000;
- }
- else if (value instanceof Boolean)
- {
- value = !((Boolean) value).booleanValue();
- }
- }
- newAttributes.put(key, value);
- }
- }
-
- // save modified entries
- store.save(entriesToStore.toArray(new ConfigurationEntry[entriesToStore.size()]));
-
- // merge again
- store = new MergingStore(_userStore, _masterStore);
-
- for (Map.Entry<UUID, Map<String, Object>> entryAttributes : modifiedAttributes.entrySet())
- {
- ConfigurationEntry entry = store.getEntry(entryAttributes.getKey());
- assertEquals("Unexpected attributes", entryAttributes.getValue(), entry.getAttributes());
- }
-
- // assert that all values have been saved, re-create user store
- _userStore = createStore(_userStoreFile);
-
- for (Map.Entry<UUID, Map<String, Object>> entryAttributes : modifiedAttributes.entrySet())
- {
- ConfigurationEntry entry = store.getEntry(entryAttributes.getKey());
- assertEquals("Unexpected attributes in user store", entryAttributes.getValue(), entry.getAttributes());
- }
-
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
index 84ade67878..2b1711c5a2 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
@@ -108,6 +108,11 @@ public class BrokerShutdownTest extends QpidTestCase
return null;
}
+ @Override
+ public void open(String storeLocation)
+ {
+ }
+
};
// mocking the required object
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
index e109806454..8480a8e225 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
@@ -24,8 +24,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.File;
-import java.lang.reflect.Constructor;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.UUID;
@@ -224,28 +222,9 @@ public class BrokerTestHelper
{
String className = getTestProfileBrokerConfigurationStoreClassName();
Class classObject = Class.forName(className);
- Constructor[] constructors = classObject.getConstructors();
- for (int i = 0; i < constructors.length; i++)
- {
- Constructor constructor = constructors[i];
- Class[] parameterTypes = constructor.getParameterTypes();
- if (parameterTypes == null || parameterTypes.length == 0)
- {
- return (ConfigurationEntryStore) classObject.newInstance();
- }
- else if (parameterTypes.length == 1)
- {
- if (parameterTypes[0] == String.class)
- {
- return (ConfigurationEntryStore) constructor.newInstance(storeLocation);
- }
- else if (parameterTypes[0] == File.class)
- {
- return (ConfigurationEntryStore) constructor.newInstance(new File(storeLocation));
- }
- }
- }
- throw new RuntimeException("Cannot instantiate broker configuration store. Try to override getTestProfileBrokerConfigurationStore");
+ ConfigurationEntryStore store = (ConfigurationEntryStore)classObject.newInstance();
+ store.open(storeLocation);
+ return store;
}
}