You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/01/18 21:20:53 UTC

activemq-artemis git commit: ARTEMIS-962 Adding test for CME when parsing system properties and a few tweaks

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 21cc67262 -> 7a7f33527


ARTEMIS-962 Adding test for CME when parsing system properties and a few tweaks


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7a7f3352
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7a7f3352
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7a7f3352

Branch: refs/heads/master
Commit: 7a7f335271b7b766d940cc38b94c7e89d96d1a4d
Parents: 21cc672
Author: Clebert Suconic <cl...@apache.org>
Authored: Wed Jan 18 16:18:05 2017 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Jan 18 16:18:05 2017 -0500

----------------------------------------------------------------------
 .../utils/DefaultSensitiveStringCodec.java      |  6 ++-
 .../apache/activemq/artemis/utils/XMLUtil.java  | 17 ------
 .../core/config/impl/ConfigurationImpl.java     | 14 ++---
 .../core/config/impl/ConfigurationImplTest.java | 56 ++++++++++++++++++++
 4 files changed, 67 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a7f3352/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
index 1861d0e..d1e3682 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
@@ -88,8 +88,10 @@ public class DefaultSensitiveStringCodec implements SensitiveDataCodec<String> {
       DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
       Map<String, String> params = new HashMap<>();
       Properties properties = System.getProperties();
-      for (final String name: properties.stringPropertyNames()) {
-         params.put(name, properties.getProperty(name));
+      synchronized (properties) {
+         for (final String name : properties.stringPropertyNames()) {
+            params.put(name, properties.getProperty(name));
+         }
       }
       codec.init(params);
       Object encode = codec.encode(args[0]);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a7f3352/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
index 39b0657..ac57a15 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
@@ -256,23 +256,6 @@ public final class XMLUtil {
       }
       return s;
    }
-
-   /* public static String replaceSystemProps(String xml)
-    {
-       Properties properties = System.getProperties();
-       Enumeration e = properties.propertyNames();
-       while (e.hasMoreElements())
-       {
-          String key = (String)e.nextElement();
-          String s = "${" + key + "}";
-          if (xml.contains(s))
-          {
-             xml = xml.replace(s, properties.getProperty(key));
-          }
-
-       }
-       return xml;
-    }*/
    public static String replaceSystemProps(String xml) {
       while (xml.contains("${")) {
          int start = xml.indexOf("${");

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a7f3352/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index bfa6c40..f4eda91 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -308,9 +308,9 @@ public class ConfigurationImpl implements Configuration, Serializable {
 
    @Override
    public Configuration parseSystemProperties(Properties properties) throws Exception {
-      synchronized (properties) {
-         Map<String, Object> beanProperties = new HashMap<>();
+      Map<String, Object> beanProperties = new HashMap<>();
 
+      synchronized (properties) {
          for (Map.Entry<Object, Object> entry : properties.entrySet()) {
             if (entry.getKey().toString().startsWith(systemPropertyPrefix)) {
                String key = entry.getKey().toString().substring(systemPropertyPrefix.length());
@@ -318,13 +318,13 @@ public class ConfigurationImpl implements Configuration, Serializable {
                beanProperties.put(key, entry.getValue());
             }
          }
+      }
 
-         if (!beanProperties.isEmpty()) {
-            BeanSupport.setData(this, beanProperties);
-         }
-
-         return this;
+      if (!beanProperties.isEmpty()) {
+         BeanSupport.setData(this, beanProperties);
       }
+
+      return this;
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7a7f3352/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
index de3fe66..f374979 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
@@ -18,6 +18,8 @@ package org.apache.activemq.artemis.core.config.impl;
 
 import java.io.File;
 import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.activemq.artemis.ArtemisConstants;
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
@@ -554,6 +556,60 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
       Assert.assertEquals(4321, configuration.getGlobalMaxSize());
    }
 
+   /**
+    * To test ARTEMIS-926
+    * @throws Throwable
+    */
+   @Test
+   public void testSetSystemPropertyCME() throws Throwable {
+      Properties properties = new Properties();
+
+      for (int i = 0; i < 5000; i++) {
+         properties.put("key" + i, "value " + i);
+      }
+
+
+      final ConfigurationImpl configuration = new ConfigurationImpl();
+
+      final AtomicBoolean running = new AtomicBoolean(true);
+      final CountDownLatch latch = new CountDownLatch(1);
+
+
+      Thread thread = new Thread() {
+         @Override
+         public void run() {
+            latch.countDown();
+            int i = 1;
+            while (running.get()) {
+               properties.remove("key" + i);
+               properties.put("key" + i, "new value " + i);
+               i++;
+               if (i > 200) {
+                  i = 1;
+               }
+            }
+         }
+      };
+
+      thread.start();
+      try {
+
+         latch.await();
+         properties.put(configuration.getSystemPropertyPrefix() + "fileDeployerScanPeriod", "1234");
+         properties.put(configuration.getSystemPropertyPrefix() + "globalMaxSize", "4321");
+
+         configuration.parseSystemProperties(properties);
+
+
+      } finally {
+         running.set(false);
+         thread.join();
+      }
+
+      Assert.assertEquals(1234, configuration.getFileDeployerScanPeriod());
+      Assert.assertEquals(4321, configuration.getGlobalMaxSize());
+   }
+
    @Override
    @Before
    public void setUp() throws Exception {