Skip to content

Commit 3384d54

Browse files
gtullybrusdev
authored andcommitted
ARTEMIS-5682 broker properties, support clear of collection or map properties with the removeValue -
1 parent 5b1db58 commit 3384d54

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,19 @@ public void setProperty(final Object bean, String name, final Object value) thro
739739
throw new InvocationTargetException(e, "Can only remove named entries from collections or maps. property: " + name + ", on: " + target);
740740
}
741741
} else {
742-
throw new InvocationTargetException(null, "Can only remove entries from collections or maps. property: " + name + ", on: " + target);
742+
// empty the collection referenced by this property
743+
try {
744+
target = getPropertyUtils().getProperty(target, name);
745+
} catch (NoSuchMethodException e) {
746+
throw new InvocationTargetException(e, "Can only clear entries from collection or map properties that are accessible. property: " + name + ", on: " + target);
747+
}
748+
if (target instanceof Map mapToClear) {
749+
mapToClear.clear();
750+
} else if (target instanceof Collection collectionToClear) {
751+
collectionToClear.clear();
752+
} else {
753+
throw new InvocationTargetException(null, "Can only clear entries from collection or map properties. property: " + name + ", on: " + target);
754+
}
743755
}
744756

745757
logger.trace("removed from target, bean: {}, name: {}", target.getClass(), name);

artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,66 @@ public void testAddressRemovalViaProperties() throws Throwable {
15351535
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
15361536
}
15371537

1538+
@Test
1539+
public void testAllAddressRemovalViaProperties() throws Throwable {
1540+
ConfigurationImpl configuration = new ConfigurationImpl();
1541+
1542+
Properties properties = new Properties();
1543+
1544+
properties.put("addressConfigurations.\"LB.TEST\".queueConfigs.\"LB.TEST\".routingType", "ANYCAST");
1545+
configuration.parsePrefixedProperties(properties, null);
1546+
1547+
assertEquals(1, configuration.getAddressConfigurations().size());
1548+
assertEquals(1, configuration.getAddressConfigurations().get(0).getQueueConfigs().size());
1549+
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
1550+
1551+
properties.clear();
1552+
properties.put("addressConfigurations", "-");
1553+
configuration.parsePrefixedProperties(properties, null);
1554+
1555+
assertEquals(0, configuration.getAddressConfigurations().size());
1556+
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
1557+
}
1558+
1559+
@Test
1560+
public void testAllMapRemovalViaProperties() throws Throwable {
1561+
ConfigurationImpl configuration = new ConfigurationImpl();
1562+
1563+
Properties properties = new Properties();
1564+
properties.put("addressSettings.NeedToTrackExpired.expiryAddress", "important");
1565+
configuration.parsePrefixedProperties(properties, null);
1566+
1567+
assertEquals(1, configuration.getAddressSettings().size());
1568+
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
1569+
1570+
properties.clear();
1571+
properties.put("addressSettings", "-");
1572+
configuration.parsePrefixedProperties(properties, null);
1573+
1574+
assertEquals(0, configuration.getAddressSettings().size());
1575+
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
1576+
}
1577+
1578+
@Test
1579+
public void testRemovalInvalidViaProperties() throws Throwable {
1580+
ConfigurationImpl configuration = new ConfigurationImpl();
1581+
1582+
Properties properties = new Properties();
1583+
properties.put("HAPolicyConfiguration", "PRIMARY_ONLY");
1584+
configuration.parsePrefixedProperties(properties, null);
1585+
1586+
assertNotNull(configuration.getHAPolicyConfiguration());
1587+
assertTrue(configuration.getStatus().contains("\"errors\":[]"));
1588+
1589+
properties.clear();
1590+
properties.put("HAPolicyConfiguration", "-");
1591+
configuration.parsePrefixedProperties(properties, null);
1592+
assertNotNull(configuration.getHAPolicyConfiguration());
1593+
1594+
assertEquals(0, configuration.getAddressSettings().size());
1595+
assertTrue(configuration.getStatus().contains("InvocationTargetException"));
1596+
}
1597+
15381598
@Test
15391599
public void testRoleRemovalViaCustomRemoveProperties() throws Throwable {
15401600
ConfigurationImpl configuration = new ConfigurationImpl();

0 commit comments

Comments
 (0)