gtully commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842680394
##########
artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java:
##########
@@ -708,6 +720,149 @@ public void testValuePostFixModifier() throws Throwable {
Assert.assertEquals(25 * 1024, configuration.getGlobalMaxSize());
}
+ @Test
+ public void testSystemPropValueReplaced() throws Exception {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ Properties properties = new Properties();
+ final String homeFromDefault = "default-home";
+ final String homeFromEnv = System.getenv("HOME");
+ properties.put("name", "${HOME:" + homeFromDefault + "}");
+ configuration.parsePrefixedProperties(properties, null);
+ if (homeFromEnv != null) {
+ Assert.assertEquals(homeFromEnv, configuration.getName());
+ } else {
+ // if $HOME is not set for some platform
+ Assert.assertEquals(homeFromDefault, configuration.getName());
+ }
+ }
+
+ @Test
+ public void testSystemPropValueNoMatch() throws Exception {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ Properties properties = new Properties();
+ properties.put("name", "vv-${SOME_RANDOM_VV}");
+ configuration.parsePrefixedProperties(properties, null);
+ Assert.assertEquals("vv-", configuration.getName());
+ }
+
+ @Test
+ public void testSystemPropValueNonExistWithDefault() throws Exception {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ Properties properties = new Properties();
+ properties.put("name", "vv-${SOME_RANDOM_VV:y}");
+ configuration.parsePrefixedProperties(properties, null);
+ Assert.assertEquals("vv-y", configuration.getName());
+ }
+
+
+ @Test
+ public void testSystemPropKeyReplacement() throws Exception {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ Properties properties = new Properties();
+
+ final String newKeyName = RandomUtil.randomString();
+ final String valueFromSysProp = "VV";
+ System.setProperty(newKeyName, valueFromSysProp);
+
+ try {
+ properties.put("connectorConfigurations.KEY-${" + newKeyName +
"}.name", "y");
+ configuration.parsePrefixedProperties(properties, null);
+ Assert.assertNotNull("configured new key from prop",
configuration.connectorConfigs.get("KEY-" + valueFromSysProp));
+ Assert.assertEquals("y", configuration.connectorConfigs.get("KEY-" +
valueFromSysProp).getName());
+ } finally {
+ System.clearProperty(newKeyName);
+ }
+ }
+
+ @Test
+ public void testEnumConversion() throws Exception {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ Properties properties = new Properties();
+ properties.put("clusterConfiguration.cc.name", "cc");
+ properties.put("clusterConfigurations.cc.messageLoadBalancingType",
"OFF_WITH_REDISTRIBUTION");
+ properties.put("criticalAnalyzerPolicy", "SHUTDOWN");
+
+ configuration.parsePrefixedProperties(properties, null);
+
+ Assert.assertEquals("cc",
configuration.getClusterConfigurations().get(0).getName());
+ Assert.assertEquals(MessageLoadBalancingType.OFF_WITH_REDISTRIBUTION,
configuration.getClusterConfigurations().get(0).getMessageLoadBalancingType());
+ Assert.assertEquals(CriticalAnalyzerPolicy.SHUTDOWN,
configuration.getCriticalAnalyzerPolicy());
+ }
+
+ @Test
+ public void testPropertiesReaderRespectsOrderFromFile() throws Exception {
+
+ File tmpFile = File.createTempFile("ordered-props-test", "");
Review Comment:
I think there are rules that manage that but I did not check since there
were already temp files in play in that test. peeking more, I see there is some
base class cleanup, but I need to make use of that.
Good catch!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]