You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2022/04/04 16:20:51 UTC

[GitHub] [activemq-artemis] gtully opened a new pull request, #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

gtully opened a new pull request, #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011

   …ig, respect order of file loaded properties and add generic enum converter


-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
gtully commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842714815


##########
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:
   pushed a fix for the temp file usage in that test class



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] brusdev commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
brusdev commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842417477


##########
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();

Review Comment:
   Why is randomString required?



##########
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 {

Review Comment:
   This test could be skipped if the required `HOME` env var isn't set



##########
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", "");
+
+      FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+      PrintWriter printWriter = new PrintWriter(fileOutputStream);
+
+      LinkedList<String> insertionOrderedKeys = new LinkedList<>();
+      char ascii = 'a';
+      for (int i = 0; i < 26; i++, ascii++) {
+         printWriter.println("resourceLimitSettings." + i + ".maxConnections=100");
+         insertionOrderedKeys.addLast(String.valueOf(i));
+
+         printWriter.println("resourceLimitSettings." + ascii + ".maxConnections=100");
+         insertionOrderedKeys.addLast(String.valueOf(ascii));
+      }
+      printWriter.flush();
+      fileOutputStream.flush();
+      fileOutputStream.close();
+
+      final AtomicReference<String> errorAt = new AtomicReference<>();
+      ConfigurationImpl configuration = new ConfigurationImpl();
+      configuration.setResourceLimitSettings(new HashMap<String, ResourceLimitSettings>() {
+         @Override
+         public ResourceLimitSettings put(String key, ResourceLimitSettings value) {
+            if (!(key.equals(insertionOrderedKeys.remove()))) {
+               errorAt.set(key);
+               fail("Expected to see props applied in insertion order!, errorAt:" + errorAt.get());
+            }
+            return super.put(key, value);
+         }
+      });
+      configuration.parseProperties(tmpFile.getAbsolutePath());
+      assertNull("no errors in insertion order, errorAt:" + errorAt.get(), errorAt.get());
+   }
+
+
+   @Test
+   public void testPropertiesFiles() throws Exception {
+
+      LinkedList<String> files = new LinkedList<>();
+      LinkedList<String> names = new LinkedList<>();
+      names.addLast("one");
+      names.addLast("two");
+
+      for (String suffix : names) {
+         File tmpFile = File.createTempFile("props-test", suffix);

Review Comment:
   Is it possible remove the tmpFile after the test execution?



##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java:
##########
@@ -52,6 +52,12 @@ private XMLUtil() {
       // Utility class
    }
 
+   public static String CONSIDER_OS_ENV_PROP = "org.apache.activemq.artemis.utils.considerOsEnv";

Review Comment:
   An alternative name could be `REPLACE_OS_ENV_PROP`



##########
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:
   Is it possible remove the tmpFile after the test execution?



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] brusdev merged pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
brusdev merged PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011


-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
gtully commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842681161


##########
artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java:
##########
@@ -52,6 +52,12 @@ private XMLUtil() {
       // Utility class
    }
 
+   public static String CONSIDER_OS_ENV_PROP = "org.apache.activemq.artemis.utils.considerOsEnv";

Review Comment:
   it does not replace tho, it only considers if the system prop is absent



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
gtully commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842675550


##########
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();

Review Comment:
   just b/c I don't have full control of the system properties in play



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4011: ARTEMIS-3757 - allow system and env var substution of properties conf…

Posted by GitBox <gi...@apache.org>.
gtully commented on code in PR #4011:
URL: https://github.com/apache/activemq-artemis/pull/4011#discussion_r842674425


##########
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 {

Review Comment:
   true, but it also exercise the default value in that case.



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org