From cdcbfb2ae0be38078f52e806e842315408bc48d9 Mon Sep 17 00:00:00 2001 From: gtully Date: Wed, 16 Feb 2022 17:56:57 +0000 Subject: [PATCH] ARTEMIS-3627 - support 25k type postfix, same feature as xml config, for long values --- .../artemis/core/config/impl/ConfigurationImpl.java | 9 +++++++++ .../core/config/impl/ConfigurationImplTest.java | 13 +++++++++++++ 2 files changed, 22 insertions(+) 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 ff7d511967..7bac741389 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 @@ -96,6 +96,7 @@ import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerResourcePlug import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerSessionPlugin; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings; +import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.Env; import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy; @@ -507,6 +508,14 @@ public class ConfigurationImpl implements Configuration, Serializable { return (T) SimpleString.toSimpleString(value.toString()); } }, SimpleString.class); + // support 25K or 25m etc like xml config + beanUtils.getConvertUtils().register(new Converter() { + @Override + public T convert(Class type, Object value) { + return (T) (Long) ByteUtil.convertTextBytes(value.toString()); + } + }, Long.TYPE); + BeanSupport.customise(beanUtils); beanUtils.populate(this, beanProperties); 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 317d6dd338..fae353134c 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 @@ -689,6 +689,19 @@ public class ConfigurationImplTest extends ActiveMQTestBase { Assert.assertEquals(SimpleString.toSimpleString("moreImportant"), configuration.getAddressesSettings().get("Name.With.Dots").getExpiryAddress()); } + @Test + public void testValuePostFixModifier() throws Throwable { + ConfigurationImpl configuration = new ConfigurationImpl(); + + Properties properties = new Properties(); + + properties.put("globalMaxSize", "25K"); + + configuration.parsePrefixedProperties(properties, null); + + Assert.assertEquals(25 * 1024, configuration.getGlobalMaxSize()); + } + @Test public void testNameWithDotsSurroundWithDollarDollar() throws Throwable { ConfigurationImpl configuration = new ConfigurationImpl();