diff options
| author | Alex Rudyy <orudyy@apache.org> | 2013-02-20 17:17:00 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2013-02-20 17:17:00 +0000 |
| commit | 5ac93e55ad1ec43d4fd985f364cb222d80e915ec (patch) | |
| tree | 4da575d3621f568ed6f660ccac11de9e6e64f74e /qpid/java/broker/src/test | |
| parent | 883120a80c24ca270e13e38c25c18ac3a2dd725a (diff) | |
| download | qpid-python-5ac93e55ad1ec43d4fd985f364cb222d80e915ec.tar.gz | |
QPID-4593: add command line argument to pass path to initial store
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1448306 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
5 files changed, 258 insertions, 60 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 9b7e3794d0..1352ea5164 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 @@ -78,4 +78,28 @@ public class BrokerOptionsTest extends QpidTestCase _options.setLogWatchFrequency(myFreq); assertEquals(myFreq, _options.getLogWatchFrequency()); } + + + public void testDefaultInitialConfigurationStoreType() + { + assertEquals("json", _options.getInitialConfigurationStoreType()); + } + + public void testOverriddenInitialConfigurationStoreType() + { + _options.setInitialConfigurationStoreType("dby"); + assertEquals("dby", _options.getInitialConfigurationStoreType()); + } + + public void testDefaultInitialConfigurationStoreLocation() + { + assertNull(_options.getInitialConfigurationStoreLocation()); + } + + public void testOverriddenInitialConfigurationStoreLocation() + { + final String testConfigFile = "etc/mytestconfig.xml"; + _options.setInitialConfigurationStoreLocation(testConfigFile); + assertEquals(testConfigFile, _options.getInitialConfigurationStoreLocation()); + } } 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 b0533080a5..bef9b8a78b 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 @@ -38,20 +38,26 @@ public class MainTest extends QpidTestCase assertEquals(null, options.getConfigurationStoreLocation()); assertEquals(null, options.getLogConfigFile()); assertEquals(0, options.getLogWatchFrequency()); + assertEquals("json", options.getInitialConfigurationStoreType()); + assertEquals(null, options.getInitialConfigurationStoreLocation()); } public void testConfigurationStoreLocation() { BrokerOptions options = startDummyMain("-sp abcd/config.xml"); - assertEquals("abcd/config.xml", options.getConfigurationStoreLocation()); + + options = startDummyMain("-store-path abcd/config2.xml"); + assertEquals("abcd/config2.xml", options.getConfigurationStoreLocation()); } public void testConfigurationStoreType() { BrokerOptions options = startDummyMain("-st dby"); - assertEquals("dby", options.getConfigurationStoreType()); + + options = startDummyMain("-store-type bdb"); + assertEquals("bdb", options.getConfigurationStoreType()); } public void testLogConfig() @@ -84,6 +90,25 @@ public class MainTest extends QpidTestCase assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h")); } + public void testInitailConfigurationStoreLocation() + { + 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()); + + } + private BrokerOptions startDummyMain(String commandLine) { return (new TestMain(commandLine.split("\\s"))).getOptions(); 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 d9bdd444aa..fa1bd966a7 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 @@ -21,19 +21,24 @@ package org.apache.qpid.server.configuration; import java.io.File; +import java.io.StringWriter; +import java.util.HashMap; +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; +import org.apache.qpid.test.utils.TestFileUtils; import org.apache.qpid.util.FileUtils; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; public class BrokerConfigurationStoreCreatorTest extends QpidTestCase { private File _userStoreLocation; private BrokerConfigurationStoreCreator _storeCreator; - private BrokerOptions _options; public void setUp() throws Exception { @@ -47,7 +52,6 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase } _storeCreator = new BrokerConfigurationStoreCreator(); _userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName()); - _options = new BrokerOptions(); } public void tearDown() throws Exception @@ -67,7 +71,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase public void testCreateJsonStore() { - ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _options); + ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", null, null); assertNotNull("Store was not created", store); assertTrue("File should exists", _userStoreLocation.exists()); assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0); @@ -77,12 +81,45 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty()); } + public void testCreateJsonStoreFromInitialStore() throws Exception + { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + + Map<String, Object> brokerObjectMap = new HashMap<String, Object>(); + UUID brokerId = UUID.randomUUID(); + brokerObjectMap.put(Broker.ID, brokerId); + brokerObjectMap.put("name", "Test"); + + StringWriter sw = new StringWriter(); + objectMapper.writeValue(sw, brokerObjectMap); + + String brokerJson = sw.toString(); + + File _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson); + + ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath(), "json"); + 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()); + ConfigurationEntry entry = jsonStore.getRootEntry(); + assertEquals("Unexpected root id", brokerId, entry.getId()); + Map<String, Object> attributes = entry.getAttributes(); + assertNotNull("Unexpected attributes: " + attributes, attributes); + assertEquals("Unexpected attributes size: " + attributes.size(), 1, attributes.size()); + assertEquals("Unexpected attribute name: " + attributes.get("name"), "Test", attributes.get("name")); + Set<UUID> childrenIds = entry.getChildrenIds(); + assertTrue("Unexpected children: " + childrenIds, childrenIds.isEmpty()); + } + public void testCreateDerbyStore() { //TODO: Implement DERBY store try { - _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", _options); + _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null, null); fail("Store is not yet supported"); } catch(IllegalConfigurationException e) @@ -95,7 +132,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase { try { - _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", _options); + _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", null, 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 a18d5501f0..7c9f4889f8 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 @@ -1,6 +1,7 @@ package org.apache.qpid.server.configuration.store; import java.io.File; +import java.io.IOException; import java.io.StringWriter; import java.util.Collections; import java.util.HashMap; @@ -11,6 +12,8 @@ import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.model.Broker; import org.apache.qpid.test.utils.TestFileUtils; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; @@ -19,6 +22,15 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest private File _storeFile; private ObjectMapper _objectMapper; + @Override + public void setUp() throws Exception + { + _objectMapper = new ObjectMapper(); + _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + super.setUp(); + } + + @Override public void tearDown() throws Exception { _storeFile.delete(); @@ -28,9 +40,15 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest @Override protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception { - _objectMapper = new ObjectMapper(); - _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); + _storeFile = createStoreFile(brokerId, brokerAttributes); + JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); + store.open(_storeFile.getAbsolutePath()); + return store; + } + private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes) throws IOException, + JsonGenerationException, JsonMappingException + { Map<String, Object> brokerObjectMap = new HashMap<String, Object>(); brokerObjectMap.put(Broker.ID, brokerId); brokerObjectMap.put("@type", Broker.class.getSimpleName()); @@ -41,11 +59,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest String brokerJson = sw.toString(); - _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson); - - JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); - store.open(_storeFile.getAbsolutePath()); - return store; + return TestFileUtils.createTempFile(this, ".json", brokerJson); } @Override @@ -74,4 +88,129 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE)); } + public void testOpenEmpty() + { + 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()); + } + + public void testOpenNotEmpty() 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()); + + 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 testOpenWithInitialStore() 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()); + + File storeFile = TestFileUtils.createTempFile(this, ".json"); + JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(); + store.open(storeFile.getAbsolutePath(), 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)); + } + + 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/model/BrokerShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java index 6ed9740c6d..7c1db6348b 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.model; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryStore; @@ -95,51 +96,23 @@ public class BrokerShutdownTest extends QpidTestCase private Broker startBroker() throws Exception { - // test store with only broker and authentication provider entries - ConfigurationEntryStore store = new ConfigurationEntryStore() - { - private UUID _brokerId = UUID.randomUUID(); - private UUID _authenticationProviderId = UUID.randomUUID(); - - @Override - public ConfigurationEntry getRootEntry() - { - return new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), - Collections.singleton(_authenticationProviderId), this); - } - - @Override - public ConfigurationEntry getEntry(UUID id) - { - if (_authenticationProviderId.equals(id)) - { - File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users"); - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); - attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath()); - return new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes, - Collections.<UUID> emptySet(), this); - } - return null; - } - - @Override - public void save(ConfigurationEntry... entries) - { - } - - @Override - public UUID[] remove(UUID... entryIds) - { - return null; - } - - @Override - public void open(String storeLocation) - { - } - - }; + ConfigurationEntryStore store = mock(ConfigurationEntryStore.class); + UUID brokerId = UUID.randomUUID(); + UUID authenticationProviderId = UUID.randomUUID(); + + ConfigurationEntry root = new ConfigurationEntry(brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), + Collections.singleton(authenticationProviderId), store); + + File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users"); + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); + attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath()); + ConfigurationEntry authenticationProviderEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes, + Collections.<UUID> emptySet(), store); + + when(store.getRootEntry()).thenReturn(root); + when(store.getEntry(brokerId)).thenReturn(root); + when(store.getEntry(authenticationProviderId)).thenReturn(authenticationProviderEntry); // mocking the required object StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class); |
