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

This commit is contained in:
Clebert Suconic 2017-01-18 16:18:05 -05:00
parent 21cc672623
commit 7a7f335271
4 changed files with 68 additions and 27 deletions

View File

@ -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]);

View File

@ -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("${");

View File

@ -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

View File

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