diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2013-07-01 09:56:29 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2013-07-01 09:56:29 +0000 |
| commit | 2549e2808832606b05383d8383e56d1fafffedee (patch) | |
| tree | 26136053cf5ad8229351948f596c41bbe0d2afb3 /qpid/java/bdbstore | |
| parent | 94a44efa32a181bfef063523cb592523d48af392 (diff) | |
| download | qpid-python-2549e2808832606b05383d8383e56d1fafffedee.tar.gz | |
QPID-4970 : [Java Broker] Configure MessageStores based on VirtualHost object not XML Configuration
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1498345 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore')
9 files changed, 262 insertions, 75 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java index d036a5d39a..d7c8102c0e 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java @@ -55,6 +55,7 @@ import org.apache.qpid.framing.FieldTable; import org.apache.qpid.server.binding.Binding; import org.apache.qpid.server.exchange.Exchange; import org.apache.qpid.server.message.EnqueableMessage; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.store.*; import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BindingRecoveryHandler; @@ -166,19 +167,18 @@ public abstract class AbstractBDBMessageStore implements MessageStore, DurableCo public void configureConfigStore(String name, ConfigurationRecoveryHandler recoveryHandler, - Configuration storeConfiguration) throws Exception + VirtualHost virtualHost) throws Exception { _stateManager.attainState(State.INITIALISING); _configRecoveryHandler = recoveryHandler; - configure(name, storeConfiguration); + configure(name, virtualHost); } public void configureMessageStore(String name, MessageStoreRecoveryHandler messageRecoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler, - Configuration storeConfiguration) throws Exception + TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception { _messageRecoveryHandler = messageRecoveryHandler; _tlogRecoveryHandler = tlogRecoveryHandler; @@ -205,18 +205,35 @@ public abstract class AbstractBDBMessageStore implements MessageStore, DurableCo /** * Called after instantiation in order to configure the message store. * + * * @param name The name of the virtual host using this store + * @param virtualHost * @return whether a new store environment was created or not (to indicate whether recovery is necessary) * * @throws Exception If any error occurs that means the store is unable to configure itself. */ - public void configure(String name, Configuration storeConfig) throws Exception + public void configure(String name, VirtualHost virtualHost) throws Exception { - final String storeLocation = storeConfig.getString(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, - System.getProperty("QPID_WORK") + File.separator + "bdbstore" + File.separator + name); - _persistentSizeHighThreshold = storeConfig.getLong(MessageStoreConstants.OVERFULL_SIZE_PROPERTY, Long.MAX_VALUE); - _persistentSizeLowThreshold = storeConfig.getLong(MessageStoreConstants.UNDERFULL_SIZE_PROPERTY, _persistentSizeHighThreshold); + + final String defaultPath = System.getProperty("QPID_WORK") + File.separator + "bdbstore" + File.separator + name; + + + String storeLocation = (String) virtualHost.getAttribute(VirtualHost.STORE_PATH); + if(storeLocation == null) + { + storeLocation = defaultPath; + } + + Object overfullAttr = virtualHost.getAttribute(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE); + Object underfullAttr = virtualHost.getAttribute(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE); + + _persistentSizeHighThreshold = overfullAttr == null ? -1l : + overfullAttr instanceof Number ? ((Number) overfullAttr).longValue() : Long.parseLong(overfullAttr.toString()); + _persistentSizeLowThreshold = underfullAttr == null ? _persistentSizeHighThreshold : + underfullAttr instanceof Number ? ((Number) underfullAttr).longValue() : Long.parseLong(underfullAttr.toString()); + + if(_persistentSizeLowThreshold > _persistentSizeHighThreshold || _persistentSizeLowThreshold < 0l) { _persistentSizeLowThreshold = _persistentSizeHighThreshold; @@ -234,7 +251,14 @@ public abstract class AbstractBDBMessageStore implements MessageStore, DurableCo _storeLocation = storeLocation; - _envConfigMap = getConfigMap(ENVCONFIG_DEFAULTS, storeConfig, "envConfig"); + _envConfigMap = new HashMap<String, String>(); + _envConfigMap.putAll(ENVCONFIG_DEFAULTS); + + Object bdbEnvConfigAttr = virtualHost.getAttribute("bdbEnvironmentConfig"); + if(bdbEnvConfigAttr instanceof Map) + { + _envConfigMap.putAll((Map)bdbEnvConfigAttr); + } LOGGER.info("Configuring BDB message store"); diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java index ba111e8091..561e4fa660 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java @@ -39,6 +39,7 @@ import org.apache.qpid.AMQStoreException; import org.apache.qpid.server.logging.RootMessageLogger; import org.apache.qpid.server.logging.actors.AbstractActor; import org.apache.qpid.server.logging.actors.CurrentActor; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.HAMessageStore; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.MessageStoreRecoveryHandler; @@ -121,17 +122,17 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess private Map<String, String> _repConfig; @Override - public void configure(String name, Configuration storeConfig) throws Exception + public void configure(String name, VirtualHost virtualHost) throws Exception { //Mandatory configuration - _groupName = getValidatedPropertyFromConfig("highAvailability.groupName", storeConfig); - _nodeName = getValidatedPropertyFromConfig("highAvailability.nodeName", storeConfig); - _nodeHostPort = getValidatedPropertyFromConfig("highAvailability.nodeHostPort", storeConfig); - _helperHostPort = getValidatedPropertyFromConfig("highAvailability.helperHostPort", storeConfig); + _groupName = getValidatedStringAttribute(virtualHost, "haGroupName"); + _nodeName = getValidatedStringAttribute(virtualHost, "haNodeName"); + _nodeHostPort = getValidatedStringAttribute(virtualHost, "haNodeAddress"); + _helperHostPort = getValidatedStringAttribute(virtualHost, "haHelperAddress"); _name = name; //Optional configuration - String durabilitySetting = storeConfig.getString("highAvailability.durability"); + String durabilitySetting = getStringAttribute(virtualHost,"haDurability",null); if (durabilitySetting == null) { _durability = DEFAULT_DURABILITY; @@ -140,9 +141,15 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess { _durability = Durability.parse(durabilitySetting); } - _designatedPrimary = storeConfig.getBoolean("highAvailability.designatedPrimary", Boolean.FALSE); - _coalescingSync = storeConfig.getBoolean("highAvailability.coalescingSync", Boolean.TRUE); - _repConfig = getConfigMap(REPCONFIG_DEFAULTS, storeConfig, "repConfig"); + _designatedPrimary = getBooleanAttribute(virtualHost, "haDesignatedPrimary", Boolean.FALSE); + _coalescingSync = getBooleanAttribute(virtualHost, "haCoalescingSync", Boolean.TRUE); + + _repConfig = new HashMap<String, String>(REPCONFIG_DEFAULTS); + Object repConfigAttr = virtualHost.getAttribute("haReplicationConfig"); + if(repConfigAttr instanceof Map) + { + _repConfig.putAll((Map)repConfigAttr); + } if (_coalescingSync && _durability.getLocalSync() == SyncPolicy.SYNC) { @@ -150,9 +157,54 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess + "! Please set highAvailability.coalescingSync to false in store configuration."); } - super.configure(name, storeConfig); + super.configure(name, virtualHost); + } + + + private String getValidatedStringAttribute(org.apache.qpid.server.model.VirtualHost virtualHost, String attributeName) + throws ConfigurationException + { + Object attrValue = virtualHost.getAttribute(attributeName); + if(attrValue != null) + { + return attrValue.toString(); + } + else + { + throw new ConfigurationException("BDB HA configuration key not found. Please specify configuration attribute: " + + attributeName); + } + } + + private String getStringAttribute(org.apache.qpid.server.model.VirtualHost virtualHost, String attributeName, String defaultVal) + { + Object attrValue = virtualHost.getAttribute(attributeName); + if(attrValue != null) + { + return attrValue.toString(); + } + return defaultVal; + } + + private boolean getBooleanAttribute(org.apache.qpid.server.model.VirtualHost virtualHost, String attributeName, boolean defaultVal) + { + Object attrValue = virtualHost.getAttribute(attributeName); + if(attrValue != null) + { + if(attrValue instanceof Boolean) + { + return ((Boolean) attrValue).booleanValue(); + } + else if(attrValue instanceof String) + { + return Boolean.parseBoolean((String)attrValue); + } + + } + return defaultVal; } + @Override protected void setupStore(File storePath, String name) throws DatabaseException, AMQStoreException { @@ -209,10 +261,9 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess @Override public void configureMessageStore(String name, MessageStoreRecoveryHandler messageRecoveryHandler, - TransactionLogRecoveryHandler tlogRecoveryHandler, - Configuration config) throws Exception + TransactionLogRecoveryHandler tlogRecoveryHandler) throws Exception { - super.configureMessageStore(name, messageRecoveryHandler, tlogRecoveryHandler, config); + super.configureMessageStore(name, messageRecoveryHandler, tlogRecoveryHandler); final ReplicatedEnvironment replicatedEnvironment = getReplicatedEnvironment(); diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java index 0231573053..8cf1ad8a83 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java @@ -23,6 +23,7 @@ package org.apache.qpid.server.store.berkeleydb; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.connection.IConnectionRegistry; import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.stats.StatisticsGatherer; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.Event; @@ -43,15 +44,16 @@ public class BDBHAVirtualHost extends AbstractVirtualHost BDBHAVirtualHost(VirtualHostRegistry virtualHostRegistry, StatisticsGatherer brokerStatisticsGatherer, org.apache.qpid.server.security.SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig) + VirtualHostConfiguration hostConfig, + VirtualHost virtualHost) throws Exception { - super(virtualHostRegistry, brokerStatisticsGatherer, parentSecurityManager, hostConfig); + super(virtualHostRegistry, brokerStatisticsGatherer, parentSecurityManager, hostConfig, virtualHost); } - protected void initialiseStorage(VirtualHostConfiguration hostConfig) throws Exception + protected void initialiseStorage(VirtualHostConfiguration hostConfig, VirtualHost virtualHost) throws Exception { _messageStore = new BDBHAMessageStore(); @@ -72,12 +74,12 @@ public class BDBHAVirtualHost extends AbstractVirtualHost _messageStore.configureConfigStore(getName(), recoveryHandler, - hostConfig.getStoreConfiguration()); + virtualHost); _messageStore.configureMessageStore(getName(), recoveryHandler, - recoveryHandler, - hostConfig.getStoreConfiguration()); + recoveryHandler + ); } diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java index b01aeafb9a..3b564f33fd 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java @@ -19,12 +19,16 @@ package org.apache.qpid.server.store.berkeleydb;/* * */ +import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import org.apache.commons.configuration.Configuration; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.model.adapter.VirtualHostAdapter; import org.apache.qpid.server.plugin.VirtualHostFactory; import org.apache.qpid.server.stats.StatisticsGatherer; +import org.apache.qpid.server.store.MessageStoreConstants; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; @@ -43,12 +47,14 @@ public class BDBHAVirtualHostFactory implements VirtualHostFactory public VirtualHost createVirtualHost(VirtualHostRegistry virtualHostRegistry, StatisticsGatherer brokerStatisticsGatherer, org.apache.qpid.server.security.SecurityManager parentSecurityManager, - VirtualHostConfiguration hostConfig) throws Exception + VirtualHostConfiguration hostConfig, + org.apache.qpid.server.model.VirtualHost virtualHost) throws Exception { return new BDBHAVirtualHost(virtualHostRegistry, - brokerStatisticsGatherer, - parentSecurityManager, - hostConfig); + brokerStatisticsGatherer, + parentSecurityManager, + hostConfig, + virtualHost); } @Override @@ -76,31 +82,77 @@ public class BDBHAVirtualHostFactory implements VirtualHostFactory { LinkedHashMap<String,Object> convertedMap = new LinkedHashMap<String, Object>(); convertedMap.put("store.environment-path", virtualHostAdapter.getAttribute(org.apache.qpid.server.model.VirtualHost.STORE_PATH)); - convertedMap.put("store.highAvailability.groupName", virtualHostAdapter.getAttribute("haGroupName")); - convertedMap.put("store.highAvailability.nodeName", virtualHostAdapter.getAttribute("haNodeName")); - convertedMap.put("store.highAvailability.nodeHostPort", virtualHostAdapter.getAttribute("haNodeAddress")); - convertedMap.put("store.highAvailability.helperHostPort", virtualHostAdapter.getAttribute("haHelperAddress")); - final Object haDurability = virtualHostAdapter.getAttribute("haDurability"); + return convertedMap; + } + + public Map<String, Object> convertVirtualHostConfiguration(Configuration configuration) + { + + LinkedHashMap<String,Object> convertedMap = new LinkedHashMap<String, Object>(); + + Configuration storeConfiguration = configuration.subset("store"); + + convertedMap.put(org.apache.qpid.server.model.VirtualHost.STORE_PATH, storeConfiguration.getString(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY)); + convertedMap.put(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE, storeConfiguration.getString(MessageStoreConstants.OVERFULL_SIZE_PROPERTY)); + convertedMap.put(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE, storeConfiguration.getString(MessageStoreConstants.UNDERFULL_SIZE_PROPERTY)); + convertedMap.put("haGroupName", configuration.getString("store.highAvailability.groupName")); + convertedMap.put("haNodeName", configuration.getString("store.highAvailability.nodeName")); + convertedMap.put("haNodeAddress", configuration.getString("store.highAvailability.nodeHostPort")); + convertedMap.put("haHelperAddress", configuration.getString("store.highAvailability.helperHostPort")); + + final Object haDurability = configuration.getString("store.highAvailability.durability"); if(haDurability !=null) { - convertedMap.put("store.highAvailability.durability", haDurability); + convertedMap.put("haDurability", haDurability); } - final Object designatedPrimary = virtualHostAdapter.getAttribute("haDesignatedPrimary"); + final Object designatedPrimary = configuration.getString("store.highAvailability.designatedPrimary"); if(designatedPrimary!=null) { - convertedMap.put("store.highAvailability.designatedPrimary", designatedPrimary); + convertedMap.put("haDesignatedPrimary", designatedPrimary); } - final Object coalescingSync = virtualHostAdapter.getAttribute("haCoalescingSync"); + final Object coalescingSync = configuration.getString("store.highAvailability.coalescingSync"); if(coalescingSync!=null) { - convertedMap.put("store.highAvailability.coalescingSync", coalescingSync); + convertedMap.put("haCoalescingSync", coalescingSync); + } + + + Map<String, String> attributes = getEnvironmentMap(storeConfiguration, "envConfig"); + + if(!attributes.isEmpty()) + { + convertedMap.put("bdbEnvironmentConfig",attributes); } - // TODO REP_CONFIG values + attributes = getEnvironmentMap(storeConfiguration, "repConfig"); + + if(!attributes.isEmpty()) + { + convertedMap.put("haReplicationConfig",attributes); + } return convertedMap; + + } + + private Map<String, String> getEnvironmentMap(Configuration storeConfiguration, String configName) + { + final List<Object> argumentNames = storeConfiguration.getList(configName +".name"); + final List<Object> argumentValues = storeConfiguration.getList(configName +".value"); + final int initialSize = argumentNames.size(); + + final Map<String,String> attributes = new HashMap<String,String>(initialSize); + + for (int i = 0; i < argumentNames.size(); i++) + { + final String argName = argumentNames.get(i).toString(); + final String argValue = argumentValues.get(i).toString(); + + attributes.put(argName, argValue); + } + return attributes; } } diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java index ef886d3d6d..4d224ab86e 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java @@ -20,6 +20,11 @@ */ package org.apache.qpid.server.store.berkeleydb; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.configuration.Configuration; import org.apache.qpid.server.plugin.MessageStoreFactory; import org.apache.qpid.server.store.MessageStore; @@ -38,4 +43,33 @@ public class BDBMessageStoreFactory implements MessageStoreFactory return new BDBMessageStore(); } + @Override + public Map<String, Object> convertStoreConfiguration(Configuration storeConfiguration) + { + final List<Object> argumentNames = storeConfiguration.getList("envConfig.name"); + final List<Object> argumentValues = storeConfiguration.getList("envConfig.value"); + final int initialSize = argumentNames.size(); + + final Map<String,String> attributes = new HashMap<String,String>(initialSize); + + for (int i = 0; i < argumentNames.size(); i++) + { + final String argName = argumentNames.get(i).toString(); + final String argValue = argumentValues.get(i).toString(); + + attributes.put(argName, argValue); + } + + if(initialSize != 0) + { + return Collections.singletonMap("bdbEnvironmentConfig", (Object)attributes); + } + else + { + return Collections.emptyMap(); + } + + + } + } diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java index 047b102817..0bbd399b9f 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java @@ -23,6 +23,8 @@ package org.apache.qpid.server.store.berkeleydb; import java.io.File; import java.net.InetAddress; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.server.configuration.VirtualHostConfiguration; import org.apache.qpid.server.util.BrokerTestHelper; @@ -35,6 +37,10 @@ import com.sleepycat.je.EnvironmentConfig; import com.sleepycat.je.rep.ReplicatedEnvironment; import com.sleepycat.je.rep.ReplicationConfig; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class BDBHAMessageStoreTest extends QpidTestCase { @@ -48,6 +54,7 @@ public class BDBHAMessageStoreTest extends QpidTestCase private String _host; private XMLConfiguration _configXml; private VirtualHost _virtualHost; + private org.apache.qpid.server.model.VirtualHost _modelVhost; public void setUp() throws Exception { @@ -60,6 +67,8 @@ public class BDBHAMessageStoreTest extends QpidTestCase FileUtils.delete(new File(_workDir), true); _configXml = new XMLConfiguration(); + _modelVhost = mock(org.apache.qpid.server.model.VirtualHost.class); + BrokerTestHelper.setUp(); } @@ -87,7 +96,8 @@ public class BDBHAMessageStoreTest extends QpidTestCase addVirtualHostConfiguration(); String vhostName = "test" + _masterPort; VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, _configXml.subset("virtualhosts.virtualhost." + vhostName), BrokerTestHelper.createBrokerMock()); - _virtualHost = BrokerTestHelper.createVirtualHost(configuration); + + _virtualHost = BrokerTestHelper.createVirtualHost(configuration,null,_modelVhost); BDBHAMessageStore store = (BDBHAMessageStore) _virtualHost.getMessageStore(); // test whether JVM system settings were applied @@ -116,27 +126,25 @@ public class BDBHAMessageStoreTest extends QpidTestCase _configXml.addProperty("virtualhosts.virtualhost.name", vhostName); _configXml.addProperty(vhostPrefix + ".type", BDBHAVirtualHostFactory.TYPE); - _configXml.addProperty(vhostPrefix + ".store.class", BDBHAMessageStore.class.getName()); - _configXml.addProperty(vhostPrefix + ".store.environment-path", _workDir + File.separator - + port); - _configXml.addProperty(vhostPrefix + ".store.highAvailability.groupName", _groupName); - _configXml.addProperty(vhostPrefix + ".store.highAvailability.nodeName", nodeName); - _configXml.addProperty(vhostPrefix + ".store.highAvailability.nodeHostPort", - getNodeHostPortForNodeAt(port)); - _configXml.addProperty(vhostPrefix + ".store.highAvailability.helperHostPort", - getHelperHostPort()); - - _configXml.addProperty(vhostPrefix + ".store.envConfig(-1).name", EnvironmentConfig.CLEANER_THREADS); - _configXml.addProperty(vhostPrefix + ".store.envConfig.value", TEST_NUMBER_OF_THREADS); - - _configXml.addProperty(vhostPrefix + ".store.envConfig(-1).name", EnvironmentConfig.LOG_FILE_MAX); - _configXml.addProperty(vhostPrefix + ".store.envConfig.value", TEST_LOG_FILE_MAX); - - _configXml.addProperty(vhostPrefix + ".store.repConfig(-1).name", ReplicationConfig.ELECTIONS_PRIMARY_RETRIES); - _configXml.addProperty(vhostPrefix + ".store.repConfig.value", TEST_ELECTION_RETRIES); - - _configXml.addProperty(vhostPrefix + ".store.repConfig(-1).name", ReplicationConfig.ENV_CONSISTENCY_TIMEOUT); - _configXml.addProperty(vhostPrefix + ".store.repConfig.value", TEST_ENV_CONSISTENCY_TIMEOUT); + + when(_modelVhost.getAttribute(eq(_modelVhost.STORE_PATH))).thenReturn(_workDir + File.separator + + port); + when(_modelVhost.getAttribute(eq("haGroupName"))).thenReturn(_groupName); + when(_modelVhost.getAttribute(eq("haNodeName"))).thenReturn(nodeName); + when(_modelVhost.getAttribute(eq("haNodeAddress"))).thenReturn(getNodeHostPortForNodeAt(port)); + when(_modelVhost.getAttribute(eq("haHelperAddress"))).thenReturn(getHelperHostPort()); + + Map<String,String> bdbEnvConfig = new HashMap<String,String>(); + bdbEnvConfig.put(EnvironmentConfig.CLEANER_THREADS, TEST_NUMBER_OF_THREADS); + bdbEnvConfig.put(EnvironmentConfig.LOG_FILE_MAX, TEST_LOG_FILE_MAX); + + when(_modelVhost.getAttribute(eq("bdbEnvironmentConfig"))).thenReturn(bdbEnvConfig); + + Map<String,String> repConfig = new HashMap<String,String>(); + repConfig.put(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES, TEST_ELECTION_RETRIES); + repConfig.put(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT, TEST_ENV_CONSISTENCY_TIMEOUT); + when(_modelVhost.getAttribute(eq("haReplicationConfig"))).thenReturn(repConfig); + } private String getNodeNameForNodeAt(final int bdbPort) diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java index fe48e29d0b..8ba0d41e03 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java @@ -20,11 +20,19 @@ */ package org.apache.qpid.server.store.berkeleydb; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.configuration.XMLConfiguration; import org.apache.log4j.Logger; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.MessageStore; +import org.apache.qpid.server.store.MessageStoreConstants; import org.apache.qpid.server.store.MessageStoreQuotaEventsTestBase; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; + public class BDBMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestBase { private static final Logger _logger = Logger.getLogger(BDBMessageStoreQuotaEventsTest.class); @@ -54,14 +62,15 @@ public class BDBMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestB } @Override - protected void applyStoreSpecificConfiguration(XMLConfiguration config) + protected void applyStoreSpecificConfiguration(VirtualHost virtualHost) { _logger.debug("Applying store specific config. overfull-sze=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE); - config.addProperty("envConfig(-1).name", "je.log.fileMax"); - config.addProperty("envConfig.value", MAX_BDB_LOG_SIZE); - config.addProperty("overfull-size", OVERFULL_SIZE); - config.addProperty("underfull-size", UNDERFULL_SIZE); + Map<String,String> envMap = Collections.singletonMap("je.log.fileMax", MAX_BDB_LOG_SIZE); + when(virtualHost.getAttribute(eq("bdbEnvironmentConfig"))).thenReturn(envMap); + when(virtualHost.getAttribute(eq(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE))).thenReturn(OVERFULL_SIZE); + when(virtualHost.getAttribute(eq(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE))).thenReturn(UNDERFULL_SIZE); + } @Override diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java index 11b30e66ad..e77119b140 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java @@ -39,6 +39,7 @@ import org.apache.qpid.server.message.MessageMetaData_0_10; import org.apache.qpid.server.message.MessageReference; import org.apache.qpid.server.message.ServerMessage; import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.MessageMetaDataType; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.StorableMessageMetaData; @@ -54,6 +55,10 @@ import org.apache.qpid.transport.MessageDeliveryPriority; import org.apache.qpid.transport.MessageProperties; import org.apache.qpid.transport.MessageTransfer; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * Subclass of MessageStoreTest which runs the standard tests from the superclass against * the BDB Store as well as additional tests specific to the BDB store-implementation. @@ -226,7 +231,7 @@ public class BDBMessageStoreTest extends org.apache.qpid.server.store.MessageSto messageStore.close(); AbstractBDBMessageStore newStore = new BDBMessageStore(); - newStore.configure("", getConfig().subset("store")); + newStore.configure("", getVirtualHostModel()); newStore.startWithNoRecover(); diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAMessageStoreSmokeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAMessageStoreSmokeTest.java index eaa3c3eba4..5ad49462ac 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAMessageStoreSmokeTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAMessageStoreSmokeTest.java @@ -21,18 +21,20 @@ package org.apache.qpid.server.store.berkeleydb; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.test.utils.QpidTestCase; +import static org.mockito.Mockito.mock; + public class HAMessageStoreSmokeTest extends QpidTestCase { private final BDBHAMessageStore _store = new BDBHAMessageStore(); - private final XMLConfiguration _config = new XMLConfiguration(); public void testMissingHAConfigThrowsException() throws Exception { try { - _store.configure("test", _config); + _store.configure("test", mock(VirtualHost.class)); fail("Expected an exception to be thrown"); } catch (ConfigurationException ce) @@ -40,4 +42,4 @@ public class HAMessageStoreSmokeTest extends QpidTestCase assertTrue(ce.getMessage().contains("BDB HA configuration key not found")); } } -}
\ No newline at end of file +} |
