You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2013/02/20 18:17:01 UTC
svn commit: r1448306 - in /qpid/trunk/qpid/java:
broker/src/main/java/org/apache/qpid/server/
broker/src/main/java/org/apache/qpid/server/configuration/
broker/src/main/java/org/apache/qpid/server/configuration/store/
broker/src/main/java/org/apache/qp...
Author: orudyy
Date: Wed Feb 20 17:17:00 2013
New Revision: 1448306
URL: http://svn.apache.org/r1448306
Log:
QPID-4593: add command line argument to pass path to initial store
Modified:
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java Wed Feb 20 17:17:00 2013
@@ -128,7 +128,8 @@ public class Broker
configureLogging(logConfigFile, options.getLogWatchFrequency());
BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator();
- ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType, options);
+ ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType,
+ options.getInitialConfigurationStoreLocation(), options.getInitialConfigurationStoreLocation());
_applicationRegistry = new ApplicationRegistry(store);
try
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java Wed Feb 20 17:17:00 2013
@@ -32,6 +32,9 @@ public class BrokerOptions
private String _configurationStoreLocation;
private String _configurationStoreType = DEFAULT_STORE_TYPE;
+ private String _initialConfigurationStoreLocation;
+ private String _initialConfigurationStoreType = DEFAULT_STORE_TYPE;
+
public String getLogConfigFile()
{
return _logConfigFile;
@@ -76,4 +79,24 @@ public class BrokerOptions
_configurationStoreType = cofigurationStoreType;
}
+ public void setInitialConfigurationStoreLocation(String initialConfigurationStore)
+ {
+ _initialConfigurationStoreLocation = initialConfigurationStore;
+ }
+
+ public void setInitialConfigurationStoreType(String initialConfigurationStoreType)
+ {
+ _initialConfigurationStoreType = initialConfigurationStoreType;
+ }
+
+ public String getInitialConfigurationStoreLocation()
+ {
+ return _initialConfigurationStoreLocation;
+ }
+
+ public String getInitialConfigurationStoreType()
+ {
+ return _initialConfigurationStoreType;
+ }
+
}
\ No newline at end of file
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java Wed Feb 20 17:17:00 2013
@@ -48,6 +48,12 @@ 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_INITIAL_CONFIGURATION_STORE_PATH = OptionBuilder.withArgName("path").hasArg()
+ .withDescription("pass the location of initial store to use to create a user store").withLongOpt("initial-store-path").create("isp");
+
+ private static final Option OPTION_INITIAL_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg()
+ .withDescription("the type of initial store").withLongOpt("initial-store-type").create("ist");
+
private static final Option OPTION_LOG_CONFIG_FILE =
OptionBuilder.withArgName("file").hasArg()
.withDescription("use the specified log4j xml configuration file. By "
@@ -69,6 +75,8 @@ public class Main
OPTIONS.addOption(OPTION_CONFIGURATION_STORE_TYPE);
OPTIONS.addOption(OPTION_LOG_CONFIG_FILE);
OPTIONS.addOption(OPTION_LOG_WATCH);
+ OPTIONS.addOption(OPTION_INITIAL_CONFIGURATION_STORE_PATH);
+ OPTIONS.addOption(OPTION_INITIAL_CONFIGURATION_STORE_TYPE);
}
protected CommandLine _commandLine;
@@ -173,6 +181,17 @@ public class Main
options.setLogConfigFile(logConfig);
}
+ String initialConfigurationStore = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_STORE_PATH.getOpt());
+ if (initialConfigurationStore != null)
+ {
+ options.setInitialConfigurationStoreLocation(initialConfigurationStore);
+ }
+ String initailConfigurationStoreType = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_STORE_TYPE.getOpt());
+ if (initailConfigurationStoreType != null)
+ {
+ options.setInitialConfigurationStoreType(initailConfigurationStoreType);
+ }
+
setExceptionHandler();
startBroker(options);
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java Wed Feb 20 17:17:00 2013
@@ -20,39 +20,83 @@
*/
package org.apache.qpid.server.configuration;
-import org.apache.qpid.server.BrokerOptions;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
import org.apache.qpid.server.plugin.QpidServiceLoader;
+/**
+ * A helper class responsible for creation and opening of broker store.
+ */
public class BrokerConfigurationStoreCreator
{
/**
- * Path to resource containing broker default configuration
+ * URL to resource containing broker default configuration
*/
- public static final String INITIAL_STORE_LOCATION = "initial-store.json";
+ public static final String DEFAULT_INITIAL_STORE_LOCATION = BrokerConfigurationStoreCreator.class.getClassLoader()
+ .getResource("initial-store.json").toExternalForm();
- /**
- * Create broker configuration store for given store location, store type
- * and command line options
- */
- public ConfigurationEntryStore createStore(String storeLocation, String storeType, BrokerOptions options)
+ private Map<String, ConfigurationStoreFactory> _factories = new HashMap<String, ConfigurationStoreFactory>();
+
+ public BrokerConfigurationStoreCreator()
{
- ConfigurationEntryStore store = null;
QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>();
- Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader.instancesOf(ConfigurationStoreFactory.class);
+ Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader
+ .instancesOf(ConfigurationStoreFactory.class);
for (ConfigurationStoreFactory storeFactory : configurationStoreFactories)
{
- if (storeFactory.getStoreType().equals(storeType))
+ String type = storeFactory.getStoreType();
+ ConfigurationStoreFactory factory = _factories.put(type.toLowerCase(), storeFactory);
+ if (factory != null)
{
- store = storeFactory.createStore();
- break;
+ throw new IllegalStateException("ConfigurationStoreFactory with type name '" + type
+ + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '"
+ + storeFactory.getClass().getName() + "'");
}
}
- if (store == null)
+ }
+
+ /**
+ * Create broker configuration store for a given store location, store type, initial store location and initial store type
+ *
+ * @param storeLocation store location
+ * @param storeType store type
+ * @param initialStoreLocation initial store location
+ * @param initialStoreType initial store type
+ * @return store instance opened at given store location
+ * @throws IllegalConfigurationException if store type is unknown
+ */
+ public ConfigurationEntryStore createStore(String storeLocation, String storeType, String initialStoreLocation,
+ String initialStoreType)
+ {
+ ConfigurationEntryStore store = createStore(storeType);
+ if (initialStoreLocation == null)
{
- throw new IllegalConfigurationException("Cannot create store for the type " + storeType);
+ initialStoreLocation = DEFAULT_INITIAL_STORE_LOCATION;
+ initialStoreType = JsonConfigurationEntryStore.STORE_TYPE;
+ }
+ if (storeType.equals(initialStoreType))
+ {
+ store.open(storeLocation, initialStoreLocation);
+ }
+ else
+ {
+ ConfigurationEntryStore initialStore = createStore(initialStoreType);
+ initialStore.open(initialStoreLocation);
+ store.open(storeLocation, initialStore);
}
- store.open(storeLocation);
return store;
}
+ private ConfigurationEntryStore createStore(String storeType)
+ {
+ ConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase());
+ if (factory == null)
+ {
+ throw new IllegalConfigurationException("Unknown store type: " + storeType);
+ }
+ return factory.createStore();
+ }
+
}
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java Wed Feb 20 17:17:00 2013
@@ -24,14 +24,75 @@ import java.util.UUID;
public interface ConfigurationEntryStore
{
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new empty store is created with a single root entry
+ *
+ * @param storeLocation store location
+ * @throws IllegalConfigurationException if store cannot be opened in the given location
+ */
void open(String storeLocation);
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new store is created either empty or from the initial store location if it is provided
+ *
+ * @param storeLocation store location
+ * @param initialStoreLocation initial store location
+ * @throws IllegalConfigurationException if store cannot be opened in the given location or initial store location does not
+ * exists or corrupted.
+ */
+ void open(String storeLocation, String initialStoreLocation);
+
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new store is created either empty or from the initial store if it is provided
+ *
+ * @param storeLocation store location
+ * @param initialStore initial store
+ * @throws IllegalConfigurationException if store cannot be opened in the given location
+ */
+ void open(String storeLocation, ConfigurationEntryStore initialStore);
+
+ /**
+ * Returns stored root configuration entry
+ *
+ * @return root entry
+ */
ConfigurationEntry getRootEntry();
+ /**
+ * Returns the configuration entry with a given id.
+ *
+ * @return entry with a given id or null if entry does not exists
+ */
ConfigurationEntry getEntry(UUID id);
+ /**
+ * Saves given entries in the store.
+ *
+ * @param entries entries to store
+ * @throws IllegalConfigurationException if save operation fails
+ */
void save(ConfigurationEntry... entries);
+ /**
+ * Removes the entries with given IDs and all their children
+ *
+ * @param entryIds IDs of entries to remove
+ * @return IDs of removed entries
+ * @throws IllegalConfigurationException if remove operation fails
+ */
UUID[] remove(UUID... entryIds);
+ /**
+ * Copies the store into the given location
+ *
+ * @param target location to copy store into
+ * @throws IllegalConfigurationException if store cannot be copied into given location
+ */
+ public void copyTo(String copyLocation);
}
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java Wed Feb 20 17:17:00 2013
@@ -9,6 +9,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -21,7 +22,6 @@ 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.ConfiguredObject;
@@ -40,6 +40,9 @@ import org.codehaus.jackson.node.ArrayNo
public class JsonConfigurationEntryStore implements ConfigurationEntryStore
{
+ public static final String STORE_TYPE = "json";
+ public static final String IN_MEMORY = ":memory:";
+
private static final String DEFAULT_BROKER_NAME = "Broker";
private static final String ID = "id";
private static final String TYPE = "@type";
@@ -48,17 +51,10 @@ public class JsonConfigurationEntryStore
private Map<UUID, ConfigurationEntry> _entries;
private File _storeFile;
private UUID _rootId;
- private String _initialStoreLocation;
private Map<String, Class<? extends ConfiguredObject>> _relationshipClasses;
public JsonConfigurationEntryStore()
{
- this(BrokerConfigurationStoreCreator.INITIAL_STORE_LOCATION);
- }
-
- public JsonConfigurationEntryStore(String initialStore)
- {
- _initialStoreLocation = initialStore;
_objectMapper = new ObjectMapper();
_objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
_objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
@@ -66,69 +62,81 @@ public class JsonConfigurationEntryStore
_relationshipClasses = buildRelationshipClassMap();
}
- private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap()
+ @Override
+ public void open(String storeLocation)
{
- Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>();
-
- Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class);
- for (Class<? extends ConfiguredObject> childClass : children)
+ if (_rootId != null)
{
- String name = childClass.getSimpleName().toLowerCase();
- String relationshipName = name + (name.endsWith("s") ? "es" : "s");
- relationships.put(relationshipName, childClass);
+ throw new IllegalConfigurationException("The store has been opened alread");
}
- return relationships;
- }
-
- public void load(URL storeURL)
- {
- if (_rootId != null)
+ if (!IN_MEMORY.equals(storeLocation))
{
- throw new IllegalStateException("Cannot load the store from");
+ _storeFile = new File(storeLocation);
}
- JsonNode node = load(storeURL, _objectMapper);
- ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
- _rootId = brokerEntry.getId();
+ createOrLoadStore();
}
@Override
- public void open(String storeLocation)
+ public void open(String storeLocation, String initialStoreLocation)
{
- _storeFile = new File(storeLocation);
- if (!_storeFile.exists() || _storeFile.length() == 0)
+ if (_rootId != null)
{
- copyInitialStore();
+ throw new IllegalConfigurationException("The store has been opened already");
+ }
+ if (!IN_MEMORY.equals(storeLocation))
+ {
+ _storeFile = new File(storeLocation);
+ if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStoreLocation != null)
+ {
+ copyInitialStoreFile(initialStoreLocation);
+ }
+ createOrLoadStore();
+ }
+ else
+ {
+ if (initialStoreLocation == null)
+ {
+ createRootEntryIfNotExists();
+ }
+ else
+ {
+ load(toURL(initialStoreLocation));
+ }
}
-
- load(fileToURL(_storeFile));
}
- private void copyInitialStore()
+ @Override
+ public void open(String storeLocation, ConfigurationEntryStore initialStore)
{
- InputStream in = null;
- try
+ if (_rootId != null)
{
- in = JsonConfigurationEntryStore.class.getClassLoader().getResourceAsStream(_initialStoreLocation);
- FileUtils.copy(in, _storeFile);
+ throw new IllegalConfigurationException("The store has been opened already");
}
- catch (IOException e)
+ boolean copyStore = false;
+ if (IN_MEMORY.equals(storeLocation))
{
- throw new IllegalConfigurationException("Cannot create store file by copying initial store", e);
+ copyStore = initialStore != null;
}
- finally
+ else
{
- if (in != null)
+ _storeFile = new File(storeLocation);
+ if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStore != null)
{
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- throw new IllegalConfigurationException("Cannot close initial store input stream", e);
- }
+ createStoreFileIfNotExist(_storeFile);
+ copyStore = true;
}
}
+ if (copyStore)
+ {
+ ConfigurationEntry rootEntry = initialStore.getRootEntry();
+ _rootId = rootEntry.getId();
+ copyEntry(rootEntry.getId(), initialStore);
+ saveAsTree();
+ }
+ else
+ {
+ createOrLoadStore();
+ }
}
@Override
@@ -201,11 +209,133 @@ public class JsonConfigurationEntryStore
return _entries.get(id);
}
- public void saveTo(File file)
+ @Override
+ public void copyTo(String copyLocation)
{
+ if (_rootId == null)
+ {
+ throw new IllegalConfigurationException("The store has not been opened");
+ }
+ File file = new File(copyLocation);
+ if (!file.exists())
+ {
+ createStoreFileIfNotExist(file);
+ }
saveAsTree(_rootId, _entries, _objectMapper, file);
}
+ @Override
+ public String toString()
+ {
+ return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + _rootId + "]";
+ }
+
+ private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap()
+ {
+ Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>();
+
+ Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class);
+ for (Class<? extends ConfiguredObject> childClass : children)
+ {
+ String name = childClass.getSimpleName().toLowerCase();
+ String relationshipName = name + (name.endsWith("s") ? "es" : "s");
+ relationships.put(relationshipName, childClass);
+ }
+ return relationships;
+ }
+
+ private void createOrLoadStore()
+ {
+ if (_storeFile != null)
+ {
+ if (!_storeFile.exists() || _storeFile.length() == 0)
+ {
+ createStoreFileIfNotExist(_storeFile);
+ }
+ else
+ {
+ load(fileToURL(_storeFile));
+ }
+ }
+
+ createRootEntryIfNotExists();
+ }
+
+ private void createRootEntryIfNotExists()
+ {
+ if (_rootId == null)
+ {
+ // create a root entry for an empty store
+ ConfigurationEntry brokerEntry = new ConfigurationEntry(UUIDGenerator.generateRandomUUID(),
+ Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), this);
+ _rootId = brokerEntry.getId();
+ _entries.put(_rootId, brokerEntry);
+ }
+ }
+
+ private void load(URL url)
+ {
+ InputStream is = null;
+ try
+ {
+ is = url.openStream();
+ JsonNode node = loadJsonNodes(is, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
+ _rootId = brokerEntry.getId();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot load store from: " + url, e);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close input stream for: " + url, e);
+ }
+ }
+ }
+ }
+ }
+
+ private void copyInitialStoreFile(String initialStoreLocation)
+ {
+ createStoreFileIfNotExist(_storeFile);
+ URL initialStoreURL = toURL(initialStoreLocation);
+ InputStream in = null;
+ try
+ {
+ in = initialStoreURL.openStream();
+ FileUtils.copy(in, _storeFile);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot create store file " + _storeFile + " by copying initial store from " + initialStoreLocation , e);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close initial store input stream: " + initialStoreLocation , e);
+ }
+ }
+ }
+ }
+
private URL fileToURL(File storeFile)
{
URL storeURL = null;
@@ -278,7 +408,7 @@ public class JsonConfigurationEntryStore
Map<String, Object> attributes = entry.getAttributes();
if (attributes != null)
{
- tree.putAll( attributes);
+ tree.putAll(attributes);
}
tree.put(ID, entry.getId());
tree.put(TYPE, entry.getType());
@@ -307,20 +437,20 @@ public class JsonConfigurationEntryStore
return tree;
}
- private JsonNode load(URL url, ObjectMapper mapper)
+ private JsonNode loadJsonNodes(InputStream is, ObjectMapper mapper)
{
JsonNode root = null;
try
{
- root = mapper.readTree(url);
+ root = mapper.readTree(is);
}
catch (JsonProcessingException e)
{
- throw new IllegalConfigurationException("Cannot parse json from '" + url + "'", e);
+ throw new IllegalConfigurationException("Cannot parse json", e);
}
catch (IOException e)
{
- throw new IllegalConfigurationException("Cannot read from '" + url + "'", e);
+ throw new IllegalConfigurationException("Cannot read json", e);
}
return root;
}
@@ -519,10 +649,63 @@ public class JsonConfigurationEntryStore
return array;
}
- @Override
- public String toString()
+ /*
+ * Initial store location can be URL or absolute path
+ */
+ private URL toURL(String location)
+ {
+ URL url = null;
+ try
+ {
+ url = new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ File locationFile = new File(location);
+ url = fileToURL(locationFile);
+ }
+ return url;
+ }
+
+ private void createStoreFileIfNotExist(File file)
{
- return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + _rootId + ", _initialStoreLocation="
- + _initialStoreLocation + "]";
+ File parent = file.getParentFile();
+ if (!parent.exists())
+ {
+ if (!parent.mkdirs())
+ {
+ throw new IllegalConfigurationException("Cannot create folders " + parent);
+ }
+ }
+ try
+ {
+ file.createNewFile();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot create file " + file, e);
+ }
+ }
+
+ private void copyEntry(UUID entryId, ConfigurationEntryStore initialStore)
+ {
+ ConfigurationEntry entry = initialStore.getEntry(entryId);
+ if (entry != null)
+ {
+ if (_entries.containsKey(entryId))
+ {
+ throw new IllegalConfigurationException("Duplicate id is found: " + entryId
+ + "! The following configuration entries have the same id: " + _entries.get(entryId) + ", " + entry);
+ }
+ _entries.put(entryId, entry);
+ Set<UUID> children = entry.getChildrenIds();
+ if (children != null)
+ {
+ for (UUID uuid : children)
+ {
+ copyEntry(uuid, initialStore);
+ }
+ }
+ }
}
}
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java Wed Feb 20 17:17:00 2013
@@ -26,8 +26,6 @@ import org.apache.qpid.server.configurat
public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory
{
- private static final String STORE_TYPE = "json";
-
@Override
public ConfigurationEntryStore createStore()
{
@@ -37,7 +35,7 @@ public class JsonConfigurationStoreFacto
@Override
public String getStoreType()
{
- return STORE_TYPE;
+ return JsonConfigurationEntryStore.STORE_TYPE;
}
}
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java Wed Feb 20 17:17:00 2013
@@ -78,4 +78,28 @@ public class BrokerOptionsTest extends Q
_options.setLogWatchFrequency(myFreq);
assertEquals(myFreq, _options.getLogWatchFrequency());
}
+
+
+ public void testDefaultInitialConfigurationStoreType()
+ {
+ assertEquals("json", _options.getInitialConfigurationStoreType());
+ }
+
+ public void testOverriddenInitialConfigurationStoreType()
+ {
+ _options.setInitialConfigurationStoreType("dby");
+ assertEquals("dby", _options.getInitialConfigurationStoreType());
+ }
+
+ public void testDefaultInitialConfigurationStoreLocation()
+ {
+ assertNull(_options.getInitialConfigurationStoreLocation());
+ }
+
+ public void testOverriddenInitialConfigurationStoreLocation()
+ {
+ final String testConfigFile = "etc/mytestconfig.xml";
+ _options.setInitialConfigurationStoreLocation(testConfigFile);
+ assertEquals(testConfigFile, _options.getInitialConfigurationStoreLocation());
+ }
}
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java Wed Feb 20 17:17:00 2013
@@ -38,20 +38,26 @@ public class MainTest extends QpidTestCa
assertEquals(null, options.getConfigurationStoreLocation());
assertEquals(null, options.getLogConfigFile());
assertEquals(0, options.getLogWatchFrequency());
+ assertEquals("json", options.getInitialConfigurationStoreType());
+ assertEquals(null, options.getInitialConfigurationStoreLocation());
}
public void testConfigurationStoreLocation()
{
BrokerOptions options = startDummyMain("-sp abcd/config.xml");
-
assertEquals("abcd/config.xml", options.getConfigurationStoreLocation());
+
+ options = startDummyMain("-store-path abcd/config2.xml");
+ assertEquals("abcd/config2.xml", options.getConfigurationStoreLocation());
}
public void testConfigurationStoreType()
{
BrokerOptions options = startDummyMain("-st dby");
-
assertEquals("dby", options.getConfigurationStoreType());
+
+ options = startDummyMain("-store-type bdb");
+ assertEquals("bdb", options.getConfigurationStoreType());
}
public void testLogConfig()
@@ -84,6 +90,25 @@ public class MainTest extends QpidTestCa
assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h"));
}
+ public void testInitailConfigurationStoreLocation()
+ {
+ BrokerOptions options = startDummyMain("-isp abcd/config.xml");
+ assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation());
+
+ options = startDummyMain("-initial-store-path abcd/config.xml");
+ assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation());
+ }
+
+ public void testInitialConfigurationStoreType()
+ {
+ BrokerOptions options = startDummyMain("-ist dby");
+ assertEquals("dby", options.getInitialConfigurationStoreType());
+
+ options = startDummyMain("-initial-store-type bdb");
+ assertEquals("bdb", options.getInitialConfigurationStoreType());
+
+ }
+
private BrokerOptions startDummyMain(String commandLine)
{
return (new TestMain(commandLine.split("\\s"))).getOptions();
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java Wed Feb 20 17:17:00 2013
@@ -21,19 +21,24 @@
package org.apache.qpid.server.configuration;
import java.io.File;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import org.apache.qpid.server.BrokerOptions;
import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
import org.apache.qpid.util.FileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
{
private File _userStoreLocation;
private BrokerConfigurationStoreCreator _storeCreator;
- private BrokerOptions _options;
public void setUp() throws Exception
{
@@ -47,7 +52,6 @@ public class BrokerConfigurationStoreCre
}
_storeCreator = new BrokerConfigurationStoreCreator();
_userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
- _options = new BrokerOptions();
}
public void tearDown() throws Exception
@@ -67,7 +71,7 @@ public class BrokerConfigurationStoreCre
public void testCreateJsonStore()
{
- ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _options);
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", null, null);
assertNotNull("Store was not created", store);
assertTrue("File should exists", _userStoreLocation.exists());
assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
@@ -77,12 +81,45 @@ public class BrokerConfigurationStoreCre
assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty());
}
+ public void testCreateJsonStoreFromInitialStore() throws Exception
+ {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+
+ Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
+ UUID brokerId = UUID.randomUUID();
+ brokerObjectMap.put(Broker.ID, brokerId);
+ brokerObjectMap.put("name", "Test");
+
+ StringWriter sw = new StringWriter();
+ objectMapper.writeValue(sw, brokerObjectMap);
+
+ String brokerJson = sw.toString();
+
+ File _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
+
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath(), "json");
+ 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();
+ jsonStore.open(_userStoreLocation.getAbsolutePath());
+ ConfigurationEntry entry = jsonStore.getRootEntry();
+ assertEquals("Unexpected root id", brokerId, entry.getId());
+ Map<String, Object> attributes = entry.getAttributes();
+ assertNotNull("Unexpected attributes: " + attributes, attributes);
+ assertEquals("Unexpected attributes size: " + attributes.size(), 1, attributes.size());
+ assertEquals("Unexpected attribute name: " + attributes.get("name"), "Test", attributes.get("name"));
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ assertTrue("Unexpected children: " + childrenIds, childrenIds.isEmpty());
+ }
+
public void testCreateDerbyStore()
{
//TODO: Implement DERBY store
try
{
- _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", _options);
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null, null);
fail("Store is not yet supported");
}
catch(IllegalConfigurationException e)
@@ -95,7 +132,7 @@ public class BrokerConfigurationStoreCre
{
try
{
- _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", _options);
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", null, null);
fail("Store is not yet supported");
}
catch(IllegalConfigurationException e)
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java Wed Feb 20 17:17:00 2013
@@ -1,6 +1,7 @@
package org.apache.qpid.server.configuration.store;
import java.io.File;
+import java.io.IOException;
import java.io.StringWriter;
import java.util.Collections;
import java.util.HashMap;
@@ -11,6 +12,8 @@ import org.apache.qpid.server.configurat
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.TestFileUtils;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
@@ -19,6 +22,15 @@ public class JsonConfigurationEntryStore
private File _storeFile;
private ObjectMapper _objectMapper;
+ @Override
+ public void setUp() throws Exception
+ {
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ super.setUp();
+ }
+
+ @Override
public void tearDown() throws Exception
{
_storeFile.delete();
@@ -28,9 +40,15 @@ public class JsonConfigurationEntryStore
@Override
protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception
{
- _objectMapper = new ObjectMapper();
- _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ _storeFile = createStoreFile(brokerId, brokerAttributes);
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(_storeFile.getAbsolutePath());
+ return store;
+ }
+ private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
brokerObjectMap.put(Broker.ID, brokerId);
brokerObjectMap.put("@type", Broker.class.getSimpleName());
@@ -41,11 +59,7 @@ public class JsonConfigurationEntryStore
String brokerJson = sw.toString();
- _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
-
- JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
- store.open(_storeFile.getAbsolutePath());
- return store;
+ return TestFileUtils.createTempFile(this, ".json", brokerJson);
}
@Override
@@ -74,4 +88,129 @@ public class JsonConfigurationEntryStore
assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
}
+ public void testOpenEmpty()
+ {
+ File file = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ store.copyTo(file.getAbsolutePath());
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(file.getAbsolutePath());
+ ConfigurationEntry root2 = store.getRootEntry();
+ assertEquals("Unexpected root entry", root.getId(), root2.getId());
+ }
+
+ public void testOpenNotEmpty() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File file = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryEmpty()
+ {
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ }
+
+ public void testOpenWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
}
Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java Wed Feb 20 17:17:00 2013
@@ -21,6 +21,7 @@
package org.apache.qpid.server.model;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.qpid.server.configuration.ConfigurationEntry;
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
@@ -95,51 +96,23 @@ public class BrokerShutdownTest extends
private Broker startBroker() throws Exception
{
- // test store with only broker and authentication provider entries
- ConfigurationEntryStore store = new ConfigurationEntryStore()
- {
- private UUID _brokerId = UUID.randomUUID();
- private UUID _authenticationProviderId = UUID.randomUUID();
-
- @Override
- public ConfigurationEntry getRootEntry()
- {
- return new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(),
- Collections.singleton(_authenticationProviderId), this);
- }
-
- @Override
- public ConfigurationEntry getEntry(UUID id)
- {
- if (_authenticationProviderId.equals(id))
- {
- File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users");
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
- attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath());
- return new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes,
- Collections.<UUID> emptySet(), this);
- }
- return null;
- }
-
- @Override
- public void save(ConfigurationEntry... entries)
- {
- }
-
- @Override
- public UUID[] remove(UUID... entryIds)
- {
- return null;
- }
-
- @Override
- public void open(String storeLocation)
- {
- }
-
- };
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+ UUID brokerId = UUID.randomUUID();
+ UUID authenticationProviderId = UUID.randomUUID();
+
+ ConfigurationEntry root = new ConfigurationEntry(brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(),
+ Collections.singleton(authenticationProviderId), store);
+
+ File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users");
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath());
+ ConfigurationEntry authenticationProviderEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), store);
+
+ when(store.getRootEntry()).thenReturn(root);
+ when(store.getEntry(brokerId)).thenReturn(root);
+ when(store.getEntry(authenticationProviderId)).thenReturn(authenticationProviderEntry);
// mocking the required object
StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java?rev=1448306&r1=1448305&r2=1448306&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java Wed Feb 20 17:17:00 2013
@@ -21,7 +21,6 @@
package org.apache.qpid.test.utils;
import java.io.File;
-import java.net.MalformedURLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -61,16 +60,7 @@ public class TestBrokerConfiguration
{
// TODO: add support for DERBY store
_store = new JsonConfigurationEntryStore();
-
- try
- {
- // load the initial store data into our store
- _store.load(new File(intialStoreLocation).toURI().toURL());
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
+ _store.open(JsonConfigurationEntryStore.IN_MEMORY, intialStoreLocation);
}
public boolean setBrokerAttribute(String name, Object value)
@@ -100,7 +90,7 @@ public class TestBrokerConfiguration
public boolean save(File configFile)
{
- _store.saveTo(configFile);
+ _store.copyTo(configFile.getAbsolutePath());
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org