Skip to content
Permalink
Browse files
ARTEMIS-3786 - ensure named properties config from routerConfiguratio…
…n can be created from string property value
  • Loading branch information
gtully authored and clebertsuconic committed Apr 20, 2022
1 parent 32c5f9d commit f9f70aeb4cf688c68d1076c657013e61f5cdbeae
Showing 2 changed files with 45 additions and 0 deletions.
@@ -72,6 +72,7 @@
import org.apache.activemq.artemis.core.config.WildcardConfiguration;
import org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration;
import org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration;
import org.apache.activemq.artemis.core.config.routing.NamedPropertyConfiguration;
import org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration;
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
@@ -527,6 +528,17 @@ public <T> T convert(Class<T> type, Object value) {
return (T) SimpleString.toSimpleString(value.toString());
}
}, SimpleString.class);

beanUtils.getConvertUtils().register(new Converter() {
@Override
public <T> T convert(Class<T> type, Object value) {
NamedPropertyConfiguration instance = new NamedPropertyConfiguration();
instance.setName(value.toString());
instance.setProperties(new HashMap<>());
return (T) instance;
}
}, NamedPropertyConfiguration.class);

// support 25K or 25m etc like xml config
beanUtils.getConvertUtils().register(new Converter() {
@Override
@@ -20,8 +20,11 @@
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@@ -40,6 +43,7 @@
import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
import org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin;
import org.apache.activemq.artemis.core.server.routing.KeyType;
import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashModuloPolicy;
import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.RandomUtil;
@@ -604,6 +608,35 @@ public void testSetSystemProperty() throws Throwable {
Assert.assertEquals(4321, configuration.getGlobalMaxSize());
}

@Test
public void testSetConnectionRoutersPolicyConfiguration() throws Throwable {
ConfigurationImpl configuration = new ConfigurationImpl();

Properties insertionOrderedProperties = new Properties() {
final LinkedHashMap<Object, Object> orderedMap = new LinkedHashMap<>();

@Override
public Object put(Object key, Object value) {
return orderedMap.put(key.toString(), value.toString());
}

@Override
public Set<Map.Entry<Object, Object>> entrySet() {
return orderedMap.entrySet();
}
};
insertionOrderedProperties.put("connectionRouters.autoShard.localTargetFilter", "NULL|$STATEFUL_SET_ORDINAL");
insertionOrderedProperties.put("connectionRouters.autoShard.keyType", KeyType.CLIENT_ID);
insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration", ConsistentHashModuloPolicy.NAME);
insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration.properties." + ConsistentHashModuloPolicy.MODULO, 2);

configuration.parsePrefixedProperties(insertionOrderedProperties, null);

Assert.assertEquals(1, configuration.getConnectionRouters().size());
Assert.assertEquals(KeyType.CLIENT_ID, configuration.getConnectionRouters().get(0).getKeyType());
Assert.assertEquals("2", configuration.getConnectionRouters().get(0).getPolicyConfiguration().getProperties().get(ConsistentHashModuloPolicy.MODULO));
}

@Test
public void testSetNestedPropertyOnCollections() throws Throwable {
ConfigurationImpl configuration = new ConfigurationImpl();

0 comments on commit f9f70ae

Please sign in to comment.