qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1580561 [3/3] - in /qpid/trunk/qpid/java: bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/ bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/entry/ bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/...
Date Sun, 23 Mar 2014 18:29:23 GMT
Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java?rev=1580561&r1=1580560&r2=1580561&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
Sun Mar 23 18:29:22 2014
@@ -21,7 +21,6 @@
 package org.apache.qpid.server.store;
 
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyMap;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
@@ -43,6 +42,8 @@ import org.apache.qpid.server.binding.Bi
 import org.apache.qpid.server.exchange.ExchangeImpl;
 import org.apache.qpid.server.logging.EventLogger;
 import org.apache.qpid.server.message.EnqueueableMessage;
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Exchange;
 import org.apache.qpid.server.model.ExclusivityPolicy;
 import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Queue;
@@ -68,6 +69,10 @@ public abstract class AbstractDurableCon
     private static final String BINDING = org.apache.qpid.server.model.Binding.class.getSimpleName();
     private static final String QUEUE = Queue.class.getSimpleName();
 
+    private static final UUID ANY_UUID = UUID.randomUUID();
+    private static final Map ANY_MAP = new HashMap();
+
+
     private String _storePath;
     private String _storeName;
     private MessageStore _messageStore;
@@ -117,10 +122,17 @@ public abstract class AbstractDurableCon
         when(_exchange.getId()).thenReturn(_exchangeId);
         when(_exchange.getExchangeType()).thenReturn(mock(ExchangeType.class));
         when(_exchange.getEventLogger()).thenReturn(new EventLogger());
+
+        ConfiguredObjectRecord exchangeRecord = mock(ConfiguredObjectRecord.class);
+        when(exchangeRecord.getId()).thenReturn(_exchangeId);
+        when(exchangeRecord.getType()).thenReturn(Exchange.class.getSimpleName());
+        when(_exchange.asObjectRecord()).thenReturn(exchangeRecord);
+
         when(_configuration.getString(eq(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY),
anyString())).thenReturn(
                 _storePath);
         when(_virtualHost.getAttribute(eq(VirtualHost.STORE_PATH))).thenReturn(_storePath);
 
+
         _bindingArgs = new HashMap<String, Object>();
         String argKey = AMQPFilterTypes.JMS_SELECTOR.toString();
         String argValue = "some selector expression";
@@ -149,8 +161,8 @@ public abstract class AbstractDurableCon
         DurableConfigurationStoreHelper.createExchange(_configStore, exchange);
 
         reopenStore();
-        verify(_recoveryHandler).configuredObject(eq(_exchangeId), eq(EXCHANGE),
-                eq(map( org.apache.qpid.server.model.Exchange.NAME, getName(),
+        verify(_recoveryHandler).configuredObject(matchesRecord(_exchangeId, EXCHANGE,
+                map( org.apache.qpid.server.model.Exchange.NAME, getName(),
                         org.apache.qpid.server.model.Exchange.TYPE, getName()+"Type",
                         org.apache.qpid.server.model.Exchange.LIFETIME_POLICY, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS.name())));
     }
@@ -183,7 +195,7 @@ public abstract class AbstractDurableCon
         DurableConfigurationStoreHelper.removeExchange(_configStore, exchange);
 
         reopenStore();
-        verify(_recoveryHandler, never()).configuredObject(any(UUID.class), anyString(),
anyMap());
+        verify(_recoveryHandler, never()).configuredObject(any(ConfiguredObjectRecord.class));
     }
 
     public void testBindQueue() throws Exception
@@ -191,42 +203,86 @@ public abstract class AbstractDurableCon
         AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false, null);
         BindingImpl binding = new BindingImpl(UUIDGenerator.generateRandomUUID(), ROUTING_KEY,
queue,
                 _exchange, _bindingArgs);
+        DurableConfigurationStoreHelper.createQueue(_configStore, queue);
         DurableConfigurationStoreHelper.createBinding(_configStore, binding);
 
         reopenStore();
 
         Map<String,Object> map = new HashMap<String, Object>();
-        map.put(org.apache.qpid.server.model.Binding.EXCHANGE, _exchange.getId().toString());
-        map.put(org.apache.qpid.server.model.Binding.QUEUE, queue.getId().toString());
-        map.put(org.apache.qpid.server.model.Binding.NAME, ROUTING_KEY);
-        map.put(org.apache.qpid.server.model.Binding.ARGUMENTS,_bindingArgs);
+        map.put(Binding.NAME, ROUTING_KEY);
+        map.put(Binding.ARGUMENTS,_bindingArgs);
+
+        Map<String,UUID> parents = new HashMap<String, UUID>();
+
+        parents.put(Exchange.class.getSimpleName(), _exchange.getId());
+        parents.put(Queue.class.getSimpleName(), queue.getId());
+
+        verify(_recoveryHandler).configuredObject(matchesRecord(binding.getId(), BINDING,
map, parents));
+    }
+
+
+    private ConfiguredObjectRecord matchesRecord(UUID id,
+                                                 String type,
+                                                 Map<String, Object> attributes,
+                                                 final Map<String, UUID> parents)
+    {
+        return argThat(new ConfiguredObjectMatcher(id, type, attributes, parents));
+    }
 
-        verify(_recoveryHandler).configuredObject(eq(binding.getId()), eq(BINDING),
-                                                  argThat(new IgnoreCreatedByMatcher(map)));
+    private ConfiguredObjectRecord matchesRecord(UUID id, String type, Map<String, Object>
attributes)
+    {
+        return argThat(new ConfiguredObjectMatcher(id, type, attributes, ANY_MAP));
     }
 
-    private static class IgnoreCreatedByMatcher extends ArgumentMatcher<Map<String,Object>>
+    private static class ConfiguredObjectMatcher extends ArgumentMatcher<ConfiguredObjectRecord>
     {
         private final Map<String,Object> _matchingMap;
+        private final UUID _id;
+        private final String _name;
+        private final Map<String,UUID> _parents;
 
-        private IgnoreCreatedByMatcher(final Map<String, Object> matchingMap)
+        private ConfiguredObjectMatcher(final UUID id, final String type, final Map<String,
Object> matchingMap, Map<String,UUID> parents)
         {
+            _id = id;
+            _name = type;
             _matchingMap = matchingMap;
+            _parents = parents;
         }
 
         @Override
         public boolean matches(final Object argument)
         {
-            if(argument instanceof Map)
+            if(argument instanceof ConfiguredObjectRecord)
             {
-                Map<String,Object> arg = new HashMap<String, Object>((Map<String,Object>)
argument);
+                ConfiguredObjectRecord binding = (ConfiguredObjectRecord) argument;
+
+                Map<String,Object> arg = new HashMap<String, Object>(binding.getAttributes());
                 arg.remove("createdBy");
                 arg.remove("createdTime");
-                return arg.equals(_matchingMap);
-
+                return (_id == ANY_UUID || _id.equals(binding.getId()))
+                       && _name.equals(binding.getType())
+                       && (_matchingMap == ANY_MAP || arg.equals(_matchingMap))
+                       && (_parents == ANY_MAP || matchesParents(binding));
             }
             return false;
         }
+
+        private boolean matchesParents(ConfiguredObjectRecord binding)
+        {
+            Map<String, ConfiguredObjectRecord> bindingParents = binding.getParents();
+            if(bindingParents.size() != _parents.size())
+            {
+                return false;
+            }
+            for(Map.Entry<String,UUID> entry : _parents.entrySet())
+            {
+                if(!bindingParents.get(entry.getKey()).getId().equals(entry.getValue()))
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
     }
 
     public void testUnbindQueue() throws Exception
@@ -239,9 +295,8 @@ public abstract class AbstractDurableCon
         DurableConfigurationStoreHelper.removeBinding(_configStore, binding);
         reopenStore();
 
-        verify(_recoveryHandler, never()).configuredObject(any(UUID.class),
-                eq(BINDING),
-                anyMap());
+        verify(_recoveryHandler, never()).configuredObject(matchesRecord(ANY_UUID, BINDING,
+                                                                         ANY_MAP));
     }
 
     public void testCreateQueueAMQQueue() throws Exception
@@ -254,7 +309,7 @@ public abstract class AbstractDurableCon
         queueAttributes.put(Queue.NAME, getName());
         queueAttributes.put(Queue.OWNER, getName()+"Owner");
         queueAttributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER.name());
-        verify(_recoveryHandler).configuredObject(eq(_queueId), eq(QUEUE), eq(queueAttributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(_queueId, QUEUE, queueAttributes));
     }
 
     public void testCreateQueueAMQQueueFieldTable() throws Exception
@@ -276,7 +331,7 @@ public abstract class AbstractDurableCon
         queueAttributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER.name());
         queueAttributes.putAll(attributes);
 
-        verify(_recoveryHandler).configuredObject(eq(_queueId), eq(QUEUE), eq(queueAttributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(_queueId, QUEUE, queueAttributes));
     }
 
     public void testCreateQueueAMQQueueWithAlternateExchange() throws Exception
@@ -294,7 +349,7 @@ public abstract class AbstractDurableCon
         queueAttributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER.name());
         queueAttributes.put(Queue.ALTERNATE_EXCHANGE, alternateExchange.getId().toString());
 
-        verify(_recoveryHandler).configuredObject(eq(_queueId), eq(QUEUE), eq(queueAttributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(_queueId, QUEUE, queueAttributes));
     }
 
     private ExchangeImpl createTestAlternateExchange()
@@ -327,7 +382,7 @@ public abstract class AbstractDurableCon
         queueAttributes.put(Queue.NAME, getName());
         queueAttributes.putAll(attributes);
 
-        verify(_recoveryHandler).configuredObject(eq(_queueId), eq(QUEUE), eq(queueAttributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(_queueId, QUEUE, queueAttributes));
 
     }
 
@@ -354,7 +409,7 @@ public abstract class AbstractDurableCon
         queueAttributes.putAll(attributes);
         queueAttributes.put(Queue.ALTERNATE_EXCHANGE, alternateExchange.getId().toString());
 
-        verify(_recoveryHandler).configuredObject(eq(_queueId), eq(QUEUE), eq(queueAttributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(_queueId, QUEUE, queueAttributes));
     }
 
     public void testRemoveQueue() throws Exception
@@ -369,9 +424,7 @@ public abstract class AbstractDurableCon
         // remove queue
         DurableConfigurationStoreHelper.removeQueue(_configStore,queue);
         reopenStore();
-        verify(_recoveryHandler, never()).configuredObject(any(UUID.class),
-                eq(org.apache.qpid.server.model.Queue.class.getName()),
-                anyMap());
+        verify(_recoveryHandler, never()).configuredObject(any(ConfiguredObjectRecord.class));
     }
 
     private AMQQueue createTestQueue(String queueName,
@@ -424,6 +477,12 @@ public abstract class AbstractDurableCon
                     });
 
         when(queue.getActualAttributes()).thenReturn(attributes);
+
+        ConfiguredObjectRecord objectRecord = mock(ConfiguredObjectRecord.class);
+        when(objectRecord.getId()).thenReturn(_queueId);
+        when(objectRecord.getType()).thenReturn(Queue.class.getSimpleName());
+        when(objectRecord.getAttributes()).thenReturn(attributes);
+        when(queue.asObjectRecord()).thenReturn(objectRecord);
         return queue;
     }
 
@@ -440,6 +499,13 @@ public abstract class AbstractDurableCon
         when(exchange.getTypeName()).thenReturn(getName() + "Type");
         when(exchange.isAutoDelete()).thenReturn(true);
         when(exchange.getId()).thenReturn(_exchangeId);
+        ConfiguredObjectRecord exchangeRecord = mock(ConfiguredObjectRecord.class);
+        when(exchangeRecord.getId()).thenReturn(_exchangeId);
+        when(exchangeRecord.getType()).thenReturn(Exchange.class.getSimpleName());
+        Map<String,Object> actualAttributesExceptId = new HashMap<String, Object>(actualAttributes);
+        actualAttributesExceptId.remove("id");
+        when(exchangeRecord.getAttributes()).thenReturn(actualAttributesExceptId);
+        when(exchange.asObjectRecord()).thenReturn(exchangeRecord);
 
         return exchange;
     }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java?rev=1580561&r1=1580560&r2=1580561&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
Sun Mar 23 18:29:22 2014
@@ -31,11 +31,13 @@ import org.apache.qpid.server.model.Queu
 import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
 import org.apache.qpid.test.utils.QpidTestCase;
+import org.mockito.ArgumentMatcher;
 import org.mockito.InOrder;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyMap;
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
@@ -49,6 +51,10 @@ public class JsonFileConfigStoreTest ext
     private VirtualHost _virtualHost;
     private JsonFileConfigStore _store;
 
+
+    private static final UUID ANY_UUID = UUID.randomUUID();
+    private static final Map<String, Object> ANY_MAP = new HashMap<String, Object>();
+
     @Override
     public void setUp() throws Exception
     {
@@ -109,7 +115,7 @@ public class JsonFileConfigStoreTest ext
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
         InOrder inorder = inOrder(_recoveryHandler);
         inorder.verify(_recoveryHandler).beginConfigurationRecovery(eq(_store), eq(0));
-        inorder.verify(_recoveryHandler,never()).configuredObject(any(UUID.class),anyString(),anyMap());
+        inorder.verify(_recoveryHandler,never()).configuredObject(any(ConfiguredObjectRecord.class));
         inorder.verify(_recoveryHandler).completeConfigurationRecovery();
         _store.close();
     }
@@ -141,11 +147,11 @@ public class JsonFileConfigStoreTest ext
         final String queueType = Queue.class.getSimpleName();
         final Map<String,Object> queueAttr = Collections.singletonMap("name", (Object)
"q1");
 
-        _store.create(queueId, queueType, queueAttr);
+        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
         _store.close();
 
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
-        verify(_recoveryHandler).configuredObject(eq(queueId), eq(queueType), eq(queueAttr));
+        verify(_recoveryHandler).configuredObject(matchesRecord(queueId, queueType, queueAttr));
         _store.close();
     }
 
@@ -156,17 +162,17 @@ public class JsonFileConfigStoreTest ext
         final String queueType = Queue.class.getSimpleName();
         Map<String,Object> queueAttr = Collections.singletonMap("name", (Object) "q1");
 
-        _store.create(queueId, queueType, queueAttr);
+        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
 
 
         queueAttr = new HashMap<String,Object>(queueAttr);
         queueAttr.put("owner", "theowner");
-        _store.update(queueId, queueType, queueAttr);
+        _store.update(false, new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
 
         _store.close();
 
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
-        verify(_recoveryHandler).configuredObject(eq(queueId), eq(queueType), eq(queueAttr));
+        verify(_recoveryHandler).configuredObject(matchesRecord(queueId, queueType, queueAttr));
         _store.close();
     }
 
@@ -178,15 +184,16 @@ public class JsonFileConfigStoreTest ext
         final String queueType = Queue.class.getSimpleName();
         Map<String,Object> queueAttr = Collections.singletonMap("name", (Object) "q1");
 
-        _store.create(queueId, queueType, queueAttr);
+        final ConfiguredObjectRecordImpl record = new ConfiguredObjectRecordImpl(queueId,
queueType, queueAttr);
+        _store.create(record);
 
 
-        _store.remove(queueId, queueType);
+        _store.remove(record);
 
         _store.close();
 
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
-        verify(_recoveryHandler, never()).configuredObject(any(UUID.class), anyString(),
anyMap());
+        verify(_recoveryHandler, never()).configuredObject(any(ConfiguredObjectRecord.class));
         _store.close();
     }
 
@@ -195,7 +202,7 @@ public class JsonFileConfigStoreTest ext
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
         try
         {
-            _store.create(UUID.randomUUID(), "wibble", Collections.<String, Object>emptyMap());
+            _store.create(new ConfiguredObjectRecordImpl(UUID.randomUUID(), "wibble", Collections.<String,
Object>emptyMap()));
             fail("Should not be able to create instance of type wibble");
         }
         catch (StoreException e)
@@ -208,10 +215,10 @@ public class JsonFileConfigStoreTest ext
     {
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
         final UUID id = UUID.randomUUID();
-        _store.create(id, "Queue", Collections.<String, Object>emptyMap());
+        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String,
Object>emptyMap()));
         try
         {
-            _store.create(id, "Exchange", Collections.<String, Object>emptyMap());
+            _store.create(new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String,
Object>emptyMap()));
             fail("Should not be able to create two objects with same id");
         }
         catch (StoreException e)
@@ -225,13 +232,13 @@ public class JsonFileConfigStoreTest ext
     {
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
         final UUID id = UUID.randomUUID();
-        _store.create(id, "Queue", Collections.<String, Object>emptyMap());
+        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String,
Object>emptyMap()));
         _store.close();
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
 
         try
         {
-            _store.update(id, "Exchange", Collections.<String, Object>emptyMap());
+            _store.update(false, new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String,
Object>emptyMap()));
             fail("Should not be able to update object to different type");
         }
         catch (StoreException e)
@@ -270,31 +277,75 @@ public class JsonFileConfigStoreTest ext
 
         final Map<String, Object> EMPTY_ATTR = Collections.emptyMap();
         final UUID exchangeId = new UUID(0, 2);
-        final Map<String, Object> bindingAttributes = new HashMap<String, Object>();
-        bindingAttributes.put(Binding.EXCHANGE, exchangeId);
-        bindingAttributes.put(Binding.QUEUE, queueId);
-        final Map<String, Object> binding2Attributes = new HashMap<String, Object>();
-        binding2Attributes.put(Binding.EXCHANGE, exchangeId);
-        binding2Attributes.put(Binding.QUEUE, queue2Id);
 
         final UUID bindingId = new UUID(0, 3);
         final UUID binding2Id = new UUID(1, 3);
 
-        _store.create(queueId, "Queue", EMPTY_ATTR);
-        _store.create(queue2Id, "Queue", EMPTY_ATTR);
-        _store.create(exchangeId, "Exchange", EMPTY_ATTR);
-        _store.update(true,
-                new ConfiguredObjectRecord(bindingId, "Binding", bindingAttributes),
-                new ConfiguredObjectRecord(binding2Id, "Binding", binding2Attributes));
+        final ConfiguredObjectRecordImpl queueRecord = new ConfiguredObjectRecordImpl(queueId,
"Queue", EMPTY_ATTR);
+        _store.create(queueRecord);
+        final ConfiguredObjectRecordImpl queue2Record = new ConfiguredObjectRecordImpl(queue2Id,
"Queue", EMPTY_ATTR);
+        _store.create(queue2Record);
+        final ConfiguredObjectRecordImpl exchangeRecord = new ConfiguredObjectRecordImpl(exchangeId,
"Exchange", EMPTY_ATTR);
+        _store.create(exchangeRecord);
+        Map<String,ConfiguredObjectRecord> bindingParents = new HashMap<String,
ConfiguredObjectRecord>();
+        bindingParents.put("Exchange", exchangeRecord);
+        bindingParents.put("Queue", queueRecord);
+        final ConfiguredObjectRecordImpl bindingRecord =
+                new ConfiguredObjectRecordImpl(bindingId, "Binding", EMPTY_ATTR, bindingParents);
+
+
+        Map<String,ConfiguredObjectRecord> binding2Parents = new HashMap<String,
ConfiguredObjectRecord>();
+        binding2Parents.put("Exchange", exchangeRecord);
+        binding2Parents.put("Queue", queue2Record);
+        final ConfiguredObjectRecordImpl binding2Record =
+                new ConfiguredObjectRecordImpl(binding2Id, "Binding", EMPTY_ATTR, binding2Parents);
+        _store.update(true, bindingRecord, binding2Record);
         _store.close();
         _store.configureConfigStore(_virtualHost, _recoveryHandler);
-        verify(_recoveryHandler).configuredObject(eq(queueId), eq("Queue"), eq(EMPTY_ATTR));
-        verify(_recoveryHandler).configuredObject(eq(queue2Id), eq("Queue"), eq(EMPTY_ATTR));
-        verify(_recoveryHandler).configuredObject(eq(exchangeId), eq("Exchange"), eq(EMPTY_ATTR));
-        verify(_recoveryHandler).configuredObject(eq(bindingId),eq("Binding"), eq(bindingAttributes));
-        verify(_recoveryHandler).configuredObject(eq(binding2Id),eq("Binding"), eq(binding2Attributes));
+        verify(_recoveryHandler).configuredObject(matchesRecord(queueId, "Queue", EMPTY_ATTR));
+        verify(_recoveryHandler).configuredObject(matchesRecord(queue2Id, "Queue", EMPTY_ATTR));
+        verify(_recoveryHandler).configuredObject(matchesRecord(exchangeId, "Exchange", EMPTY_ATTR));
+        verify(_recoveryHandler).configuredObject(matchesRecord(bindingId, "Binding", EMPTY_ATTR));
+        verify(_recoveryHandler).configuredObject(matchesRecord(binding2Id, "Binding", EMPTY_ATTR));
         _store.close();
 
     }
 
+    private ConfiguredObjectRecord matchesRecord(UUID id, String type, Map<String, Object>
attributes)
+    {
+        return argThat(new ConfiguredObjectMatcher(id, type, attributes));
+    }
+
+    private static class ConfiguredObjectMatcher extends ArgumentMatcher<ConfiguredObjectRecord>
+    {
+        private final Map<String,Object> _matchingMap;
+        private final UUID _id;
+        private final String _name;
+
+        private ConfiguredObjectMatcher(final UUID id, final String type, final Map<String,
Object> matchingMap)
+        {
+            _id = id;
+            _name = type;
+            _matchingMap = matchingMap;
+        }
+
+        @Override
+        public boolean matches(final Object argument)
+        {
+            if(argument instanceof ConfiguredObjectRecord)
+            {
+                ConfiguredObjectRecord binding = (ConfiguredObjectRecord) argument;
+
+                Map<String,Object> arg = new HashMap<String, Object>(binding.getAttributes());
+                arg.remove("createdBy");
+                arg.remove("createdTime");
+                return (_id == ANY_UUID || _id.equals(binding.getId()))
+                       && _name.equals(binding.getType())
+                       && (_matchingMap == ANY_MAP || arg.equals(_matchingMap));
+
+            }
+            return false;
+        }
+    }
+
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/DurableConfigurationRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/DurableConfigurationRecovererTest.java?rev=1580561&r1=1580560&r2=1580561&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/DurableConfigurationRecovererTest.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/DurableConfigurationRecovererTest.java
Sun Mar 23 18:29:22 2014
@@ -30,6 +30,7 @@ import java.util.UUID;
 
 import org.apache.qpid.server.exchange.ExchangeImpl;
 import org.apache.qpid.server.logging.EventLogger;
+import org.apache.qpid.server.store.ConfiguredObjectRecordImpl;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.configuration.IllegalConfigurationException;
 import org.apache.qpid.server.exchange.DirectExchange;
@@ -214,17 +215,16 @@ public class DurableConfigurationRecover
 
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 0);
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
                                                            "org.apache.qpid.server.model.Binding",
                                                            createBinding("key",
-                                                                         DIRECT_EXCHANGE_ID,
-                                                                         QUEUE_ID,
                                                                          "x-filter-jms-selector",
-                                                                         "wibble"));
+                                                                         "wibble"),
+                                                           createBindingParents(DIRECT_EXCHANGE_ID,
QUEUE_ID)));
 
         final ConfiguredObjectRecord[] expected = {
-                new ConfiguredObjectRecord(new UUID(1, 0), "Binding",
-                        createBinding("key", DIRECT_EXCHANGE_ID, QUEUE_ID))
+                new ConfiguredObjectRecordImpl(new UUID(1, 0), "Binding",
+                        createBinding("key"))
         };
 
         verifyCorrectUpdates(expected);
@@ -239,32 +239,30 @@ public class DurableConfigurationRecover
 
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 0);
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
                                                            "org.apache.qpid.server.model.Binding",
                                                            createBinding("key",
-                                                                         DIRECT_EXCHANGE_ID,
-                                                                         QUEUE_ID,
                                                                          "x-filter-jms-selector",
                                                                          "wibble",
                                                                          "not-a-selector",
-                                                                         "moo"));
+                                                                         "moo"),
+                                                           createBindingParents(DIRECT_EXCHANGE_ID,
QUEUE_ID)));
 
 
         final UUID customExchangeId = new UUID(3,0);
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(2, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(2, 0),
                                                            "org.apache.qpid.server.model.Binding",
                                                            createBinding("key",
-                                                                         customExchangeId,
-                                                                         QUEUE_ID,
                                                                          "x-filter-jms-selector",
                                                                          "wibble",
                                                                          "not-a-selector",
-                                                                         "moo"));
+                                                                         "moo"),
+                                                           createBindingParents(customExchangeId,QUEUE_ID)));
 
-        _durableConfigurationRecoverer.configuredObject(customExchangeId,
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(customExchangeId,
                                                            "org.apache.qpid.server.model.Exchange",
-                                                           createExchange(CUSTOM_EXCHANGE_NAME,
HeadersExchange.TYPE));
+                                                           createExchange(CUSTOM_EXCHANGE_NAME,
HeadersExchange.TYPE)));
 
         final ExchangeImpl customExchange = mock(ExchangeImpl.class);
 
@@ -291,10 +289,10 @@ public class DurableConfigurationRecover
 
 
         final ConfiguredObjectRecord[] expected = {
-                new ConfiguredObjectRecord(new UUID(1, 0), "org.apache.qpid.server.model.Binding",
-                        createBinding("key", DIRECT_EXCHANGE_ID, QUEUE_ID, "not-a-selector",
"moo")),
-                new ConfiguredObjectRecord(new UUID(2, 0), "org.apache.qpid.server.model.Binding",
-                        createBinding("key", customExchangeId, QUEUE_ID, "not-a-selector",
"moo"))
+                new ConfiguredObjectRecordImpl(new UUID(1, 0), "org.apache.qpid.server.model.Binding",
+                        createBinding("key", "not-a-selector", "moo")),
+                new ConfiguredObjectRecordImpl(new UUID(2, 0), "org.apache.qpid.server.model.Binding",
+                        createBinding("key", "not-a-selector", "moo"))
         };
 
         verifyCorrectUpdates(expected);
@@ -308,17 +306,16 @@ public class DurableConfigurationRecover
 
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 0);
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
                                                            "org.apache.qpid.server.model.Binding",
                                                            createBinding("key",
-                                                                         TOPIC_EXCHANGE_ID,
-                                                                         QUEUE_ID,
                                                                          "x-filter-jms-selector",
-                                                                         "wibble"));
+                                                                         "wibble"),
+                                                           createBindingParents(TOPIC_EXCHANGE_ID,QUEUE_ID)));
 
         final ConfiguredObjectRecord[] expected = {
-                new ConfiguredObjectRecord(new UUID(1, 0), "Binding",
-                        createBinding("key", TOPIC_EXCHANGE_ID, QUEUE_ID, "x-filter-jms-selector",
"wibble"))
+                new ConfiguredObjectRecordImpl(new UUID(1, 0), "Binding",
+                        createBinding("key", "x-filter-jms-selector", "wibble"))
         };
 
         verifyCorrectUpdates(expected);
@@ -331,16 +328,15 @@ public class DurableConfigurationRecover
 
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 2);
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
                                                            "Binding",
                                                            createBinding("key",
-                                                                         DIRECT_EXCHANGE_ID,
-                                                                         QUEUE_ID,
                                                                          "x-filter-jms-selector",
-                                                                         "wibble"));
+                                                                         "wibble"),
+                                                           createBindingParents(DIRECT_EXCHANGE_ID,QUEUE_ID)));
 
         doThrow(new RuntimeException("Update Should not be called"))
-                .when(_store).update(anyBoolean(), any(ConfiguredObjectRecord[].class));
+                .when(_store).update(anyBoolean(), any(ConfiguredObjectRecordImpl[].class));
 
         _durableConfigurationRecoverer.completeConfigurationRecovery();
     }
@@ -350,13 +346,13 @@ public class DurableConfigurationRecover
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 2);
 
 
-        _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
                                                         "Binding",
                                                         createBinding("key",
-                                                                      new UUID(3,0),
-                                                                      QUEUE_ID,
                                                                       "x-filter-jms-selector",
-                                                                      "wibble"));
+                                                                      "wibble"),
+                                                        createBindingParents(new UUID(3,0),
+                                                                             QUEUE_ID)));
 
         try
         {
@@ -378,8 +374,8 @@ public class DurableConfigurationRecover
         try
         {
             final Map<String, Object> emptyArguments = Collections.emptyMap();
-            _durableConfigurationRecoverer.configuredObject(new UUID(1, 0),
-                                                            "Wibble", emptyArguments);
+            _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(new
UUID(1, 0),
+                                                            "Wibble", emptyArguments));
             _durableConfigurationRecoverer.completeConfigurationRecovery();
             fail("Expected resolution to fail due to unknown object type");
         }
@@ -425,11 +421,11 @@ public class DurableConfigurationRecover
 
         _durableConfigurationRecoverer.beginConfigurationRecovery(_store, 2);
 
-        _durableConfigurationRecoverer.configuredObject(queueId, Queue.class.getSimpleName(),
-                                                        createQueue("testQueue", exchangeId));
-        _durableConfigurationRecoverer.configuredObject(exchangeId,
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(queueId,
Queue.class.getSimpleName(),
+                                                        createQueue("testQueue", exchangeId)));
+        _durableConfigurationRecoverer.configuredObject(new ConfiguredObjectRecordImpl(exchangeId,
                                                         org.apache.qpid.server.model.Exchange.class.getSimpleName(),
-                                                        createExchange(CUSTOM_EXCHANGE_NAME,
HeadersExchange.TYPE));
+                                                        createExchange(CUSTOM_EXCHANGE_NAME,
HeadersExchange.TYPE)));
 
         _durableConfigurationRecoverer.completeConfigurationRecovery();
 
@@ -450,16 +446,14 @@ public class DurableConfigurationRecover
 
                 return null;
             }
-        }).when(_store).update(anyBoolean(), any(ConfiguredObjectRecord[].class));
+        }).when(_store).update(anyBoolean(), any(ConfiguredObjectRecordImpl[].class));
     }
 
-    private Map<String,Object> createBinding(String bindingKey, UUID exchangeId, UUID
queueId, String... args)
+    private Map<String,Object> createBinding(String bindingKey, String... args)
     {
         Map<String, Object> binding = new LinkedHashMap<String, Object>();
 
         binding.put("name", bindingKey);
-        binding.put(Binding.EXCHANGE, exchangeId.toString());
-        binding.put(Binding.QUEUE, queueId.toString());
         Map<String,String> argumentMap = new LinkedHashMap<String, String>();
         if(args != null && args.length != 0)
         {
@@ -481,6 +475,15 @@ public class DurableConfigurationRecover
         return binding;
     }
 
+    private Map<String,ConfiguredObjectRecord> createBindingParents(UUID exchangeId,
UUID queueId)
+    {
+        Map<String,ConfiguredObjectRecord> parents = new HashMap<String, ConfiguredObjectRecord>();
+        parents.put("Exchange", new ConfiguredObjectRecordImpl(exchangeId,"Exchange",Collections.<String,Object>emptyMap()));
+        parents.put("Queue", new ConfiguredObjectRecordImpl(queueId,"Queue",Collections.<String,Object>emptyMap()));
+
+        return parents;
+    }
+
 
     private Map<String, Object> createExchange(String name, ExchangeType<HeadersExchange>
type)
     {

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/MessageStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/MessageStoreTest.java?rev=1580561&r1=1580560&r2=1580561&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/MessageStoreTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/MessageStoreTest.java
Sun Mar 23 18:29:22 2014
@@ -190,6 +190,12 @@ public class MessageStoreTest extends Qp
         try
         {
             _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getClass().getName(),
_config, _broker),new VirtualHostRegistry(_broker.getEventLogger()),getVirtualHostModel());
+            when(_virtualHostModel.getId()).thenReturn(_virtualHost.getId());
+
+            ConfiguredObjectRecord objectRecord = mock(ConfiguredObjectRecord.class);
+            when(objectRecord.getId()).thenReturn(_virtualHost.getId());
+            when(objectRecord.getType()).thenReturn(org.apache.qpid.server.model.VirtualHost.class.getSimpleName());
+            when(_virtualHostModel.asObjectRecord()).thenReturn(objectRecord);
         }
         catch (Exception e)
         {

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java?rev=1580561&r1=1580560&r2=1580561&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
Sun Mar 23 18:29:22 2014
@@ -184,41 +184,25 @@ public class SlowMessageStore implements
         return _realStore.addMessage(metaData);
     }
 
-
     @Override
-    public void create(UUID id, String type, Map<String, Object> attributes) throws
StoreException
+    public void create(ConfiguredObjectRecord record) throws StoreException
     {
         doPreDelay("create");
-        _durableConfigurationStore.create(id, type, attributes);
+        _durableConfigurationStore.create(record);
         doPostDelay("create");
     }
 
-    @Override
-    public void remove(UUID id, String type) throws StoreException
-    {
-        doPreDelay("remove");
-        _durableConfigurationStore.remove(id, type);
-        doPostDelay("remove");
-    }
 
     @Override
-    public UUID[] removeConfiguredObjects(final UUID... objects) throws StoreException
+    public UUID[] remove(final ConfiguredObjectRecord... objects) throws StoreException
     {
         doPreDelay("remove");
-        UUID[] removed = _durableConfigurationStore.removeConfiguredObjects(objects);
+        UUID[] removed = _durableConfigurationStore.remove(objects);
         doPostDelay("remove");
         return removed;
     }
 
     @Override
-    public void update(UUID id, String type, Map<String, Object> attributes) throws
StoreException
-    {
-        doPreDelay("update");
-        _durableConfigurationStore.update(id, type, attributes);
-        doPostDelay("update");
-    }
-
-    @Override
     public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws
StoreException
     {
         doPreDelay("update");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message