summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2013-04-15 10:38:03 +0000
committerRobert Gemmell <robbie@apache.org>2013-04-15 10:38:03 +0000
commit5eef6907dde64786c1d68d4903a7a5904fff6068 (patch)
tree1460a054a80e06c1c3bc83bc82b6d347482d313c /qpid/java/broker/src/test
parent8123a2f1895047072b78438ced886558d470000d (diff)
downloadqpid-python-5eef6907dde64786c1d68d4903a7a5904fff6068.tar.gz
QPID-4741: add command line option to request overwritig existing broker config store with current initial config file
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1467930 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java14
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java11
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java50
3 files changed, 64 insertions, 11 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 b36d1bd21f..c1acf81a1a 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
@@ -28,8 +28,9 @@ public class BrokerOptionsTest extends QpidTestCase
{
private BrokerOptions _options;
- protected void setUp()
+ protected void setUp() throws Exception
{
+ super.setUp();
_options = new BrokerOptions();
}
@@ -208,4 +209,15 @@ public class BrokerOptionsTest extends QpidTestCase
_options.setSkipLoggingConfiguration(true);
assertTrue(_options.isSkipLoggingConfiguration());
}
+
+ public void testDefaultOverwriteConfigurationStore()
+ {
+ assertFalse(_options.isOverwriteConfigurationStore());
+ }
+
+ public void testOverriddenOverwriteConfigurationStore()
+ {
+ _options.setOverwriteConfigurationStore(true);
+ assertTrue(_options.isOverwriteConfigurationStore());
+ }
}
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 b587ee9030..aab919a828 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
@@ -47,7 +47,7 @@ public class MainTest extends QpidTestCase
assertEquals(null, options.getLogConfigFile());
assertEquals(0, options.getLogWatchFrequency());
assertEquals(BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, options.getInitialConfigurationLocation());
-
+ assertFalse(options.isOverwriteConfigurationStore());
assertFalse(options.isManagementMode());
assertEquals(0, options.getManagementModeConnectorPort());
assertEquals(0, options.getManagementModeRmiPort());
@@ -72,6 +72,15 @@ public class MainTest extends QpidTestCase
assertEquals("bdb", options.getConfigurationStoreType());
}
+ public void testOverwriteConfigurationStore()
+ {
+ BrokerOptions options = startDummyMain("-os");
+ assertTrue(options.isOverwriteConfigurationStore());
+
+ options = startDummyMain("-overwrite-store");
+ assertTrue(options.isOverwriteConfigurationStore());
+ }
+
public void testLogConfig()
{
BrokerOptions options = startDummyMain("-l wxyz/log4j.xml");
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 d61117868f..47e6849c01 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
@@ -73,7 +73,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
public void testCreateJsonStore()
{
- ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION);
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, false);
assertNotNull("Store was not created", store);
assertTrue("File should exists", _userStoreLocation.exists());
assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
@@ -84,41 +84,73 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
public void testCreateJsonStoreFromInitialStore() throws Exception
{
+ createJsonStoreFromInitialStoreTestImpl(false);
+ }
+
+ public void testOverwriteExistingJsonStoreWithInitialConfig() throws Exception
+ {
+ createJsonStoreFromInitialStoreTestImpl(true);
+ }
+
+ public void createJsonStoreFromInitialStoreTestImpl(boolean overwrite) throws Exception
+ {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ String defaultBrokerName = "QpidBroker";
+ String testBrokerName = getTestName();
+
Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
- UUID brokerId = UUID.randomUUID();
- brokerObjectMap.put(Broker.ID, brokerId);
- brokerObjectMap.put("name", "Test");
+ UUID testBrokerId = UUID.randomUUID();
+ brokerObjectMap.put(Broker.ID, testBrokerId);
+ brokerObjectMap.put("name", testBrokerName);
StringWriter sw = new StringWriter();
objectMapper.writeValue(sw, brokerObjectMap);
String brokerJson = sw.toString();
- File _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
+ File _initialStoreFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
- ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath());
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _initialStoreFile.getAbsolutePath(), false);
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(_userStoreLocation.getAbsolutePath(), null);
ConfigurationEntry entry = jsonStore.getRootEntry();
- assertEquals("Unexpected root id", brokerId, entry.getId());
+ assertEquals("Unexpected root id", testBrokerId, 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"));
+ assertEquals("Unexpected attribute name: " + attributes.get("name"), testBrokerName, attributes.get(Broker.NAME));
Set<UUID> childrenIds = entry.getChildrenIds();
assertTrue("Unexpected children: " + childrenIds, childrenIds.isEmpty());
+
+ if(overwrite)
+ {
+ ConfigurationEntryStore overwrittenStore = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, true);
+ assertNotNull("Store was not created", overwrittenStore);
+ assertTrue("File should exists", _userStoreLocation.exists());
+ assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
+
+ //check the contents reflect the test store content having been overwritten with the default store
+ JsonConfigurationEntryStore reopenedOverwrittenStore = new JsonConfigurationEntryStore(_userStoreLocation.getAbsolutePath(), null, false);
+ entry = reopenedOverwrittenStore.getRootEntry();
+ assertFalse("Root id did not change, store content was not overwritten", testBrokerId.equals(entry.getId()));
+ attributes = entry.getAttributes();
+ assertNotNull("No attributes found", attributes);
+ assertFalse("Test name should not equal default broker name", testBrokerName.equals(defaultBrokerName));
+ assertEquals("Unexpected broker name value" , defaultBrokerName, attributes.get(Broker.NAME));
+ childrenIds = entry.getChildrenIds();
+ assertFalse("Expected children were not found" + childrenIds, childrenIds.isEmpty());
+ }
}
public void testCreateStoreWithUnknownType()
{
try
{
- _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null);
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null, false);
fail("Store is not yet supported");
}
catch(IllegalConfigurationException e)