You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by de...@apache.org on 2015/09/17 11:08:30 UTC
activemq git commit: https://issues.apache.org/jira/browse/AMQ-5972 -
wildcard policy entries not applied in correct order
Repository: activemq
Updated Branches:
refs/heads/master 8a09b7e5f -> ee4672baa
https://issues.apache.org/jira/browse/AMQ-5972 - wildcard policy entries not applied in correct order
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/ee4672ba
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/ee4672ba
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/ee4672ba
Branch: refs/heads/master
Commit: ee4672baaf190782c197b886f13aea566ba3253f
Parents: 8a09b7e
Author: Dejan Bosanac <de...@nighttale.net>
Authored: Thu Sep 17 11:08:05 2015 +0200
Committer: Dejan Bosanac <de...@nighttale.net>
Committed: Thu Sep 17 11:08:21 2015 +0200
----------------------------------------------------------------------
.../broker/region/policy/PolicyEntry.java | 4 +
.../activemq/command/ActiveMQDestination.java | 21 ++-
.../apache/activemq/filter/DestinationMap.java | 2 +-
.../FilteredKahaDBPersistenceAdapter.java | 13 ++
.../broker/policy/DestinationWildcardTest.java | 184 +++++++++++++++++++
5 files changed, 220 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/ee4672ba/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
index 2e8c2a7..97d9155 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
@@ -1001,4 +1001,8 @@ public class PolicyEntry extends DestinationMapEntry {
this.maxDestinations = maxDestinations;
}
+ @Override
+ public String toString() {
+ return "PolicyEntry [" + destination + "]";
+ }
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/ee4672ba/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
index 09d54ab..4819a1a 100755
--- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
@@ -37,6 +37,8 @@ import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;
import javax.jms.Topic;
+import org.apache.activemq.filter.AnyDestination;
+import org.apache.activemq.filter.DestinationFilter;
import org.apache.activemq.jndi.JNDIBaseStorable;
import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.URISupport;
@@ -151,13 +153,26 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da
if (destination == destination2) {
return 0;
}
- if (destination == null) {
+ if (destination == null || destination2 instanceof AnyDestination) {
return -1;
- } else if (destination2 == null) {
+ } else if (destination2 == null || destination instanceof AnyDestination) {
return 1;
} else {
- if (destination.isQueue() == destination2.isQueue()) {
+ if (destination.getDestinationType() == destination2.getDestinationType()) {
+ if (destination.isPattern()) {
+ DestinationFilter filter = DestinationFilter.parseFilter(destination);
+ if (filter.matches(destination2)) {
+ return 1;
+ }
+ }
+ if (destination2.isPattern()) {
+ DestinationFilter filter = DestinationFilter.parseFilter(destination2);
+ if (filter.matches(destination)) {
+ return -1;
+ }
+ }
return destination.getPhysicalName().compareTo(destination2.getPhysicalName());
+
} else {
return destination.isQueue() ? -1 : 1;
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/ee4672ba/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
index c01f76d..fd07b7a 100755
--- a/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
+++ b/activemq-client/src/main/java/org/apache/activemq/filter/DestinationMap.java
@@ -207,7 +207,7 @@ public class DestinationMap {
return null;
}
SortedSet sortedSet = new TreeSet(set);
- return sortedSet.last();
+ return sortedSet.first();
}
/**
http://git-wip-us.apache.org/repos/asf/activemq/blob/ee4672ba/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/FilteredKahaDBPersistenceAdapter.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/FilteredKahaDBPersistenceAdapter.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/FilteredKahaDBPersistenceAdapter.java
index 10d0023..f994c67 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/FilteredKahaDBPersistenceAdapter.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/FilteredKahaDBPersistenceAdapter.java
@@ -52,4 +52,17 @@ public class FilteredKahaDBPersistenceAdapter extends DestinationMapEntry {
public void setPerDestination(boolean perDestination) {
this.perDestination = perDestination;
}
+
+ @Override
+ public String toString() {
+ return "FilteredKahaDBPersistenceAdapter [" + destination + "]";
+ }
+
+ @Override
+ public int compareTo(Object that) {
+ if (that instanceof FilteredKahaDBPersistenceAdapter) {
+ return this.destination.compareTo(((FilteredKahaDBPersistenceAdapter) that).destination);
+ }
+ return super.compareTo(that);
+ }
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/ee4672ba/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/DestinationWildcardTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/DestinationWildcardTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/DestinationWildcardTest.java
new file mode 100644
index 0000000..0f984ac
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/policy/DestinationWildcardTest.java
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.broker.policy;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.ConnectionContext;
+import org.apache.activemq.broker.jmx.ManagedRegionBroker;
+import org.apache.activemq.broker.region.Queue;
+import org.apache.activemq.broker.region.policy.PolicyEntry;
+import org.apache.activemq.broker.region.policy.PolicyMap;
+import org.apache.activemq.command.ActiveMQQueue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DestinationWildcardTest {
+ protected final static String DESTNAME="DomainA.DomainB.TestMeA.TestMeB.Prioritised.Queue";
+ protected final static int QUEUE_LIMIT = 5000000;
+ protected static Logger LOG = LoggerFactory.getLogger(DestinationWildcardTest.class);
+ private BrokerService broker = null;
+
+ @Before
+ public void setUp() throws Exception {
+ broker = new BrokerService();
+ broker.setPersistent(false);
+ broker.setDeleteAllMessagesOnStartup(true);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ LOG.info("Shutting down");
+ if (broker != null && broker.isStarted()) {
+ LOG.info("Broker still running, stopping it now.");
+ broker.stop();
+ }
+ else {
+ LOG.info("Broker not running, nothing to shutdown.");
+ }
+ }
+
+ /**
+ * Configures broker for two wildcard policies and one specific destination policy, creates a destination
+ * and checks if the right policy is applied to the destination.
+ */
+ @Test
+ public void testDestinationWildcardThreeEntries() throws Exception {
+ LOG.info("testDestinationWildcard() called.");
+
+ // configure broker for policyEntries
+ List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
+
+ PolicyEntry e1 = new PolicyEntry();
+ e1.setDestination(new ActiveMQQueue("DomainA.DomainB.TestMeA.TestMeB.Prioritised.Queue"));
+ e1.setMemoryLimit(QUEUE_LIMIT);
+ e1.setPrioritizedMessages(true);
+ entries.add(e1);
+
+ PolicyEntry e2 = new PolicyEntry();
+ e2.setDestination(new ActiveMQQueue("DomainA.DomainB.*.*.Prioritised.Queue"));
+ e2.setMemoryLimit(3000000);
+ e2.setPrioritizedMessages(false);
+ entries.add(e2);
+
+ PolicyEntry e3 = new PolicyEntry();
+ e3.setDestination(new ActiveMQQueue("DomainA.DomainB.>"));
+ e3.setMemoryLimit(3000000);
+ e3.setPrioritizedMessages(false);
+ entries.add(e3);
+
+ PolicyMap policyMap = new PolicyMap();
+ policyMap.setPolicyEntries(entries);
+ broker.setDestinationPolicy(policyMap);
+ broker.start();
+ broker.waitUntilStarted();
+
+ // verify broker isn't null
+ Assert.assertNotNull(broker);
+
+ // verify effective policy is in place.
+ ManagedRegionBroker rb = (ManagedRegionBroker) broker.getRegionBroker();
+ org.apache.activemq.broker.region.Queue queue = (Queue) rb.addDestination(new ConnectionContext(), new ActiveMQQueue(DESTNAME), true);
+ Assert.assertTrue("PolicyEntry should have priorityMessages enabled for destination " + DESTNAME, queue.isPrioritizedMessages());
+ long limit = queue.getMemoryUsage().getLimit();
+ LOG.info("MemoryLimit of {}: expected: 5242880, actual: {}", DESTNAME, limit);
+ Assert.assertEquals("Memory limit is expected to be " + QUEUE_LIMIT + " for this destination, but does not match.", QUEUE_LIMIT, limit);
+ }
+
+
+ /**
+ * Configures broker for two wildcard policies, creates a destination
+ * and checks if the policy is applied to the destination.
+ */
+ @Test
+ public void testDestinationWildcardTwoEntries() throws Exception {
+ LOG.info("testDestinationWildcard() called.");
+
+ // configure broker for policyEntries
+ List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
+
+ PolicyEntry e1 = new PolicyEntry();
+ e1.setDestination(new ActiveMQQueue("DomainA.DomainB.*.*.Prioritised.Queue"));
+ e1.setMemoryLimit(QUEUE_LIMIT);
+ e1.setPrioritizedMessages(true);
+ entries.add(e1);
+
+ PolicyEntry e2 = new PolicyEntry();
+ e2.setDestination(new ActiveMQQueue("DomainA.DomainB.>"));
+ e2.setMemoryLimit(3000000);
+ e2.setPrioritizedMessages(false);
+ entries.add(e2);
+
+ PolicyMap policyMap = new PolicyMap();
+ policyMap.setPolicyEntries(entries);
+ broker.setDestinationPolicy(policyMap);
+ broker.start();
+ broker.waitUntilStarted();
+
+ // verify broker isn't null
+ Assert.assertNotNull(broker);
+
+ // verify effective policy is in place.
+ ManagedRegionBroker rb = (ManagedRegionBroker) broker.getRegionBroker();
+ org.apache.activemq.broker.region.Queue queue = (Queue) rb.addDestination(new ConnectionContext(), new ActiveMQQueue(DESTNAME), true);
+ Assert.assertTrue("PolicyEntry should have priorityMessages enabled for destination " + DESTNAME, queue.isPrioritizedMessages());
+ long limit = queue.getMemoryUsage().getLimit();
+ LOG.info("MemoryLimit of {}: expected: 5242880, actual: {}", DESTNAME, limit);
+ Assert.assertEquals("Memory limit is expected to be " + QUEUE_LIMIT + " for this destination, but does not match.", QUEUE_LIMIT, limit);
+ }
+
+
+ @Test
+ public void testDestinationWildcardOneEntry() throws Exception {
+ LOG.info("testDestinationWildcard2() called.");
+ // verify broker isn't null
+ Assert.assertNotNull(broker);
+
+ // configure broker for policyEntries
+ List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
+
+ PolicyEntry e1 = new PolicyEntry();
+ e1.setDestination(new ActiveMQQueue("DomainA.DomainB.*.*.Prioritised.Queue"));
+ e1.setMemoryLimit(QUEUE_LIMIT);
+ e1.setPrioritizedMessages(true);
+ entries.add(e1);
+ PolicyMap policyMap = new PolicyMap();
+ policyMap.setPolicyEntries(entries);
+ broker.setDestinationPolicy(policyMap);
+ broker.start();
+ broker.waitUntilStarted();
+
+ // verify effective policy is in place.
+ ManagedRegionBroker rb = (ManagedRegionBroker) broker.getRegionBroker();
+ org.apache.activemq.broker.region.Queue queue = (Queue) rb.addDestination(new ConnectionContext(), new ActiveMQQueue(DESTNAME), true);
+ Assert.assertTrue("PolicyEntry should have priorityMessages enabled for destination " + DESTNAME, queue.isPrioritizedMessages());
+ long limit = queue.getMemoryUsage().getLimit();
+ LOG.info("MemoryLimit of {}: expected: 5000000, actual: {}", "DomainA", limit);
+ Assert.assertEquals("Memory limit is expected to be " + 5000000 + " for this destination, but does not match.", 5000000, limit);
+ }
+}
+