ARTEMIS-3891 - allow TransformerConfig creation via properties

This commit is contained in:
Gary Tully 2022-07-12 16:20:05 +01:00 committed by clebertsuconic
parent 4a4765c39c
commit 1f2543029c
2 changed files with 56 additions and 13 deletions

View File

@ -55,6 +55,7 @@ import org.apache.activemq.artemis.api.core.Pair;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.config.TransformerConfiguration;
import org.apache.activemq.artemis.core.config.routing.ConnectionRouterConfiguration;
import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectConfiguration;
import org.apache.activemq.artemis.core.config.BridgeConfiguration;
@ -541,6 +542,14 @@ public class ConfigurationImpl implements Configuration, Serializable {
}
}, NamedPropertyConfiguration.class);
beanUtils.getConvertUtils().register(new Converter() {
@Override
public <T> T convert(Class<T> type, Object value) {
TransformerConfiguration instance = new TransformerConfiguration(value.toString());
return (T) instance;
}
}, TransformerConfiguration.class);
// support 25K or 25m etc like xml config
beanUtils.getConvertUtils().register(new Converter() {
@Override

View File

@ -617,19 +617,7 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
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();
}
};
Properties insertionOrderedProperties = new InsertionOrderedProperties();
insertionOrderedProperties.put("connectionRouters.autoShard.localTargetFilter", "NULL|$STATEFUL_SET_ORDINAL");
insertionOrderedProperties.put("connectionRouters.autoShard.keyType", KeyType.CLIENT_ID);
insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration", ConsistentHashModuloPolicy.NAME);
@ -764,6 +752,37 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
Assert.assertEquals(SimpleString.toSimpleString("moreImportant"), configuration.getAddressSettings().get("Name.With.Dots").getExpiryAddress());
}
@Test
public void testDivertViaProperties() throws Exception {
ConfigurationImpl configuration = new ConfigurationImpl();
final String routingName = "divert1";
final String address = "testAddress";
final String forwardAddress = "forwardAddress";
final String className = "s.o.m.e.class";
Properties properties = new InsertionOrderedProperties();
properties.put("divertConfigurations.divert1.routingName", routingName);
properties.put("divertConfigurations.divert1.address", address);
properties.put("divertConfigurations.divert1.forwardingAddress", forwardAddress);
properties.put("divertConfigurations.divert1.transformerConfiguration", className);
properties.put("divertConfigurations.divert1.transformerConfiguration.properties.a", "va");
properties.put("divertConfigurations.divert1.transformerConfiguration.properties.b", "vb");
configuration.parsePrefixedProperties(properties, null);
Assert.assertEquals(1, configuration.getDivertConfigurations().size());
Assert.assertEquals(routingName, configuration.getDivertConfigurations().get(0).getRoutingName());
Assert.assertEquals(address, configuration.getDivertConfigurations().get(0).getAddress());
Assert.assertEquals(forwardAddress, configuration.getDivertConfigurations().get(0).getForwardingAddress());
Assert.assertEquals(className, configuration.getDivertConfigurations().get(0).getTransformerConfiguration().getClassName());
Assert.assertEquals("va", configuration.getDivertConfigurations().get(0).getTransformerConfiguration().getProperties().get("a"));
Assert.assertEquals("vb", configuration.getDivertConfigurations().get(0).getTransformerConfiguration().getProperties().get("b"));
}
@Test
public void testRoleSettingsViaProperties() throws Exception {
ConfigurationImpl configuration = new ConfigurationImpl();
@ -1078,4 +1097,19 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
protected Configuration createConfiguration() throws Exception {
return new ConfigurationImpl();
}
private static class InsertionOrderedProperties extends 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();
}
}
}