The chooseValue method in DestinationMap will now always return the
exact match, if there is one, else it will then sort as before.

(cherry picked from commit 8e2176d93c)
This commit is contained in:
Christopher L. Shannon (cshannon) 2015-12-28 16:40:10 +00:00
parent bf3c5e7873
commit 63f045e5c9
2 changed files with 60 additions and 2 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.filter;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -201,12 +202,18 @@ public class DestinationMap {
* @return the largest matching value or null if no value matches
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public Object chooseValue(ActiveMQDestination destination) {
public Object chooseValue(final ActiveMQDestination destination) {
Set set = get(destination);
if (set == null || set.isEmpty()) {
return null;
}
SortedSet sortedSet = new TreeSet(set);
SortedSet sortedSet = new TreeSet(new Comparator<DestinationMapEntry>() {
@Override
public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) {
return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2));
}
});
sortedSet.addAll(set);
return sortedSet.first();
}

View File

@ -406,6 +406,57 @@ public class JavaPolicyEntryTest extends RuntimeConfigTestSupport {
verifyQueueLimit("queue.test", 1024);
}
@Test
public void testModWithMultipleChildPolicies() throws Exception {
BrokerService brokerService = new BrokerService();
PolicyMap policyMap = new PolicyMap();
PolicyEntry entry = new PolicyEntry();
entry.setQueue("queue.>");
entry.setMemoryLimit(1024);
PolicyEntry entry2 = new PolicyEntry();
entry2.setQueue("queue.child.>");
entry2.setMemoryLimit(2048);
PolicyEntry entry3 = new PolicyEntry();
entry3.setQueue("queue.child.test");
entry3.setMemoryLimit(5000);
PolicyEntry entry4 = new PolicyEntry();
entry4.setQueue("queue.child.test.test");
entry4.setMemoryLimit(5100);
PolicyEntry entry5 = new PolicyEntry();
entry5.setQueue("queue.child.a");
entry5.setMemoryLimit(5200);
policyMap.setPolicyEntries(Arrays.asList(entry, entry2, entry3, entry4, entry5));
brokerService.setDestinationPolicy(policyMap);
startBroker(brokerService);
assertTrue("broker alive", brokerService.isStarted());
brokerService.getBroker().addDestination(
brokerService.getAdminConnectionContext(), new ActiveMQQueue("queue.child.>"), false);
brokerService.getBroker().addDestination(
brokerService.getAdminConnectionContext(), new ActiveMQQueue("queue.test"), false);
brokerService.getBroker().addDestination(
brokerService.getAdminConnectionContext(), new ActiveMQQueue("queue.child.test2"), false);
//check destinations before policy updates
verifyQueueLimit("queue.test", 1024);
verifyQueueLimit("queue.child.test2", 2048);
//Reapply new limit to policy 2
entry3.setMemoryLimit(4194304);
javaConfigBroker.modifyPolicyEntry(entry);
TimeUnit.SECONDS.sleep(SLEEP);
//should be unchanged
verifyQueueLimit("queue.child.>", 2048);
//verify new dest and existing are changed
verifyQueueLimit("queue.child.test", 4194304);
//verify that destination at a higher level policy is not affected
verifyQueueLimit("queue.test", 1024);
}
@Test
public void testModParentPolicy() throws Exception {
BrokerService brokerService = new BrokerService();