diff options
| author | Alex Rudyy <orudyy@apache.org> | 2013-05-03 11:21:16 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2013-05-03 11:21:16 +0000 |
| commit | d5b2c0ea6ee32c86433cfe310374275594184d06 (patch) | |
| tree | 194589ffc5560b769749a0d7ec47ed7290d72885 /qpid/java/broker/src/test | |
| parent | 357d3fab9136a9a279f9d19ead929a864f5641f2 (diff) | |
| download | qpid-python-d5b2c0ea6ee32c86433cfe310374275594184d06.tar.gz | |
QPID-4803: Ensure the modelVersion and storeVersion attributes are saved to the configuration store and validated at startup
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1478732 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
3 files changed, 137 insertions, 8 deletions
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 8fc7d99246..a7772ffd10 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 @@ -31,6 +31,7 @@ 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.server.model.Model; import org.apache.qpid.test.utils.QpidTestCase; import org.apache.qpid.test.utils.TestFileUtils; import org.apache.qpid.util.FileUtils; @@ -104,7 +105,9 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase Map<String, Object> brokerObjectMap = new HashMap<String, Object>(); UUID testBrokerId = UUID.randomUUID(); brokerObjectMap.put(Broker.ID, testBrokerId); - brokerObjectMap.put("name", testBrokerName); + brokerObjectMap.put(Broker.NAME, testBrokerName); + brokerObjectMap.put(Broker.MODEL_VERSION, Model.MODEL_VERSION); + brokerObjectMap.put(Broker.STORE_VERSION, 1); StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, brokerObjectMap); @@ -122,7 +125,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase 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 attributes size: " + attributes.size(), 3, attributes.size()); assertEquals("Unexpected attribute name: " + attributes.get("name"), testBrokerName, attributes.get(Broker.NAME)); Set<UUID> childrenIds = entry.getChildrenIds(); assertTrue("Unexpected children: " + childrenIds, childrenIds.isEmpty()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java index 758eb62809..589f0fc5af 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java @@ -36,6 +36,7 @@ import junit.framework.TestCase; import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer; +import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.configuration.RecovererProvider; import org.apache.qpid.server.logging.LogRecorder; import org.apache.qpid.server.logging.RootMessageLogger; @@ -44,6 +45,7 @@ import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.TrustStore; @@ -77,6 +79,7 @@ public class BrokerRecovererTest extends TestCase mock(StatisticsGatherer.class), mock(VirtualHostRegistry.class), mock(LogRecorder.class), mock(RootMessageLogger.class), mock(TaskExecutor.class), mock(BrokerOptions.class)); when(_brokerEntry.getId()).thenReturn(_brokerId); when(_brokerEntry.getChildren()).thenReturn(_brokerEntryChildren); + when(_brokerEntry.getAttributes()).thenReturn(Collections.<String, Object>singletonMap(Broker.MODEL_VERSION, Model.MODEL_VERSION)); //Add a base AuthenticationProvider for all tests _authenticationProvider1 = mock(AuthenticationProvider.class); @@ -104,6 +107,7 @@ public class BrokerRecovererTest extends TestCase attributes.put(Broker.CONNECTION_HEART_BEAT_DELAY, 2000); attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000); attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true); + attributes.put(Broker.MODEL_VERSION, Model.MODEL_VERSION); Map<String, Object> entryAttributes = new HashMap<String, Object>(); for (Map.Entry<String, Object> attribute : attributes.entrySet()) @@ -191,9 +195,6 @@ public class BrokerRecovererTest extends TestCase ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class); _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2)); - Map<String,Object> brokerAtttributes = new HashMap<String,Object>(); - when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes); - //Add a couple ports ConfigurationEntry portEntry1 = mock(ConfigurationEntry.class); Port port1 = mock(Port.class); @@ -288,6 +289,69 @@ public class BrokerRecovererTest extends TestCase assertEquals(Collections.singleton(trustStore), new HashSet<ConfiguredObject>(broker.getChildren(TrustStore.class))); } + public void testModelVersionValidationForIncompatibleMajorVersion() throws Exception + { + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + String[] incompatibleVersions = {Integer.MAX_VALUE + "." + 0, "0.0"}; + for (String incompatibleVersion : incompatibleVersions) + { + brokerAttributes.put(Broker.MODEL_VERSION, incompatibleVersion); + when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); + + try + { + _brokerRecoverer.create(null, _brokerEntry); + fail("The broker creation should fail due to unsupported model version"); + } + catch (IllegalConfigurationException e) + { + assertEquals("The model version '" + incompatibleVersion + + "' in configuration is incompatible with the broker model version '" + Model.MODEL_VERSION + "'", e.getMessage()); + } + } + } + + + public void testModelVersionValidationForIncompatibleMinorVersion() throws Exception + { + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + String incompatibleVersion = Model.MODEL_MAJOR_VERSION + "." + Integer.MAX_VALUE; + brokerAttributes.put(Broker.MODEL_VERSION, incompatibleVersion); + when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); + + try + { + _brokerRecoverer.create(null, _brokerEntry); + fail("The broker creation should fail due to unsupported model version"); + } + catch (IllegalConfigurationException e) + { + assertEquals("The model version '" + incompatibleVersion + + "' in configuration is incompatible with the broker model version '" + Model.MODEL_VERSION + "'", e.getMessage()); + } + } + + public void testIncorrectModelVersion() throws Exception + { + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + String[] versions = { Integer.MAX_VALUE + "_" + 0, "", null }; + for (String modelVersion : versions) + { + brokerAttributes.put(Broker.MODEL_VERSION, modelVersion); + when(_brokerEntry.getAttributes()).thenReturn(brokerAttributes); + + try + { + _brokerRecoverer.create(null, _brokerEntry); + fail("The broker creation should fail due to unsupported model version"); + } + catch (IllegalConfigurationException e) + { + // pass + } + } + } + private String convertToString(Object attributeValue) { return String.valueOf(attributeValue); 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 9ee93a345f..f328211253 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 @@ -49,10 +49,19 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes) throws IOException, JsonGenerationException, JsonMappingException { + return createStoreFile(brokerId, brokerAttributes, true); + } + + private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes, boolean setVersion) throws IOException, + JsonGenerationException, JsonMappingException + { Map<String, Object> brokerObjectMap = new HashMap<String, Object>(); brokerObjectMap.put(Broker.ID, brokerId); - brokerObjectMap.put("@type", Broker.class.getSimpleName()); - brokerObjectMap.put("storeVersion", 1); + if (setVersion) + { + brokerObjectMap.put(Broker.STORE_VERSION, MemoryConfigurationEntryStore.STORE_VERSION); + } + brokerObjectMap.put(Broker.NAME, getTestName()); brokerObjectMap.putAll(brokerAttributes); StringWriter sw = new StringWriter(); @@ -124,7 +133,6 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest { 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(initialStoreFile.getAbsolutePath(), null, false, Collections.<String,String>emptyMap()); @@ -151,4 +159,58 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest { assertEquals("Unexpected type", "json", getStore().getType()); } + + public void testUnsupportedStoreVersion() throws Exception + { + UUID brokerId = UUID.randomUUID(); + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + int[] storeVersions = {Integer.MAX_VALUE, 0}; + for (int storeVersion : storeVersions) + { + brokerAttributes.put(Broker.STORE_VERSION, storeVersion); + File storeFile = null; + try + { + storeFile = createStoreFile(brokerId, brokerAttributes); + new JsonConfigurationEntryStore(storeFile.getAbsolutePath(), null, false, Collections.<String, String>emptyMap()); + fail("The store creation should fail due to unsupported store version"); + } + catch (IllegalConfigurationException e) + { + assertEquals("The data of version " + storeVersion + + " can not be loaded by store of version " + MemoryConfigurationEntryStore.STORE_VERSION, e.getMessage()); + } + finally + { + if (storeFile != null) + { + storeFile.delete(); + } + } + } + } + + public void testStoreVersionNotSpecified() throws Exception + { + UUID brokerId = UUID.randomUUID(); + Map<String, Object> brokerAttributes = new HashMap<String, Object>(); + File storeFile = null; + try + { + storeFile = createStoreFile(brokerId, brokerAttributes, false); + new JsonConfigurationEntryStore(storeFile.getAbsolutePath(), null, false, Collections.<String, String>emptyMap()); + fail("The store creation should fail due to unspecified store version"); + } + catch (IllegalConfigurationException e) + { + assertEquals("Broker " + Broker.STORE_VERSION + " attribute must be specified", e.getMessage()); + } + finally + { + if (storeFile != null) + { + storeFile.delete(); + } + } + } } |
