diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2013-06-19 15:51:30 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2013-06-19 15:51:30 +0000 |
| commit | 706675d432369def04b47ab935a17adec390e202 (patch) | |
| tree | b4c85415ad3a305e47d4d8af51a43b39bcd5a106 /qpid/java/broker/src/test | |
| parent | 0c801f4ef8be29a0a756bce67651cac7f583a525 (diff) | |
| download | qpid-python-706675d432369def04b47ab935a17adec390e202.tar.gz | |
QPID-4937 : [Java Broker] separate virtualhosts into different types
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1494667 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
9 files changed, 133 insertions, 158 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java index 713cd25adb..c6473d9520 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java @@ -35,6 +35,7 @@ import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.stats.StatisticsGatherer; +import org.apache.qpid.server.virtualhost.StandardVirtualHostFactory; import org.apache.qpid.test.utils.TestFileUtils; public class VirtualHostRecovererTest extends TestCase @@ -75,6 +76,8 @@ public class VirtualHostRecovererTest extends TestCase VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(VirtualHost.NAME, getName()); + attributes.put(VirtualHost.TYPE, StandardVirtualHostFactory.TYPE); + attributes.put(VirtualHost.STORE_PATH, "/path/to/virtualhost/store"); attributes.put(VirtualHost.STORE_TYPE, "DERBY"); when(entry.getAttributes()).thenReturn(attributes); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java index 478013f61f..05d5d75864 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java @@ -23,7 +23,6 @@ package org.apache.qpid.server.model; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.File; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -39,14 +38,10 @@ import org.apache.qpid.server.logging.SystemOutMessageLogger; import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.actors.TestLogActor; import org.apache.qpid.server.stats.StatisticsGatherer; -import org.apache.qpid.server.store.Event; -import org.apache.qpid.server.store.EventListener; -import org.apache.qpid.server.store.EventManager; import org.apache.qpid.server.store.MemoryMessageStore; -import org.apache.qpid.server.store.NullMessageStore; -import org.apache.qpid.server.store.StateManager; import org.apache.qpid.server.util.BrokerTestHelper; -import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.server.virtualhost.StandardVirtualHost; +import org.apache.qpid.server.virtualhost.StandardVirtualHostFactory; public class VirtualHostTest extends TestCase { @@ -96,6 +91,7 @@ public class VirtualHostTest extends TestCase { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(VirtualHost.NAME, getName()); + attributes.put(VirtualHost.TYPE, StandardVirtualHostFactory.TYPE); attributes.put(VirtualHost.STORE_TYPE, MemoryMessageStore.TYPE); attributes.put(VirtualHost.STATE, State.QUIESCED); @@ -130,36 +126,11 @@ public class VirtualHostTest extends TestCase assertEquals("Unexpected state", State.DELETED, host.getAttribute(VirtualHost.STATE)); } - public void testReplicaState() - { - String hostName = getName(); - File configPath = TestFileUtils.createTempFile(this, ".xml", "<virtualhosts><virtualhost><" + hostName - + "><store><class>" + ReplicaMessageStore.class.getName() + "</class></store></" + hostName - + "></virtualhost></virtualhosts>"); - try - { - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(VirtualHost.NAME, hostName); - attributes.put(VirtualHost.CONFIG_PATH, configPath.getAbsolutePath()); - - VirtualHost host = createHost(attributes); - - assertEquals("Unexpected state", State.INITIALISING, host.getAttribute(VirtualHost.STATE)); - - host.setDesiredState(State.INITIALISING, State.ACTIVE); - - assertEquals("Unexpected state", State.REPLICA, host.getAttribute(VirtualHost.STATE)); - } - finally - { - configPath.delete(); - } - } - private VirtualHost createHost() { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(VirtualHost.NAME, getName()); + attributes.put(VirtualHost.TYPE, StandardVirtualHostFactory.TYPE); attributes.put(VirtualHost.STORE_TYPE, MemoryMessageStore.TYPE); VirtualHost host = createHost(attributes); @@ -174,34 +145,4 @@ public class VirtualHostTest extends TestCase return new VirtualHostRecoverer(_statisticsGatherer).create(_recovererProvider, entry, _broker); } - public static final class ReplicaMessageStore extends NullMessageStore - { - private final EventManager _eventManager = new EventManager(); - private final StateManager _stateManager = new StateManager(_eventManager); - - @Override - public void activate() throws Exception - { - _stateManager.attainState(org.apache.qpid.server.store.State.INITIALISING); - _stateManager.attainState(org.apache.qpid.server.store.State.INITIALISED); - _stateManager.attainState(org.apache.qpid.server.store.State.ACTIVATING); - _stateManager.attainState(org.apache.qpid.server.store.State.ACTIVE); - - // this should change the virtual host state to PASSIVE - _stateManager.attainState(org.apache.qpid.server.store.State.INITIALISED); - } - - @Override - public void addEventListener(EventListener eventListener, Event... events) - { - _eventManager.addEventListener(eventListener, events); - } - - @Override - public String getStoreType() - { - return ReplicaMessageStore.class.getSimpleName(); - } - } - } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java index f0ecfb6407..8a7d5d85fc 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java @@ -65,7 +65,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase private static final String EXCHANGE_NAME = "exchangeName"; private String _storePath; private String _storeName; - private MessageStore _store; + private MessageStore _messageStore; private Configuration _configuration; private ConfigurationRecoveryHandler _recoveryHandler; @@ -84,6 +84,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase private FieldTable _bindingArgs; private UUID _queueId; private UUID _exchangeId; + private DurableConfigurationStore _configStore; public void setUp() throws Exception { @@ -135,7 +136,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase public void testCreateExchange() throws Exception { Exchange exchange = createTestExchange(); - _store.createExchange(exchange); + _configStore.createExchange(exchange); reopenStore(); verify(_exchangeRecoveryHandler).exchange(_exchangeId, getName(), getName() + "Type", true); @@ -144,9 +145,9 @@ public class DurableConfigurationStoreTest extends QpidTestCase public void testRemoveExchange() throws Exception { Exchange exchange = createTestExchange(); - _store.createExchange(exchange); + _configStore.createExchange(exchange); - _store.removeExchange(exchange); + _configStore.removeExchange(exchange); reopenStore(); verify(_exchangeRecoveryHandler, never()).exchange(any(UUID.class), anyString(), anyString(), anyBoolean()); @@ -157,7 +158,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false); Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue, _exchange, FieldTable.convertToMap(_bindingArgs)); - _store.bindQueue(binding); + _configStore.bindQueue(binding); reopenStore(); @@ -171,9 +172,9 @@ public class DurableConfigurationStoreTest extends QpidTestCase AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false); Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue, _exchange, FieldTable.convertToMap(_bindingArgs)); - _store.bindQueue(binding); + _configStore.bindQueue(binding); - _store.unbindQueue(binding); + _configStore.unbindQueue(binding); reopenStore(); verify(_bindingRecoveryHandler, never()).binding(any(UUID.class), any(UUID.class), any(UUID.class), anyString(), @@ -183,7 +184,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase public void testCreateQueueAMQQueue() throws Exception { AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true); - _store.createQueue(queue); + _configStore.createQueue(queue); reopenStore(); verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", true, null, null); @@ -197,7 +198,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase attributes.put("x-qpid-maximum-delivery-count", new Integer(10)); FieldTable arguments = FieldTable.convertToFieldTable(attributes); - _store.createQueue(queue, arguments); + _configStore.createQueue(queue, arguments); reopenStore(); verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", true, arguments, null); @@ -208,7 +209,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase Exchange alternateExchange = createTestAlternateExchange(); AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true, alternateExchange); - _store.createQueue(queue); + _configStore.createQueue(queue); reopenStore(); verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", true, null, alternateExchange.getId()); @@ -230,11 +231,11 @@ public class DurableConfigurationStoreTest extends QpidTestCase attributes.put("x-qpid-dlq-enabled", Boolean.TRUE); attributes.put("x-qpid-maximum-delivery-count", new Integer(10)); FieldTable arguments = FieldTable.convertToFieldTable(attributes); - _store.createQueue(queue, arguments); + _configStore.createQueue(queue, arguments); // update the queue to have exclusive=false queue = createTestQueue(getName(), getName() + "Owner", false); - _store.updateQueue(queue); + _configStore.updateQueue(queue); reopenStore(); verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", false, arguments, null); @@ -248,12 +249,12 @@ public class DurableConfigurationStoreTest extends QpidTestCase attributes.put("x-qpid-dlq-enabled", Boolean.TRUE); attributes.put("x-qpid-maximum-delivery-count", new Integer(10)); FieldTable arguments = FieldTable.convertToFieldTable(attributes); - _store.createQueue(queue, arguments); + _configStore.createQueue(queue, arguments); // update the queue to have exclusive=false Exchange alternateExchange = createTestAlternateExchange(); queue = createTestQueue(getName(), getName() + "Owner", false, alternateExchange); - _store.updateQueue(queue); + _configStore.updateQueue(queue); reopenStore(); verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", false, arguments, alternateExchange.getId()); @@ -267,10 +268,10 @@ public class DurableConfigurationStoreTest extends QpidTestCase attributes.put("x-qpid-dlq-enabled", Boolean.TRUE); attributes.put("x-qpid-maximum-delivery-count", new Integer(10)); FieldTable arguments = FieldTable.convertToFieldTable(attributes); - _store.createQueue(queue, arguments); + _configStore.createQueue(queue, arguments); // remove queue - _store.removeQueue(queue); + _configStore.removeQueue(queue); reopenStore(); verify(_queueRecoveryHandler, never()).queue(any(UUID.class), anyString(), anyString(), anyBoolean(), any(FieldTable.class), any(UUID.class)); @@ -306,18 +307,19 @@ public class DurableConfigurationStoreTest extends QpidTestCase private void reopenStore() throws Exception { - if (_store != null) + if (_messageStore != null) { - _store.close(); + _messageStore.close(); } - _store = createStore(); + _messageStore = createMessageStore(); + _configStore = createConfigStore(); - _store.configureConfigStore(_storeName, _recoveryHandler, _configuration); - _store.configureMessageStore(_storeName, _messageStoreRecoveryHandler, _logRecoveryHandler, _configuration); - _store.activate(); + _configStore.configureConfigStore(_storeName, _recoveryHandler, _configuration); + _messageStore.configureMessageStore(_storeName, _messageStoreRecoveryHandler, _logRecoveryHandler, _configuration); + _messageStore.activate(); } - protected MessageStore createStore() throws Exception + protected MessageStore createMessageStore() throws Exception { String storeClass = System.getProperty(MESSAGE_STORE_CLASS_NAME_KEY); if (storeClass == null) @@ -329,6 +331,26 @@ public class DurableConfigurationStoreTest extends QpidTestCase return messageStore; } + protected DurableConfigurationStore createConfigStore() throws Exception + { + String storeClass = System.getProperty(CONFIGURATION_STORE_CLASS_NAME_KEY); + if (storeClass == null) + { + storeClass = DerbyMessageStore.class.getName(); + } + Class<DurableConfigurationStore> clazz = (Class<DurableConfigurationStore>) Class.forName(storeClass); + DurableConfigurationStore configurationStore ; + if(clazz.isInstance(_messageStore)) + { + configurationStore = (DurableConfigurationStore) _messageStore; + } + else + { + configurationStore = (DurableConfigurationStore) Class.forName(storeClass).newInstance(); + } + return configurationStore; + } + public void testRecordXid() throws Exception { Record enqueueRecord = getTestRecord(1); @@ -338,13 +360,13 @@ public class DurableConfigurationStoreTest extends QpidTestCase byte[] globalId = new byte[] { 1 }; byte[] branchId = new byte[] { 2 }; - Transaction transaction = _store.newTransaction(); + Transaction transaction = _messageStore.newTransaction(); transaction.recordXid(1l, globalId, branchId, enqueues, dequeues); transaction.commitTran(); reopenStore(); verify(_dtxRecordRecoveryHandler).dtxRecord(1l, globalId, branchId, enqueues, dequeues); - transaction = _store.newTransaction(); + transaction = _messageStore.newTransaction(); transaction.removeXid(1l, globalId, branchId); transaction.commitTran(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java index f1976ecee3..8743c4111b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreQuotaEventsTestBase.java @@ -71,7 +71,7 @@ public abstract class MessageStoreQuotaEventsTestBase extends QpidTestCase imple applyStoreSpecificConfiguration(config); _store = createStore(); - _store.configureConfigStore("test", null, config); + ((DurableConfigurationStore)_store).configureConfigStore("test", null, config); _transactionResource = UUID.randomUUID(); _events = new ArrayList<Event>(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java index fbf1828e77..fb255e89f9 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java @@ -65,7 +65,7 @@ import java.util.Map; /** * This tests the MessageStores by using the available interfaces. * - * For persistent stores, it validates that Exchanges, Queues, Bindings and + * For persistent stores, it validates that Exchanges, Queues, Bindings and * Messages are persisted and recovered correctly. */ public class MessageStoreTest extends QpidTestCase @@ -106,7 +106,7 @@ public class MessageStoreTest extends QpidTestCase BrokerTestHelper.setUp(); String storePath = System.getProperty("QPID_WORK") + File.separator + getName(); - + _config = new PropertiesConfiguration(); _config.addProperty("store.class", getTestProfileMessageStoreClassName()); _config.addProperty("store.environment-path", storePath); @@ -224,8 +224,8 @@ public class MessageStoreTest extends QpidTestCase /** * Tests message persistence by running the testQueueExchangeAndBindingCreation() method above - * before reloading the virtual host and ensuring that the persistent messages were restored. - * + * before reloading the virtual host and ensuring that the persistent messages were restored. + * * More specific testing of message persistence is left to store-specific unit testing. */ public void testMessagePersistence() throws Exception @@ -238,7 +238,7 @@ public class MessageStoreTest extends QpidTestCase validateMessageOnQueues(2, false); validateMessageOnTopics(1, false); } - + /** * Tests message removal by running the testMessagePersistence() method above before * clearing the queues, reloading the virtual host, and ensuring that the persistent @@ -250,15 +250,15 @@ public class MessageStoreTest extends QpidTestCase QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); - assertEquals("Incorrect number of queues registered after recovery", + assertEquals("Incorrect number of queues registered after recovery", 6, queueRegistry.getQueues().size()); //clear the queue queueRegistry.getQueue(durableQueueName).clearQueue(); - + //check the messages are gone validateMessageOnQueue(durableQueueName, 0); - + //reload and verify messages arent restored reloadVirtualHost(); @@ -284,17 +284,17 @@ public class MessageStoreTest extends QpidTestCase QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); - assertEquals("Incorrect number of queues registered after recovery", + assertEquals("Incorrect number of queues registered after recovery", 6, queueRegistry.getQueues().size()); //Validate the non-Durable Queues were not recovered. - assertNull("Non-Durable queue still registered:" + priorityQueueName, + assertNull("Non-Durable queue still registered:" + priorityQueueName, queueRegistry.getQueue(priorityQueueName)); - assertNull("Non-Durable queue still registered:" + queueName, + assertNull("Non-Durable queue still registered:" + queueName, queueRegistry.getQueue(queueName)); - assertNull("Non-Durable queue still registered:" + priorityTopicQueueName, + assertNull("Non-Durable queue still registered:" + priorityTopicQueueName, queueRegistry.getQueue(priorityTopicQueueName)); - assertNull("Non-Durable queue still registered:" + topicQueueName, + assertNull("Non-Durable queue still registered:" + topicQueueName, queueRegistry.getQueue(topicQueueName)); //Validate normally expected properties of Queues/Topics @@ -320,26 +320,26 @@ public class MessageStoreTest extends QpidTestCase 1, queueRegistry.getQueues().size()); reloadVirtualHost(); - + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after first recovery", 1, queueRegistry.getQueues().size()); - + //test that removing the queue means it is not recovered next time - getVirtualHost().getMessageStore().removeQueue(queueRegistry.getQueue(durableQueueName)); + getVirtualHost().getDurableConfigurationStore().removeQueue(queueRegistry.getQueue(durableQueueName)); reloadVirtualHost(); - + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after second recovery", 0, queueRegistry.getQueues().size()); - assertNull("Durable queue was not removed:" + durableQueueName, + assertNull("Durable queue was not removed:" + durableQueueName, queueRegistry.getQueue(durableQueueName)); } /** * Tests exchange persistence by creating a selection of exchanges, both durable - * and non durable, and ensuring that following the recovery process the correct + * and non durable, and ensuring that following the recovery process the correct * durable exchanges are still present. */ public void testExchangePersistence() throws Exception @@ -348,7 +348,7 @@ public class MessageStoreTest extends QpidTestCase Map<AMQShortString, Exchange> oldExchanges = createExchanges(); - assertEquals("Incorrect number of exchanges registered before recovery", + assertEquals("Incorrect number of exchanges registered before recovery", origExchangeCount + 3, getVirtualHost().getExchangeRegistry().getExchangeNames().size()); reloadVirtualHost(); @@ -367,33 +367,33 @@ public class MessageStoreTest extends QpidTestCase int origExchangeCount = getVirtualHost().getExchangeRegistry().getExchangeNames().size(); createExchange(DirectExchange.TYPE, directExchangeName, true); - + ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry(); - assertEquals("Incorrect number of exchanges registered before recovery", + assertEquals("Incorrect number of exchanges registered before recovery", origExchangeCount + 1, exchangeRegistry.getExchangeNames().size()); reloadVirtualHost(); - + exchangeRegistry = getVirtualHost().getExchangeRegistry(); - assertEquals("Incorrect number of exchanges registered after first recovery", + assertEquals("Incorrect number of exchanges registered after first recovery", origExchangeCount + 1, exchangeRegistry.getExchangeNames().size()); - + //test that removing the exchange means it is not recovered next time - getVirtualHost().getMessageStore().removeExchange(exchangeRegistry.getExchange(directExchangeName)); + getVirtualHost().getDurableConfigurationStore().removeExchange(exchangeRegistry.getExchange(directExchangeName)); reloadVirtualHost(); - + exchangeRegistry = getVirtualHost().getExchangeRegistry(); - assertEquals("Incorrect number of exchanges registered after second recovery", + assertEquals("Incorrect number of exchanges registered after second recovery", origExchangeCount, exchangeRegistry.getExchangeNames().size()); - assertNull("Durable exchange was not removed:" + directExchangeName, + assertNull("Durable exchange was not removed:" + directExchangeName, exchangeRegistry.getExchange(directExchangeName)); } - + /** * Tests binding persistence by creating a selection of queues and exchanges, both durable * and non durable, then adding bindings with and without selectors before reloading the - * virtual host and verifying that following the recovery process the correct durable + * virtual host and verifying that following the recovery process the correct durable * bindings (those for durable queues to durable exchanges) are still present. */ public void testBindingPersistence() throws Exception @@ -413,7 +413,7 @@ public class MessageStoreTest extends QpidTestCase bindAllQueuesToExchange(directExchange, directRouting); bindAllTopicQueuesToExchange(topicExchange, topicRouting); - assertEquals("Incorrect number of exchanges registered before recovery", + assertEquals("Incorrect number of exchanges registered before recovery", origExchangeCount + 3, getVirtualHost().getExchangeRegistry().getExchangeNames().size()); reloadVirtualHost(); @@ -422,10 +422,10 @@ public class MessageStoreTest extends QpidTestCase validateBindingProperties(); } - + /** * Tests binding removal by creating a durable exchange, and queue, binding them together, - * recovering to verify the persistence, then removing it from the store, and ensuring + * recovering to verify the persistence, then removing it from the store, and ensuring * that following the second reload process it is not recovered. */ public void testDurableBindingRemoval() throws Exception @@ -437,14 +437,14 @@ public class MessageStoreTest extends QpidTestCase createQueue(durableQueueName, false, true, false, false); bindQueueToExchange(exch, directRouting, queueRegistry.getQueue(durableQueueName), false, null); - assertEquals("Incorrect number of bindings registered before recovery", + assertEquals("Incorrect number of bindings registered before recovery", 1, queueRegistry.getQueue(durableQueueName).getBindings().size()); //verify binding is actually normally recovered reloadVirtualHost(); queueRegistry = getVirtualHost().getQueueRegistry(); - assertEquals("Incorrect number of bindings registered after first recovery", + assertEquals("Incorrect number of bindings registered after first recovery", 1, queueRegistry.getQueue(durableQueueName).getBindings().size()); ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry(); @@ -457,13 +457,13 @@ public class MessageStoreTest extends QpidTestCase reloadVirtualHost(); queueRegistry = getVirtualHost().getQueueRegistry(); - assertEquals("Incorrect number of bindings registered after second recovery", + assertEquals("Incorrect number of bindings registered after second recovery", 0, queueRegistry.getQueue(durableQueueName).getBindings().size()); } /** * Validates that the durable exchanges are still present, the non durable exchange is not, - * and that the new exchanges are not the same objects as the provided list (i.e. that the + * and that the new exchanges are not the same objects as the provided list (i.e. that the * reload actually generated new exchange objects) */ private void validateExchanges(int originalNumExchanges, Map<AMQShortString, Exchange> oldExchanges) @@ -484,7 +484,7 @@ public class MessageStoreTest extends QpidTestCase registry.getExchange(topicExchangeName) != oldExchanges.get(topicExchangeName)); // There should only be the original exchanges + our 2 recovered durable exchanges - assertEquals("Incorrect number of exchanges available", + assertEquals("Incorrect number of exchanges available", originalNumExchanges + 2, registry.getExchangeNames().size()); } @@ -562,7 +562,7 @@ public class MessageStoreTest extends QpidTestCase { assertNotSame("Queues cant be both Priority and LastValue based", usePriority, lastValueQueue); } - + if (usePriority) { assertEquals("Queue is no longer a Priority Queue", AMQPriorityQueue.class, queue.getClass()); @@ -705,7 +705,7 @@ public class MessageStoreTest extends QpidTestCase { FieldTable queueArguments = null; - + if(usePriority || lastValueQueue) { assertNotSame("Queues cant be both Priority and LastValue based", usePriority, lastValueQueue); @@ -716,7 +716,7 @@ public class MessageStoreTest extends QpidTestCase queueArguments = new FieldTable(); queueArguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), DEFAULT_PRIORTY_LEVEL); } - + if (lastValueQueue) { queueArguments = new FieldTable(); @@ -735,7 +735,7 @@ public class MessageStoreTest extends QpidTestCase if (queue.isDurable() && !queue.isAutoDelete()) { - getVirtualHost().getMessageStore().createQueue(queue, queueArguments); + getVirtualHost().getDurableConfigurationStore().createQueue(queue, queueArguments); } } catch (AMQException e) @@ -779,7 +779,7 @@ public class MessageStoreTest extends QpidTestCase getVirtualHost().getExchangeRegistry().registerExchange(exchange); if (durable) { - getVirtualHost().getMessageStore().createExchange(exchange); + getVirtualHost().getDurableConfigurationStore().createExchange(exchange); } } catch (AMQException e) @@ -836,7 +836,7 @@ public class MessageStoreTest extends QpidTestCase fail(e.getMessage()); } } - + protected void unbindQueueFromExchange(Exchange exchange, AMQShortString routingKey, AMQQueue queue, boolean useSelector, FieldTable queueArguments) { FieldTable bindArguments = null; @@ -931,4 +931,4 @@ public class MessageStoreTest extends QpidTestCase return _routingKey; } } -}
\ No newline at end of file +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java index 065d6408de..88d5852a17 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java @@ -73,7 +73,7 @@ public abstract class MessageStoreTestCase extends QpidTestCase setUpStoreConfiguration(_storeConfiguration); _store = createMessageStore(); - _store.configureConfigStore(getTestName(), _recoveryHandler, _storeConfiguration); + ((DurableConfigurationStore)_store).configureConfigStore(getTestName(), _recoveryHandler, _storeConfiguration); _store.configureMessageStore(getTestName(), _messageStoreRecoveryHandler, _logRecoveryHandler, _storeConfiguration); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java index 4d10058d17..8de19d9cff 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java @@ -55,8 +55,10 @@ import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.SubjectCreator; import org.apache.qpid.server.stats.StatisticsGatherer; import org.apache.qpid.server.store.TestableMemoryMessageStore; +import org.apache.qpid.server.virtualhost.StandardVirtualHostFactory; import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.server.virtualhost.VirtualHostImpl; +import org.apache.qpid.server.plugin.VirtualHostFactory; +import org.apache.qpid.server.virtualhost.VirtualHostFactoryRegistry; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; public class BrokerTestHelper @@ -96,14 +98,24 @@ public class BrokerTestHelper throws Exception { StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class); - VirtualHost host = new VirtualHostImpl(virtualHostRegistry, statisticsGatherer, new SecurityManager(mock(Broker.class), false), virtualHostConfiguration); + final VirtualHostFactory factory = + virtualHostConfiguration == null ? new StandardVirtualHostFactory() + : VirtualHostFactory.FACTORIES.get(virtualHostConfiguration.getType()); + VirtualHost host = factory.createVirtualHost(virtualHostRegistry, + statisticsGatherer, + new SecurityManager(mock(Broker.class), false), + virtualHostConfiguration); virtualHostRegistry.registerVirtualHost(host); return host; } public static VirtualHost createVirtualHost(VirtualHostConfiguration virtualHostConfiguration) throws Exception { - return new VirtualHostImpl(null, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), virtualHostConfiguration); + final VirtualHostFactory factory = + virtualHostConfiguration == null ? new StandardVirtualHostFactory() + : VirtualHostFactory.FACTORIES.get(virtualHostConfiguration.getType()); + + return factory.createVirtualHost(null, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), virtualHostConfiguration); } public static VirtualHost createVirtualHost(String name, VirtualHostRegistry virtualHostRegistry) throws Exception diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java index 324e36e132..7552a653fe 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java @@ -31,6 +31,7 @@ import org.apache.qpid.server.queue.QueueRegistry; import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.auth.manager.AuthenticationManager; import org.apache.qpid.server.stats.StatisticsCounter; +import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.txn.DtxRegistry; @@ -111,6 +112,11 @@ public class MockVirtualHost implements VirtualHost return null; } + public DurableConfigurationStore getDurableConfigurationStore() + { + return null; + } + public String getName() { return _name; @@ -214,4 +220,4 @@ public class MockVirtualHost implements VirtualHost public void unblock() { } -}
\ No newline at end of file +} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/StandardVirtualHostTest.java index 3ae269ff20..1243d9f7dd 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/StandardVirtualHostTest.java @@ -46,7 +46,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -public class VirtualHostImplTest extends QpidTestCase +public class StandardVirtualHostTest extends QpidTestCase { private VirtualHostRegistry _virtualHostRegistry; @@ -109,14 +109,9 @@ public class VirtualHostImplTest extends QpidTestCase createVirtualHost(queueName, config); fail("virtualhost creation should have failed due to illegal configuration"); } - catch (RuntimeException e) + catch (ConfigurationException e) { - assertNotNull(e.getCause()); - - assertEquals(ConfigurationException.class, e.getCause().getClass()); - - Throwable configException = e.getCause(); - assertEquals("Illegal attempt to bind queue '" + queueName + "' to the default exchange with a key other than the queue name: " + customBinding, configException.getMessage()); + assertEquals("Illegal attempt to bind queue '" + queueName + "' to the default exchange with a key other than the queue name: " + customBinding, e.getMessage()); } } @@ -172,14 +167,9 @@ public class VirtualHostImplTest extends QpidTestCase createVirtualHost(queueName, config); fail("virtualhost creation should have failed due to illegal configuration"); } - catch (RuntimeException e) + catch (ConfigurationException e) { - assertNotNull(e.getCause()); - - assertEquals(ConfigurationException.class, e.getCause().getClass()); - - Throwable configException = e.getCause(); - assertEquals("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName, configException.getMessage()); + assertEquals("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName, e.getMessage()); } } @@ -274,7 +264,7 @@ public class VirtualHostImplTest extends QpidTestCase _virtualHostRegistry = broker.getVirtualHostRegistry(); VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, config, broker); - VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), configuration); + VirtualHost host = new StandardVirtualHostFactory().createVirtualHost(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), configuration); _virtualHostRegistry.registerVirtualHost(host); return host; @@ -282,7 +272,7 @@ public class VirtualHostImplTest extends QpidTestCase /** * Create a configuration file for testing virtualhost creation - * + * * @param vhostName name of the virtualhost * @param queueName name of the queue * @param exchangeName name of a direct exchange to declare (unless dontDeclare = true) and bind the queue to (null = none) @@ -313,6 +303,7 @@ public class VirtualHostImplTest extends QpidTestCase writer.write(" <virtualhost>"); writer.write(" <name>" + vhostName + "</name>"); writer.write(" <" + vhostName + ">"); + writer.write(" <type>" + StandardVirtualHostFactory.TYPE + "</type>"); writer.write(" <store>"); writer.write(" <class>" + MemoryMessageStore.class.getName() + "</class>"); writer.write(" </store>"); @@ -373,7 +364,7 @@ public class VirtualHostImplTest extends QpidTestCase Configuration config = new PropertiesConfiguration(); config.setProperty("store.type", MemoryMessageStore.TYPE); VirtualHostConfiguration configuration = new VirtualHostConfiguration(virtualHostName, config, broker); - VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), configuration); + VirtualHost host = new StandardVirtualHostFactory().createVirtualHost(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(mock(Broker.class), false), configuration); _virtualHostRegistry.registerVirtualHost(host); return host; } |
