diff options
Diffstat (limited to 'qpid/java/broker/src/test')
6 files changed, 134 insertions, 176 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java index 9105f5b2e7..7a7df66c57 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java @@ -106,28 +106,16 @@ public class BrokerOptionsTest extends QpidTestCase assertEquals(myFreq, _options.getLogWatchFrequency()); } - - public void testDefaultInitialConfigurationStoreType() - { - assertEquals("json", _options.getInitialConfigurationStoreType()); - } - - public void testOverriddenInitialConfigurationStoreType() - { - _options.setInitialConfigurationStoreType("dby"); - assertEquals("dby", _options.getInitialConfigurationStoreType()); - } - - public void testDefaultInitialConfigurationStoreLocation() + public void testDefaultInitialConfigurationLocation() { - assertNull(_options.getInitialConfigurationStoreLocation()); + assertEquals(BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, _options.getInitialConfigurationLocation()); } - public void testOverriddenInitialConfigurationStoreLocation() + public void testOverriddenInitialConfigurationLocation() { - final String testConfigFile = "etc/mytestconfig.xml"; - _options.setInitialConfigurationStoreLocation(testConfigFile); - assertEquals(testConfigFile, _options.getInitialConfigurationStoreLocation()); + final String testConfigFile = "etc/mytestconfig.json"; + _options.setInitialConfigurationLocation(testConfigFile); + assertEquals(testConfigFile, _options.getInitialConfigurationLocation()); } public void testDefaultManagementMode() diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java index 6ca9a55d7b..46c63c9e34 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java @@ -46,8 +46,7 @@ public class MainTest extends QpidTestCase assertEquals(expectedStorePath, options.getConfigurationStoreLocation()); assertEquals(null, options.getLogConfigFile()); assertEquals(0, options.getLogWatchFrequency()); - assertEquals("json", options.getInitialConfigurationStoreType()); - assertEquals(null, options.getInitialConfigurationStoreLocation()); + assertEquals(BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, options.getInitialConfigurationLocation()); assertFalse(options.isManagementMode()); assertEquals(0, options.getManagementModeConnectorPort()); @@ -103,23 +102,13 @@ public class MainTest extends QpidTestCase assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h")); } - public void testInitailConfigurationStoreLocation() + public void testInitailConfigurationLocation() { - BrokerOptions options = startDummyMain("-isp abcd/config.xml"); - assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation()); - - options = startDummyMain("-initial-store-path abcd/config.xml"); - assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation()); - } - - public void testInitialConfigurationStoreType() - { - BrokerOptions options = startDummyMain("-ist dby"); - assertEquals("dby", options.getInitialConfigurationStoreType()); - - options = startDummyMain("-initial-store-type bdb"); - assertEquals("bdb", options.getInitialConfigurationStoreType()); + BrokerOptions options = startDummyMain("-icp abcd/initial-config.json"); + assertEquals("abcd/initial-config.json", options.getInitialConfigurationLocation()); + options = startDummyMain("-initial-config-path abcd/initial-config.json"); + assertEquals("abcd/initial-config.json", options.getInitialConfigurationLocation()); } public void testManagementMode() diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java index afb7559d9d..d61117868f 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore; import org.apache.qpid.server.model.Broker; import org.apache.qpid.test.utils.QpidTestCase; @@ -49,6 +50,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase { // set the properties in order to resolve the defaults store settings setTestSystemProperty("QPID_HOME", TMP_FOLDER); + setTestSystemProperty("QPID_WORK", TMP_FOLDER + File.separator + "work"); } _storeCreator = new BrokerConfigurationStoreCreator(); _userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName()); @@ -71,12 +73,11 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase public void testCreateJsonStore() { - ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", null, null); + ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION); assertNotNull("Store was not created", store); assertTrue("File should exists", _userStoreLocation.exists()); assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0); - JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(); - jsonStore.open(_userStoreLocation.getAbsolutePath()); + JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(_userStoreLocation.getAbsolutePath(), null); Set<UUID> childrenIds = jsonStore.getRootEntry().getChildrenIds(); assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty()); } @@ -98,12 +99,11 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase File _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson); - ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath(), "json"); + ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath()); assertNotNull("Store was not created", store); assertTrue("File should exists", _userStoreLocation.exists()); assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0); - JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(); - jsonStore.open(_userStoreLocation.getAbsolutePath()); + JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore(_userStoreLocation.getAbsolutePath(), null); ConfigurationEntry entry = jsonStore.getRootEntry(); assertEquals("Unexpected root id", brokerId, entry.getId()); Map<String, Object> attributes = entry.getAttributes(); @@ -118,7 +118,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase { try { - _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null, null); + _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null); fail("Store is not yet supported"); } catch(IllegalConfigurationException e) diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java index 7c9f4889f8..92e304ab86 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java @@ -10,6 +10,7 @@ import java.util.UUID; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.Broker; import org.apache.qpid.test.utils.TestFileUtils; import org.codehaus.jackson.JsonGenerationException; @@ -41,8 +42,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception { _storeFile = createStoreFile(brokerId, brokerAttributes); - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(_storeFile.getAbsolutePath()); + JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(_storeFile.getAbsolutePath(), null); return store; } @@ -82,84 +82,33 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest attributes, brokerConfigEntry.getChildrenIds(), store); store.save(updatedBrokerEntry); - JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore(); - store2.open(_storeFile.getAbsolutePath()); + JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore(_storeFile.getAbsolutePath(), null); assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE)); } - public void testOpenEmpty() + public void testCreateEmptyStore() { File file = TestFileUtils.createTempFile(this, ".json"); - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(file.getAbsolutePath()); - ConfigurationEntry root = store.getRootEntry(); - assertNotNull("Root entry is not found", root); - store.copyTo(file.getAbsolutePath()); - - JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore(); - store2.open(file.getAbsolutePath()); - ConfigurationEntry root2 = store.getRootEntry(); - assertEquals("Unexpected root entry", root.getId(), root2.getId()); + try + { + new JsonConfigurationEntryStore(file.getAbsolutePath(), null); + fail("Cannot create a new store without initial store"); + } + catch(IllegalConfigurationException e) + { + // pass + } } - public void testOpenNotEmpty() throws Exception + public void testCreateFromExistingLocation() throws Exception { UUID brokerId = UUID.randomUUID(); Map<String, Object> brokerAttributes = new HashMap<String, Object>(); brokerAttributes.put(Broker.NAME, getTestName()); File file = createStoreFile(brokerId, brokerAttributes); - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(file.getAbsolutePath()); - ConfigurationEntry root = store.getRootEntry(); - assertNotNull("Root entry is not found", root); - assertEquals("Unexpected root entry", brokerId, root.getId()); - Map<String, Object> attributes = root.getAttributes(); - assertNotNull("Attributes not found", attributes); - assertEquals("Unexpected number of attriburtes", 1, attributes.size()); - assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); - } - - public void testOpenInMemoryEmpty() - { - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(JsonConfigurationEntryStore.IN_MEMORY); - - ConfigurationEntry root = store.getRootEntry(); - assertNotNull("Root entry is not found", root); - } - - public void testOpenWithInitialStoreLocation() throws Exception - { - UUID brokerId = UUID.randomUUID(); - Map<String, Object> brokerAttributes = new HashMap<String, Object>(); - brokerAttributes.put(Broker.NAME, getTestName()); - File initialStoreFile = createStoreFile(brokerId, brokerAttributes); - - File storeFile = TestFileUtils.createTempFile(this, ".json"); - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(storeFile.getAbsolutePath(), initialStoreFile.getAbsolutePath()); - - ConfigurationEntry root = store.getRootEntry(); - assertNotNull("Root entry is not found", root); - assertEquals("Unexpected root entry", brokerId, root.getId()); - Map<String, Object> attributes = root.getAttributes(); - assertNotNull("Attributes not found", attributes); - assertEquals("Unexpected number of attriburtes", 1, attributes.size()); - assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); - } - - public void testOpenInMemoryWithInitialStoreLocation() throws Exception - { - UUID brokerId = UUID.randomUUID(); - Map<String, Object> brokerAttributes = new HashMap<String, Object>(); - brokerAttributes.put(Broker.NAME, getTestName()); - File initialStoreFile = createStoreFile(brokerId, brokerAttributes); - - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStoreFile.getAbsolutePath()); - + JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(file.getAbsolutePath(), null); ConfigurationEntry root = store.getRootEntry(); assertNotNull("Root entry is not found", root); assertEquals("Unexpected root entry", brokerId, root.getId()); @@ -169,19 +118,17 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); } - public void testOpenWithInitialStore() throws Exception + public void testCreateFromInitialStore() throws Exception { UUID brokerId = UUID.randomUUID(); Map<String, Object> brokerAttributes = new HashMap<String, Object>(); brokerAttributes.put(Broker.NAME, getTestName()); File initialStoreFile = createStoreFile(brokerId, brokerAttributes); - JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore(); - initialStore.open(initialStoreFile.getAbsolutePath()); + JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore(initialStoreFile.getAbsolutePath(), null); File storeFile = TestFileUtils.createTempFile(this, ".json"); - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(storeFile.getAbsolutePath(), initialStore); + JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(storeFile.getAbsolutePath(), initialStore); ConfigurationEntry root = store.getRootEntry(); assertNotNull("Root entry is not found", root); @@ -192,25 +139,4 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); } - public void testOpenInMemoryWithInitialStore() throws Exception - { - UUID brokerId = UUID.randomUUID(); - Map<String, Object> brokerAttributes = new HashMap<String, Object>(); - brokerAttributes.put(Broker.NAME, getTestName()); - File initialStoreFile = createStoreFile(brokerId, brokerAttributes); - - JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore(); - initialStore.open(initialStoreFile.getAbsolutePath()); - - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStore); - - ConfigurationEntry root = store.getRootEntry(); - assertNotNull("Root entry is not found", root); - assertEquals("Unexpected root entry", brokerId, root.getId()); - Map<String, Object> attributes = root.getAttributes(); - assertNotNull("Attributes not found", attributes); - assertEquals("Unexpected number of attriburtes", 1, attributes.size()); - assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); - } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java index a67daac610..52e021240e 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java @@ -5,7 +5,6 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.any; -import java.io.File; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -15,7 +14,6 @@ import java.util.Map; import java.util.UUID; import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.configuration.IllegalConfigurationException; @@ -54,46 +52,6 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase _handler = new ManagementModeStoreHandler(_store, _options); } - public void testOpenString() - { - try - { - _handler.open(TMP_FOLDER + File.separator + getTestName()); - fail("Exception should be thrown on attempt to call open method on a handler"); - } - catch (IllegalStateException e) - { - // pass - } - } - - public void testOpenStringString() - { - try - { - _handler.open(TMP_FOLDER + File.separator + getTestName(), - BrokerConfigurationStoreCreator.DEFAULT_INITIAL_STORE_LOCATION); - fail("Exception should be thrown on attempt to call open method on a handler"); - } - catch (IllegalStateException e) - { - // pass - } - } - - public void testOpenStringConfigurationEntryStore() - { - try - { - _handler.open(TMP_FOLDER + File.separator + getTestName(), _store); - fail("Exception should be thrown on attempt to call open method on a handler"); - } - catch (IllegalStateException e) - { - // pass - } - } - public void testGetRootEntryWithEmptyOptions() { ConfigurationEntry root = _handler.getRootEntry(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java new file mode 100644 index 0000000000..65ced69915 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java @@ -0,0 +1,97 @@ +package org.apache.qpid.server.configuration.store; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.Broker; +import org.codehaus.jackson.map.ObjectMapper; + +public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase +{ + + @Override + protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception + { + Map<String, Object> broker = new HashMap<String, Object>(); + broker.put(Broker.ID, brokerId); + broker.putAll(brokerAttributes); + ObjectMapper mapper = new ObjectMapper(); + + return new MemoryConfigurationEntryStore(mapper.writeValueAsString(broker)); + } + + @Override + protected void addConfiguration(UUID id, String type, Map<String, Object> attributes) + { + ConfigurationEntryStore store = getStore(); + store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store)); + } + + public void testCreateWithNullLocationAndNullInitialStore() + { + try + { + new MemoryConfigurationEntryStore(null, null); + fail("Cannot create a memory store without either initial store or path to an initial store file"); + } + catch(IllegalConfigurationException e) + { + // pass + } + } + + public void testCreateWithNullJson() + { + MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(null); + + ConfigurationEntry root = store.getRootEntry(); + assertNotNull("Root entry is not found", root); + } + + public void testOpenInMemoryWithInitialStore() throws Exception + { + UUID brokerId = UUID.randomUUID(); + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + brokerAttributes.put(Broker.NAME, getTestName()); + MemoryConfigurationEntryStore initialStoreFile = (MemoryConfigurationEntryStore)createStore(brokerId, brokerAttributes); + MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(null, initialStoreFile); + + ConfigurationEntry root = store.getRootEntry(); + assertNotNull("Root entry is not found", root); + assertEquals("Unexpected root entry", brokerId, root.getId()); + Map<String, Object> attributes = root.getAttributes(); + assertNotNull("Attributes not found", attributes); + assertEquals("Unexpected number of attriburtes", 1, attributes.size()); + assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); + } + + + public void testOpenWithDefaultInitialStore() throws Exception + { + // check whether QPID_HOME JVM system property is set + if (QPID_HOME == null) + { + // set the properties in order to resolve the defaults store settings + setTestSystemProperty("QPID_HOME", TMP_FOLDER); + setTestSystemProperty("QPID_WORK", TMP_FOLDER + File.separator + "work"); + } + MemoryConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, null); + ConfigurationEntry initialStoreRoot = initialStore.getRootEntry(); + assertNotNull("Initial store root entry is not found", initialStoreRoot); + + MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(null, initialStore); + + ConfigurationEntry root = store.getRootEntry(); + assertNotNull("Root entry is not found", root); + + assertEquals("Unexpected broker attributes", initialStoreRoot.getAttributes(), root.getAttributes()); + assertEquals("Unexpected broker children", initialStoreRoot.getChildrenIds(), root.getChildrenIds()); + } +} |
