diff options
| author | Andrew MacBean <macbean@apache.org> | 2014-06-26 11:19:54 +0000 |
|---|---|---|
| committer | Andrew MacBean <macbean@apache.org> | 2014-06-26 11:19:54 +0000 |
| commit | 8a1190a3bc398233b3cb9a295add11eef0f3cec4 (patch) | |
| tree | 15ecfb671967401f81b9dce15e46aa9f1a33489c /qpid/java/broker-plugins/derby-store | |
| parent | 4ad072fd1cca374bcf36292bcf83aba74f18f08c (diff) | |
| download | qpid-python-8a1190a3bc398233b3cb9a295add11eef0f3cec4.tar.gz | |
QPID-5821: [Java Broker] Refactor MessageStore and DurableConfigurationStore interfaces to remove message store settings map.
VirtualHost model objects now have attributes.
Work done by Keith Wall <kwall@apache.org> and me.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1605737 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins/derby-store')
10 files changed, 229 insertions, 130 deletions
diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java index 0a121ad476..e75a4c8065 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java @@ -28,15 +28,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.store.AbstractJDBCMessageStore; -import org.apache.qpid.server.store.Event; -import org.apache.qpid.server.store.JdbcUtils; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.StoreException; +import org.apache.qpid.server.store.*; public abstract class AbstractDerbyMessageStore extends AbstractJDBCMessageStore { @@ -50,7 +45,7 @@ public abstract class AbstractDerbyMessageStore extends AbstractJDBCMessageStore private ConfiguredObject<?> _parent; @Override - public final void openMessageStore(final ConfiguredObject<?> parent, final Map<String, Object> messageStoreSettings) + public final void openMessageStore(final ConfiguredObject<?> parent) { if (_messageStoreOpen.compareAndSet(false, true)) { @@ -58,33 +53,24 @@ public abstract class AbstractDerbyMessageStore extends AbstractJDBCMessageStore DerbyUtils.loadDerbyDriver(); - doOpen(parent, messageStoreSettings); + doOpen(parent); - 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()); - _persistentSizeLowThreshold = underfullAttr == null ? _persistentSizeHighThreshold : - underfullAttr instanceof Number - ? ((Number) underfullAttr).longValue() - : Long.parseLong(underfullAttr.toString()); + final SizeMonitorSettings sizeMonitorSettings = (SizeMonitorSettings) parent; + _persistentSizeHighThreshold = sizeMonitorSettings.getStoreOverfullSize(); + _persistentSizeLowThreshold = sizeMonitorSettings.getStoreUnderfullSize(); if (_persistentSizeLowThreshold > _persistentSizeHighThreshold || _persistentSizeLowThreshold < 0l) { _persistentSizeLowThreshold = _persistentSizeHighThreshold; } - createOrOpenMessageStoreDatabase(); setInitialSize(); setMaximumMessageId(); } } - protected abstract void doOpen(final ConfiguredObject<?> parent, final Map<String, Object> messageStoreSettings); + protected abstract void doOpen(final ConfiguredObject<?> parent); @Override public final void upgradeStoreStructure() throws StoreException diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java index 6596b5b621..fdf08a9940 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java @@ -25,21 +25,16 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.log4j.Logger; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.store.AbstractJDBCConfigurationStore; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.MessageStoreProvider; -import org.apache.qpid.server.store.StoreException; +import org.apache.qpid.server.store.*; /** * Implementation of a DurableConfigurationStore backed by Apache Derby - * that also provides a MessageStore. + * that also provides a MessageStore.A */ public class DerbyConfigurationStore extends AbstractJDBCConfigurationStore implements MessageStoreProvider, DurableConfigurationStore @@ -55,7 +50,7 @@ public class DerbyConfigurationStore extends AbstractJDBCConfigurationStore private ConfiguredObject<?> _parent; @Override - public void openConfigurationStore(ConfiguredObject<?> parent, Map<String, Object> storeSettings) + public void openConfigurationStore(ConfiguredObject<?> parent) throws StoreException { if (_configurationStoreOpen.compareAndSet(false, true)) @@ -63,10 +58,9 @@ public class DerbyConfigurationStore extends AbstractJDBCConfigurationStore _parent = parent; DerbyUtils.loadDerbyDriver(); - String databasePath = (String) storeSettings.get(MessageStore.STORE_PATH); - - _storeLocation = databasePath; - _connectionURL = DerbyUtils.createConnectionUrl(parent.getName(), databasePath); + final FileBasedSettings settings = (FileBasedSettings)parent; + _storeLocation = settings.getStorePath(); + _connectionURL = DerbyUtils.createConnectionUrl(parent.getName(), _storeLocation); createOrOpenConfigurationStoreDatabase(); } @@ -188,7 +182,7 @@ public class DerbyConfigurationStore extends AbstractJDBCConfigurationStore private class ProvidedMessageStore extends AbstractDerbyMessageStore { @Override - protected void doOpen(final ConfiguredObject<?> parent, final Map<String, Object> messageStoreSettings) + protected void doOpen(final ConfiguredObject<?> parent) { // Nothing to do, store provided by DerbyConfigurationStore } 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 9e2a2f63d4..d9948fe21e 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 @@ -24,12 +24,11 @@ package org.apache.qpid.server.store.derby; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -import java.util.Map; import org.apache.log4j.Logger; import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.store.MessageStore; +import org.apache.qpid.server.store.FileBasedSettings; import org.apache.qpid.server.store.StoreException; /** @@ -43,13 +42,12 @@ public class DerbyMessageStore extends AbstractDerbyMessageStore private String _storeLocation; @Override - protected void doOpen(final ConfiguredObject<?> parent, final Map<String, Object> messageStoreSettings) + protected void doOpen(final ConfiguredObject<?> parent) { - String databasePath = (String) messageStoreSettings.get(MessageStore.STORE_PATH); - String name = parent.getName(); + final FileBasedSettings settings = (FileBasedSettings)parent; + _storeLocation = settings.getStorePath(); - _storeLocation = databasePath; - _connectionURL = DerbyUtils.createConnectionUrl(name, databasePath); + _connectionURL = DerbyUtils.createConnectionUrl(parent.getName(), _storeLocation); } @Override diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHost.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHost.java index fc67d2fa50..4355447971 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHost.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHost.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,36 +15,25 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * */ -package org.apache.qpid.server.virtualhost.derby; -import java.util.Map; +package org.apache.qpid.server.virtualhost.derby; -import org.apache.qpid.server.model.ManagedObject; -import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.model.VirtualHostNode; -import org.apache.qpid.server.store.MessageStore; -import org.apache.qpid.server.store.derby.DerbyMessageStore; -import org.apache.qpid.server.virtualhost.AbstractVirtualHost; +import org.apache.qpid.server.exchange.ExchangeImpl; +import org.apache.qpid.server.model.ManagedAttribute; +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.virtualhost.VirtualHostImpl; -@ManagedObject(category = false, type = DerbyVirtualHost.VIRTUAL_HOST_TYPE) -public class DerbyVirtualHost extends AbstractVirtualHost<DerbyVirtualHost> +public interface DerbyVirtualHost<X extends DerbyVirtualHost<X>> extends VirtualHostImpl<X,AMQQueue<?>,ExchangeImpl<?>>, org.apache.qpid.server.store.FileBasedSettings, org.apache.qpid.server.store.SizeMonitorSettings { - public static final String VIRTUAL_HOST_TYPE = "DERBY"; - - @ManagedObjectFactoryConstructor - public DerbyVirtualHost(final Map<String, Object> attributes, - final VirtualHostNode<?> virtualHostNode) - { - super(attributes, virtualHostNode); - } + String STORE_PATH = "storePath"; + @ManagedAttribute(mandatory = true) + String getStorePath(); - @Override - protected MessageStore createMessageStore() - { - return new DerbyMessageStore(); - } + @ManagedAttribute(mandatory = true, defaultValue = "0") + Long getStoreUnderfullSize(); + @ManagedAttribute(mandatory = true, defaultValue = "0") + Long getStoreOverfullSize(); } diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHostImpl.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHostImpl.java new file mode 100644 index 0000000000..5089090643 --- /dev/null +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhost/derby/DerbyVirtualHostImpl.java @@ -0,0 +1,78 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.virtualhost.derby; + +import org.apache.qpid.server.model.ManagedAttributeField; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; +import org.apache.qpid.server.model.VirtualHostNode; +import org.apache.qpid.server.store.MessageStore; +import org.apache.qpid.server.store.derby.DerbyMessageStore; +import org.apache.qpid.server.virtualhost.AbstractVirtualHost; + +import java.util.Map; + +@ManagedObject(category = false, type = DerbyVirtualHostImpl.VIRTUAL_HOST_TYPE) +public class DerbyVirtualHostImpl extends AbstractVirtualHost<DerbyVirtualHostImpl> implements DerbyVirtualHost<DerbyVirtualHostImpl> +{ + public static final String VIRTUAL_HOST_TYPE = "DERBY"; + + @ManagedAttributeField + private String _storePath; + + @ManagedAttributeField + private Long _storeUnderfullSize; + + @ManagedAttributeField + private Long _storeOverfullSize; + + @ManagedObjectFactoryConstructor + public DerbyVirtualHostImpl(final Map<String, Object> attributes, + final VirtualHostNode<?> virtualHostNode) + { + super(attributes, virtualHostNode); + } + + + @Override + protected MessageStore createMessageStore() + { + return new DerbyMessageStore(); + } + + @Override + public String getStorePath() + { + return _storePath; + } + + @Override + public Long getStoreUnderfullSize() + { + return _storeUnderfullSize; + } + + @Override + public Long getStoreOverfullSize() + { + return _storeOverfullSize; + } +} diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java index 340d046033..3b31f4e7e0 100644 --- a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,51 +15,17 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * */ package org.apache.qpid.server.virtualhostnode.derby; -import java.util.Map; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ManagedAttributeField; -import org.apache.qpid.server.model.ManagedObject; -import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.derby.DerbyConfigurationStore; -import org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode; -import org.apache.qpid.server.virtualhostnode.FileBasedVirtualHostNode; +import org.apache.qpid.server.model.ManagedAttribute; -@ManagedObject( category = false, type = DerbyVirtualHostNode.VIRTUAL_HOST_NODE_TYPE ) -public class DerbyVirtualHostNode extends AbstractStandardVirtualHostNode<DerbyVirtualHostNode> implements FileBasedVirtualHostNode<DerbyVirtualHostNode> +public interface DerbyVirtualHostNode<X extends DerbyVirtualHostNode<X>> extends org.apache.qpid.server.model.VirtualHostNode<X>, org.apache.qpid.server.store.FileBasedSettings { - public static final String VIRTUAL_HOST_NODE_TYPE = "DERBY"; - - @ManagedAttributeField - private String _storePath; - - @ManagedObjectFactoryConstructor - public DerbyVirtualHostNode(Map<String, Object> attributes, Broker<?> parent) - { - super(attributes, parent); - } - - @Override - protected DurableConfigurationStore createConfigurationStore() - { - return new DerbyConfigurationStore(); - } - - @Override - public String getStorePath() - { - return _storePath; - } + String STORE_PATH = "storePath"; - @Override - public String toString() - { - return getClass().getSimpleName() + " [id=" + getId() + ", name=" + getName() + ", storePath=" + getStorePath() + "]"; - } + @ManagedAttribute(mandatory = true) + String getStorePath(); } diff --git a/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeImpl.java b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeImpl.java new file mode 100644 index 0000000000..ae440014c7 --- /dev/null +++ b/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeImpl.java @@ -0,0 +1,72 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.qpid.server.virtualhostnode.derby; + +import java.util.Map; + +import org.apache.qpid.server.logging.messages.ConfigStoreMessages; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ManagedAttributeField; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; +import org.apache.qpid.server.store.DurableConfigurationStore; +import org.apache.qpid.server.store.derby.DerbyConfigurationStore; +import org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode; + +@ManagedObject( category = false, type = DerbyVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE ) +public class DerbyVirtualHostNodeImpl extends AbstractStandardVirtualHostNode<DerbyVirtualHostNodeImpl> implements DerbyVirtualHostNode<DerbyVirtualHostNodeImpl> +{ + public static final String VIRTUAL_HOST_NODE_TYPE = "DERBY"; + + @ManagedAttributeField + private String _storePath; + + @ManagedObjectFactoryConstructor + public DerbyVirtualHostNodeImpl(Map<String, Object> attributes, Broker<?> parent) + { + super(attributes, parent); + } + + @Override + protected void writeLocationEventLog() + { + getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.STORE_LOCATION(getStorePath())); + } + + @Override + protected DurableConfigurationStore createConfigurationStore() + { + return new DerbyConfigurationStore(); + } + + @Override + public String getStorePath() + { + return _storePath; + } + + @Override + public String toString() + { + return getClass().getSimpleName() + " [id=" + getId() + ", name=" + getName() + ", storePath=" + getStorePath() + "]"; + } +} diff --git a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreConfigurationTest.java b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreConfigurationTest.java index 08c421b606..849bd066c7 100644 --- a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreConfigurationTest.java +++ b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreConfigurationTest.java @@ -20,12 +20,26 @@ */ package org.apache.qpid.server.store.derby; +import org.apache.qpid.server.model.ConfiguredObjectFactory; +import org.apache.qpid.server.model.VirtualHostNode; import org.apache.qpid.server.store.AbstractDurableConfigurationStoreTestCase; +import org.apache.qpid.server.virtualhostnode.derby.DerbyVirtualHostNode; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DerbyMessageStoreConfigurationTest extends AbstractDurableConfigurationStoreTestCase { @Override + protected VirtualHostNode createVirtualHostNode(String storeLocation, ConfiguredObjectFactory factory) + { + final DerbyVirtualHostNode parent = mock(DerbyVirtualHostNode.class); + when(parent.getStorePath()).thenReturn(storeLocation); + return parent; + } + + @Override protected DerbyConfigurationStore createConfigStore() throws Exception { return new DerbyConfigurationStore(); 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 348d81fadd..5c8eb94d91 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 @@ -21,26 +21,27 @@ package org.apache.qpid.server.store.derby; import java.util.Collections; -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.MessageStoreQuotaEventsTestBase; +import org.apache.qpid.server.virtualhost.derby.DerbyVirtualHost; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DerbyMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestBase { - private static final Logger _logger = Logger.getLogger(DerbyMessageStoreQuotaEventsTest.class); - private static final int NUMBER_OF_MESSAGES_TO_OVERFILL_STORE = 10; /** * Estimated using an assumption that a physical disk space occupied by a * message is 3 times bigger then a message size */ - private static final int OVERFULL_SIZE = (int) (MESSAGE_DATA.length * 3 * NUMBER_OF_MESSAGES_TO_OVERFILL_STORE * 0.8); + private static final long OVERFULL_SIZE = (long) (MESSAGE_DATA.length * 3 * NUMBER_OF_MESSAGES_TO_OVERFILL_STORE * 0.8); - private static final int UNDERFULL_SIZE = (int) (OVERFULL_SIZE * 0.8); + private static final long UNDERFULL_SIZE = (long) (OVERFULL_SIZE * 0.8); @Override protected int getNumberOfMessagesToFillStore() @@ -49,27 +50,26 @@ public class DerbyMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTes } @Override - protected MessageStore createStore() throws Exception + protected VirtualHost createVirtualHost(String storeLocation) { - return new DerbyMessageStore(); + final DerbyVirtualHost parent = mock(DerbyVirtualHost.class); + when(parent.getContext()).thenReturn(createContextSettings()); + when(parent.getStorePath()).thenReturn(storeLocation); + when(parent.getStoreOverfullSize()).thenReturn(OVERFULL_SIZE); + when(parent.getStoreUnderfullSize()).thenReturn(UNDERFULL_SIZE); + return parent; } @Override - protected Map<String, Object> createStoreSettings(String storeLocation) + protected MessageStore createStore() throws Exception { - _logger.debug("Applying store specific config. overfull-size=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE); - - 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); - return messageStoreSettings; + return new DerbyMessageStore(); } - @Override - protected Map<String, String> createContextSettings() + private Map<String, String> createContextSettings() { return Collections.emptyMap(); } + } 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 9a2d945494..ad3246290c 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 @@ -22,13 +22,16 @@ package org.apache.qpid.server.store.derby; 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.server.virtualhost.derby.DerbyVirtualHost; import org.apache.qpid.util.FileUtils; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class DerbyMessageStoreTest extends MessageStoreTestCase { private String _storeLocation; @@ -59,13 +62,14 @@ public class DerbyMessageStoreTest extends MessageStoreTestCase } @Override - protected Map<String, Object> getStoreSettings() throws Exception + protected VirtualHost createVirtualHost() { _storeLocation = TMP_FOLDER + File.separator + getTestName(); deleteStoreIfExists(); - Map<String, Object> messageStoreSettings = new HashMap<String, Object>(); - messageStoreSettings.put(MessageStore.STORE_PATH, _storeLocation); - return messageStoreSettings; + + final DerbyVirtualHost parent = mock(DerbyVirtualHost.class); + when(parent.getStorePath()).thenReturn(_storeLocation); + return parent; } private void deleteStoreIfExists() |
