summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2015-03-03 09:30:49 +0000
committerRobert Godfrey <rgodfrey@apache.org>2015-03-03 09:30:49 +0000
commit83120216de949c1cae3004c74475cc6c54cd61f1 (patch)
treebc3e4facca57ff0bea576584a61f44a5422331cb
parent2bb28f477ab2ff92d6fe6c7a5694449638f94661 (diff)
downloadqpid-python-83120216de949c1cae3004c74475cc6c54cd61f1.tar.gz
QPID-6428 : [Java Broker] Use StoreConfigurationChangeListener to manage storage of all configured objects
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1663573 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java31
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java35
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java30
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java14
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java97
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java58
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java6
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java4
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java15
9 files changed, 145 insertions, 145 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
index 76c6b6007f..6012e2e8db 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.binding;
-import java.security.AccessControlException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -45,10 +44,8 @@ import org.apache.qpid.server.model.ManagedAttributeField;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.StateTransition;
-import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.util.StateChangeListener;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
public class BindingImpl
extends AbstractConfiguredObject<BindingImpl>
@@ -108,26 +105,6 @@ public class BindingImpl
}
}
- @Override
- protected void onCreate()
- {
- super.onCreate();
- try
- {
- _queue.getVirtualHost().getSecurityManager().authoriseCreateBinding(this);
- }
- catch(AccessControlException e)
- {
- deleted();
- throw e;
- }
- if (isDurable())
- {
- _queue.getVirtualHost().getDurableConfigurationStore().create(asObjectRecord());
- }
-
- }
-
private static Map<String, Object> enhanceWithDurable(Map<String, Object> attributes,
final AMQQueue queue,
final ExchangeImpl exchange)
@@ -263,12 +240,6 @@ public class BindingImpl
{
_arguments = arguments;
BindingImpl.super.setAttribute(ARGUMENTS, getActualAttributes().get(ARGUMENTS), arguments);
- if (isDurable())
- {
- VirtualHostImpl<?, ?, ?> vhost =
- (VirtualHostImpl<?, ?, ?>) _exchange.getParent(VirtualHost.class);
- vhost.getDurableConfigurationStore().update(true, asObjectRecord());
- }
}
}
);
@@ -278,6 +249,8 @@ public class BindingImpl
@Override
public void validateOnCreate()
{
+ _queue.getVirtualHost().getSecurityManager().authoriseCreateBinding(this);
+
AMQQueue queue = getAMQQueue();
Map<String, Object> arguments = getArguments();
if (arguments!=null && !arguments.isEmpty() && FilterSupport.argumentsContainFilter(arguments))
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
index b8bbe181c3..d5bbe16446 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
@@ -42,7 +42,10 @@ public class StoreConfigurationChangeListener implements ConfigurationChangeList
{
if (newState == State.DELETED)
{
- _store.remove(object.asObjectRecord());
+ if(object.isDurable())
+ {
+ _store.remove(object.asObjectRecord());
+ }
object.removeChangeListener(this);
}
}
@@ -52,17 +55,21 @@ public class StoreConfigurationChangeListener implements ConfigurationChangeList
{
if (!object.managesChildStorage())
{
- child.addChangeListener(this);
- _store.update(true,child.asObjectRecord());
+ if(object.isDurable() && child.isDurable())
+ {
+ child.addChangeListener(this);
+ _store.update(true, child.asObjectRecord());
- Class<? extends ConfiguredObject> categoryClass = child.getCategoryClass();
- Collection<Class<? extends ConfiguredObject>> childTypes = child.getModel().getChildTypes(categoryClass);
+ Class<? extends ConfiguredObject> categoryClass = child.getCategoryClass();
+ Collection<Class<? extends ConfiguredObject>> childTypes =
+ child.getModel().getChildTypes(categoryClass);
- for(Class<? extends ConfiguredObject> childClass : childTypes)
- {
- for (ConfiguredObject<?> grandchild : child.getChildren(childClass))
+ for (Class<? extends ConfiguredObject> childClass : childTypes)
{
- childAdded(child, grandchild);
+ for (ConfiguredObject<?> grandchild : child.getChildren(childClass))
+ {
+ childAdded(child, grandchild);
+ }
}
}
}
@@ -72,14 +79,20 @@ public class StoreConfigurationChangeListener implements ConfigurationChangeList
@Override
public void childRemoved(ConfiguredObject object, ConfiguredObject child)
{
- _store.remove(child.asObjectRecord());
+ if(child.isDurable())
+ {
+ _store.remove(child.asObjectRecord());
+ }
child.removeChangeListener(this);
}
@Override
public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
{
- _store.update(false, object.asObjectRecord());
+ if(object.isDurable())
+ {
+ _store.update(false, object.asObjectRecord());
+ }
}
@Override
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
index 2e7f3eee7f..e515c09526 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
@@ -177,17 +177,6 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
}
@Override
- protected void onCreate()
- {
- super.onCreate();
- if(isDurable())
- {
- getVirtualHost().getDurableConfigurationStore().create(asObjectRecord());
- }
-
- }
-
- @Override
public EventLogger getEventLogger()
{
return _virtualHost.getEventLogger();
@@ -213,12 +202,6 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
throw new RequiredExchangeException(getName());
}
- if (isDurable() && !isAutoDelete())
- {
- getVirtualHost().getDurableConfigurationStore().remove(asObjectRecord());
-
- }
-
if(_closed.compareAndSet(false,true))
{
List<BindingImpl> bindings = new ArrayList<BindingImpl>(_bindings);
@@ -241,11 +224,6 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
}
_closeTaskList.clear();
- if (isDurable() && !isAutoDelete())
- {
- getVirtualHost().getDurableConfigurationStore().remove(asObjectRecord());
-
- }
}
deleted();
}
@@ -665,10 +643,6 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
doRemoveBinding(b);
queue.removeBinding(b);
- if (b.isDurable())
- {
- _virtualHost.getDurableConfigurationStore().remove(b.asObjectRecord());
- }
b.delete();
}
@@ -905,9 +879,5 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
protected void changeAttributes(final Map<String, Object> attributes)
{
super.changeAttributes(attributes);
- if (isDurable() && getState() != State.DELETED)
- {
- this.getVirtualHost().getDurableConfigurationStore().update(false, asObjectRecord());
- }
}
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
index fc7d9d0fec..b85377e2a7 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
@@ -293,11 +293,7 @@ public abstract class AbstractQueue<X extends AbstractQueue<X>>
});
}
- if (isDurable())
- {
- _virtualHost.getDurableConfigurationStore().create(asObjectRecord());
- }
- else if(getMessageDurability() != MessageDurability.NEVER)
+ if(!isDurable() && getMessageDurability() != MessageDurability.NEVER)
{
Subject.doAs(SecurityManager.getSubjectWithAddedSystemRights(),
new PrivilegedAction<Object>()
@@ -361,17 +357,9 @@ public abstract class AbstractQueue<X extends AbstractQueue<X>>
case PRINCIPAL:
_exclusiveOwner = sessionModel.getConnectionModel().getAuthorizedPrincipal();
- if(isDurable())
- {
- _virtualHost.getDurableConfigurationStore().update(false,asObjectRecord());
- }
break;
case CONTAINER:
_exclusiveOwner = sessionModel.getConnectionModel().getRemoteContainerName();
- if(isDurable())
- {
- _virtualHost.getDurableConfigurationStore().update(false,asObjectRecord());
- }
break;
case CONNECTION:
_exclusiveOwner = sessionModel.getConnectionModel();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java
index 10d8a5d61c..c59fd821c3 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/VirtualHostStoreUpgraderAndRecoverer.java
@@ -20,8 +20,10 @@
*/
package org.apache.qpid.server.store;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -30,14 +32,19 @@ import java.util.UUID;
import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener;
import org.apache.qpid.server.filter.FilterSupport;
import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.ConfigurationChangeListener;
+import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.queue.QueueArgumentsConverter;
+import org.apache.qpid.server.util.Action;
public class VirtualHostStoreUpgraderAndRecoverer
{
@@ -509,12 +516,100 @@ public class VirtualHostStoreUpgraderAndRecoverer
}
- public void perform(DurableConfigurationStore durableConfigurationStore)
+ public void perform(final DurableConfigurationStore durableConfigurationStore)
{
String virtualHostCategory = VirtualHost.class.getSimpleName();
GenericStoreUpgrader upgraderHandler = new GenericStoreUpgrader(virtualHostCategory, VirtualHost.MODEL_VERSION, durableConfigurationStore, _upgraders);
upgraderHandler.upgrade();
new GenericRecoverer(_virtualHostNode).recover(upgraderHandler.getRecords());
+
+ final StoreConfigurationChangeListener configChangeListener = new StoreConfigurationChangeListener(durableConfigurationStore);
+ if(_virtualHostNode.getVirtualHost() != null)
+ {
+ applyRecursively(_virtualHostNode.getVirtualHost(), new Action<ConfiguredObject<?>>()
+ {
+ @Override
+ public void performAction(final ConfiguredObject<?> object)
+ {
+ object.addChangeListener(configChangeListener);
+ }
+ });
+ }
+ _virtualHostNode.addChangeListener(new ConfigurationChangeListener()
+ {
+ @Override
+ public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState)
+ {
+
+ }
+
+ @Override
+ public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child)
+ {
+ if(child instanceof VirtualHost)
+ {
+ applyRecursively(child, new Action<ConfiguredObject<?>>()
+ {
+ @Override
+ public void performAction(final ConfiguredObject<?> object)
+ {
+ if(object.isDurable())
+ {
+ durableConfigurationStore.update(true, object.asObjectRecord());
+ object.addChangeListener(configChangeListener);
+ }
+ }
+ });
+
+ }
+ }
+
+ @Override
+ public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child)
+ {
+ if(child instanceof VirtualHost)
+ {
+ child.removeChangeListener(configChangeListener);
+ }
+ }
+
+ @Override
+ public void attributeSet(final ConfiguredObject<?> object,
+ final String attributeName,
+ final Object oldAttributeValue,
+ final Object newAttributeValue)
+ {
+
+ }
+ });
+ }
+
+ private void applyRecursively(final ConfiguredObject<?> object, final Action<ConfiguredObject<?>> action)
+ {
+ applyRecursively(object, action, new HashSet<ConfiguredObject<?>>());
+ }
+
+ private void applyRecursively(final ConfiguredObject<?> object,
+ final Action<ConfiguredObject<?>> action,
+ final HashSet<ConfiguredObject<?>> visited)
+ {
+ if(!visited.contains(object))
+ {
+ visited.add(object);
+ action.performAction(object);
+ for(Class<? extends ConfiguredObject> childClass : object.getModel().getChildTypes(object.getCategoryClass()))
+ {
+ Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
+ if(children != null)
+ {
+ for(ConfiguredObject<?> child : children)
+ {
+ applyRecursively(child, action, visited);
+ }
+ }
+ }
+ }
}
+
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
index abc570239c..7cf988961e 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
@@ -77,7 +77,6 @@ import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
-import org.apache.qpid.server.store.ConfiguredObjectRecordImpl;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.Event;
import org.apache.qpid.server.store.EventListener;
@@ -341,9 +340,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte
_messageStore.addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
_messageStore.addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL);
- addChangeListener(new StoreUpdatingChangeListener());
-
-
_fileSystemMaxUsagePercent = getContextValue(Integer.class, Broker.STORE_FILESYSTEM_MAX_USAGE_PERCENT);
@@ -664,14 +660,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte
{
int purged = queue.deleteAndReturnCount();
- if (queue.isDurable() && !(queue.getLifetimePolicy()
- == LifetimePolicy.DELETE_ON_CONNECTION_CLOSE
- || queue.getLifetimePolicy()
- == LifetimePolicy.DELETE_ON_SESSION_END))
- {
- DurableConfigurationStore store = getDurableConfigurationStore();
- store.remove(queue.asObjectRecord());
- }
return purged;
}
@@ -1535,14 +1523,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte
return total;
}
- @Override
- protected void onCreate()
- {
- super.onCreate();
- ConfiguredObjectRecord record = asObjectRecord();
- getDurableConfigurationStore().create(new ConfiguredObjectRecordImpl(record.getId(), record.getType(), record.getAttributes()));
- }
-
@StateTransition( currentState = { State.UNINITIALIZED,State.ERRORED }, desiredState = State.ACTIVE )
private void onActivate()
{
@@ -1654,44 +1634,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte
onActivate();
}
- private class StoreUpdatingChangeListener implements ConfigurationChangeListener
- {
- @Override
- public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState)
- {
- if (object == AbstractVirtualHost.this && isDurable() && newState == State.DELETED)
- {
- getDurableConfigurationStore().remove(asObjectRecord());
- object.removeChangeListener(this);
- }
- }
-
- @Override
- public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child)
- {
-
- }
-
- @Override
- public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child)
- {
-
- }
-
- @Override
- public void attributeSet(final ConfiguredObject<?> object,
- final String attributeName,
- final Object oldAttributeValue,
- final Object newAttributeValue)
- {
- if (object == AbstractVirtualHost.this && isDurable() && getState() != State.DELETED && isAttributePersisted(attributeName)
- && !(attributeName.equals(VirtualHost.DESIRED_STATE) && newAttributeValue.equals(State.DELETED)))
- {
- getDurableConfigurationStore().update(false, asObjectRecord());
- }
- }
- }
-
private class FileSystemSpaceChecker extends HouseKeepingTask
{
private boolean _fileSystemFull;
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java
index 93fa9114fb..d004f16466 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/binding/BindingImplTest.java
@@ -35,6 +35,8 @@ import org.apache.qpid.server.model.Binding;
import org.apache.qpid.server.model.BrokerModel;
import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.test.utils.QpidTestCase;
public class BindingImplTest extends QpidTestCase
@@ -57,7 +59,11 @@ public class BindingImplTest extends QpidTestCase
attributes.put(Binding.ARGUMENTS, arguments);
attributes.put(Binding.NAME, getTestName());
AMQQueue queue = mock(AMQQueue.class);
+ VirtualHostImpl vhost = mock(VirtualHostImpl.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ when(vhost.getSecurityManager()).thenReturn(securityManager);
when(queue.getTaskExecutor()).thenReturn(_taskExecutor);
+ when(queue.getVirtualHost()).thenReturn(vhost);
when(queue.getModel()).thenReturn(_model);
ExchangeImpl exchange = mock(ExchangeImpl.class);
when(exchange.getTaskExecutor()).thenReturn(_taskExecutor);
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
index f23085943b..f5a9217ef3 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
@@ -57,6 +57,7 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
notifyBrokerStarted();
UUID id = UUID.randomUUID();
ConfiguredObject object = mock(VirtualHost.class);
+ when(object.isDurable()).thenReturn(true);
when(object.getId()).thenReturn(id);
ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
when(object.asObjectRecord()).thenReturn(record);
@@ -69,11 +70,13 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
notifyBrokerStarted();
Broker broker = mock(Broker.class);
when(broker.getCategoryClass()).thenReturn(Broker.class);
+ when(broker.isDurable()).thenReturn(true);
VirtualHost child = mock(VirtualHost.class);
when(child.getCategoryClass()).thenReturn(VirtualHost.class);
Model model = mock(Model.class);
when(model.getChildTypes(any(Class.class))).thenReturn(Collections.<Class<? extends ConfiguredObject>>emptyList());
when(child.getModel()).thenReturn(model);
+ when(child.isDurable()).thenReturn(true);
_listener.childAdded(broker, child);
verify(_store).update(eq(true), any(ConfiguredObjectRecord.class));
}
@@ -83,6 +86,7 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
notifyBrokerStarted();
Broker broker = mock(Broker.class);
when(broker.getCategoryClass()).thenReturn(Broker.class);
+ when(broker.isDurable()).thenReturn(true);
_listener.attributeSet(broker, Broker.CONNECTION_SESSION_COUNT_LIMIT, null, 1);
verify(_store).update(eq(false),any(ConfiguredObjectRecord.class));
}
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
index ba6b0d95f3..aa05447851 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
@@ -45,6 +45,7 @@ import org.mockito.stubbing.Answer;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener;
import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.connection.IConnectionRegistry.RegistryChangeListener;
@@ -66,6 +67,7 @@ public class VirtualHostTest extends QpidTestCase
private VirtualHostNode<?> _virtualHostNode;
private DurableConfigurationStore _configStore;
private VirtualHost<?, ?, ?> _virtualHost;
+ private StoreConfigurationChangeListener _storeConfigurationChangeListener;
@Override
protected void setUp() throws Exception
@@ -79,9 +81,13 @@ public class VirtualHostTest extends QpidTestCase
when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
_virtualHostNode = mock(VirtualHostNode.class);
+ when(_virtualHostNode.isDurable()).thenReturn(true);
_configStore = mock(DurableConfigurationStore.class);
+ _storeConfigurationChangeListener = new StoreConfigurationChangeListener(_configStore);
+
when(_virtualHostNode.getConfigurationStore()).thenReturn(_configStore);
+
// Virtualhost needs the EventLogger from the SystemContext.
when(_virtualHostNode.getParent(Broker.class)).thenReturn(_broker);
@@ -122,7 +128,7 @@ public class VirtualHostTest extends QpidTestCase
assertEquals("Unexpected name", virtualHostName, virtualHost.getName());
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
- verify(_configStore).create(matchesRecord(virtualHost.getId(), virtualHost.getType()));
+ verify(_configStore).update(eq(true),matchesRecord(virtualHost.getId(), virtualHost.getType()));
}
public void testDeleteVirtualHost()
@@ -170,7 +176,7 @@ public class VirtualHostTest extends QpidTestCase
virtualHost.start();
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
- verify(_configStore, times(1)).create(matchesRecord(virtualHost.getId(), virtualHost.getType()));
+ verify(_configStore, times(1)).update(eq(true), matchesRecord(virtualHost.getId(), virtualHost.getType()));
verify(_configStore, times(2)).update(eq(false), matchesRecord(virtualHost.getId(), virtualHost.getType()));
}
@@ -293,7 +299,7 @@ public class VirtualHostTest extends QpidTestCase
assertNotNull(queue.getId());
assertEquals(queueName, queue.getName());
- verify(_configStore).create(matchesRecord(queue.getId(), queue.getType()));
+ verify(_configStore).update(eq(true),matchesRecord(queue.getId(), queue.getType()));
}
public void testCreateNonDurableQueue()
@@ -396,7 +402,10 @@ public class VirtualHostTest extends QpidTestCase
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
TestMemoryVirtualHost host = new TestMemoryVirtualHost(attributes, _virtualHostNode);
+ host.addChangeListener(_storeConfigurationChangeListener);
host.create();
+ // Fire the child added event on the node
+ _storeConfigurationChangeListener.childAdded(_virtualHostNode,host);
_virtualHost = host;
return host;
}