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/src/test | |
| 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/src/test')
4 files changed, 55 insertions, 31 deletions
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 +} |
