diff options
| author | Keith Wall <kwall@apache.org> | 2014-03-14 16:39:47 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-03-14 16:39:47 +0000 |
| commit | ec486999608568e37a55dc9c81d9be133d95ebc3 (patch) | |
| tree | 87d6446e97cfdca321b1faff6f24a3010df4cdff /qpid/java/broker-plugins/derby-store/src | |
| parent | db26915f9b2edfa410c094162bec78b9d2010b24 (diff) | |
| download | qpid-python-ec486999608568e37a55dc9c81d9be133d95ebc3.tar.gz | |
QPID-5624: Introduce messageStoreSettings VH attribute and move all message store related attributes into messageStoreSettings map
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-bdb-ha2@1577606 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins/derby-store/src')
4 files changed, 54 insertions, 24 deletions
diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java index 5d56329c20..25ce3b8adc 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java @@ -32,6 +32,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Map; + import org.apache.log4j.Logger; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.AbstractJDBCMessageStore; @@ -39,7 +41,6 @@ import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.Event; import org.apache.qpid.server.store.EventListener; import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.MessageStoreConstants; import org.apache.qpid.server.store.StoreException; import org.apache.qpid.util.FileUtils; @@ -130,13 +131,25 @@ public class DerbyMessageStore extends AbstractJDBCMessageStore implements Messa { //Update to pick up QPID_WORK and use that as the default location not just derbyDB + Map<String, Object> messageStoreSettings = virtualHost.getMessageStoreSettings(); _driverClass = (Class<Driver>) Class.forName(SQL_DRIVER_NAME); - String defaultPath = System.getProperty("QPID_WORK") + File.separator + "derbyDB"; - String databasePath = isConfigStoreOnly() ? (String) virtualHost.getAttribute(VirtualHost.CONFIG_STORE_PATH) : (String) virtualHost.getAttribute(VirtualHost.STORE_PATH); + String databasePath = null; + if (isConfigStoreOnly()) + { + databasePath = (String) virtualHost.getAttribute(VirtualHost.CONFIG_STORE_PATH); + } + else + { + if (messageStoreSettings != null) + { + databasePath = (String) messageStoreSettings.get(MessageStore.STORE_PATH); + } + } + if(databasePath == null) { - databasePath = defaultPath; + databasePath = System.getProperty("QPID_WORK") + File.separator + "derbyDB"; } if(!MEMORY_STORE_LOCATION.equals(databasePath)) @@ -154,8 +167,8 @@ public class DerbyMessageStore extends AbstractJDBCMessageStore implements Messa _storeLocation = databasePath; - Object overfullAttr = virtualHost.getAttribute(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE); - Object underfullAttr = virtualHost.getAttribute(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE); + Object overfullAttr = messageStoreSettings.get(MessageStore.OVERFULL_SIZE); + Object underfullAttr = messageStoreSettings.get(MessageStore.UNDERFULL_SIZE); _persistentSizeHighThreshold = overfullAttr == null ? -1l : overfullAttr instanceof Number ? ((Number) overfullAttr).longValue() : Long.parseLong(overfullAttr.toString()); diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java index d64420a808..4e81c4e9ba 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java @@ -52,12 +52,15 @@ public class DerbyMessageStoreFactory implements MessageStoreFactory, DurableCon @Override public void validateAttributes(Map<String, Object> attributes) { - if(getType().equals(attributes.get(VirtualHost.STORE_TYPE))) + @SuppressWarnings("unchecked") + Map<String, Object> messageStoreSettings = (Map<String, Object>) attributes.get(VirtualHost.MESSAGE_STORE_SETTINGS); + + if(getType().equals(messageStoreSettings.get(MessageStore.STORE_TYPE))) { - Object storePath = attributes.get(VirtualHost.STORE_PATH); + Object storePath = messageStoreSettings.get(MessageStore.STORE_PATH); if(!(storePath instanceof String)) { - throw new IllegalArgumentException("Attribute '"+ VirtualHost.STORE_PATH + throw new IllegalArgumentException("Setting '"+ MessageStore.STORE_PATH +"' is required and must be of type String."); } diff --git a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java index 479675dac1..f23b5a3e23 100644 --- a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java +++ b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java @@ -20,15 +20,17 @@ */ package org.apache.qpid.server.store.derby; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + 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 DerbyMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestBase { private static final Logger _logger = Logger.getLogger(DerbyMessageStoreQuotaEventsTest.class); @@ -50,17 +52,26 @@ public class DerbyMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTes } @Override - protected void applyStoreSpecificConfiguration(VirtualHost vhost) + protected MessageStore createStore() throws Exception { - _logger.debug("Applying store specific config. overfull-sze=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE); - - when(vhost.getAttribute(eq(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE))).thenReturn(OVERFULL_SIZE); - when(vhost.getAttribute(eq(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE))).thenReturn(UNDERFULL_SIZE); + return new DerbyMessageStore(); } @Override - protected MessageStore createStore() throws Exception + protected VirtualHost<?> createVirtualHost(String storeLocation) { - return new DerbyMessageStore(); + _logger.debug("Applying store specific config. overfull-size=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE); + + VirtualHost<?> vhost = mock(VirtualHost.class); + Map<String, Object> messageStoreSettings = new HashMap<String, Object>(); + messageStoreSettings.put(MessageStore.STORE_PATH, storeLocation); + messageStoreSettings.put(MessageStore.OVERFULL_SIZE, OVERFULL_SIZE); + messageStoreSettings.put(MessageStore.UNDERFULL_SIZE, UNDERFULL_SIZE); + + when(vhost.getMessageStoreSettings()).thenReturn(messageStoreSettings ); + when(vhost.getName()).thenReturn("test"); + + return vhost; } + } diff --git a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java index 859fad629b..e3f91cc8fb 100644 --- a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java +++ b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java @@ -20,16 +20,17 @@ */ package org.apache.qpid.server.store.derby; +import static org.mockito.Mockito.when; + import java.io.File; +import java.util.HashMap; +import java.util.Map; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.MessageStoreTestCase; import org.apache.qpid.util.FileUtils; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.when; - public class DerbyMessageStoreTest extends MessageStoreTestCase { private String _storeLocation; @@ -63,7 +64,9 @@ public class DerbyMessageStoreTest extends MessageStoreTestCase protected void setUpStoreConfiguration(VirtualHost virtualHost) throws Exception { _storeLocation = TMP_FOLDER + File.separator + getTestName(); - when(virtualHost.getAttribute(eq(VirtualHost.STORE_PATH))).thenReturn(_storeLocation); + Map<String, Object> messageStoreSettings = new HashMap<String, Object>(); + messageStoreSettings.put(MessageStore.STORE_PATH, _storeLocation); + when(virtualHost.getMessageStoreSettings()).thenReturn(messageStoreSettings); deleteStoreIfExists(); } |
