summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2013-04-17 09:35:45 +0000
committerKeith Wall <kwall@apache.org>2013-04-17 09:35:45 +0000
commita082e56d66d8c222709605dea00b397a72bd9117 (patch)
tree0e8109f5babdc918ba364855894b7e80ea3169b1
parentb3b8fa1c981c712dc218f80f3d0d34692fe7d653 (diff)
downloadqpid-python-a082e56d66d8c222709605dea00b397a72bd9117.tar.gz
QPID-4731: Implemented JMSSelectorFilter equals() and hashcode() to avoid leaking topic queues. Previously TopicExchangeResult._filteredQueues look-ups in TopicExchangeResult.removeFilteredQueue were erroneously failing, causing the queues therein to evade deletion during topic consumer close.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1468815 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java39
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/filter/JMSSelectorFilterTest.java56
2 files changed, 91 insertions, 4 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java
index 47cacdc176..3d0d9a0f31 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/JMSSelectorFilter.java
@@ -14,14 +14,17 @@
* "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.
+ * under the License.
+ *
*
- *
*/
package org.apache.qpid.server.filter;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.log4j.Logger;
-
import org.apache.qpid.filter.BooleanExpression;
import org.apache.qpid.filter.FilterableMessage;
import org.apache.qpid.filter.SelectorParsingException;
@@ -119,6 +122,34 @@ public class JMSSelectorFilter implements MessageFilter
@Override
public String toString()
{
- return "JMSSelector("+_selector+")";
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("selector", _selector)
+ .toString();
}
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(_selector).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ JMSSelectorFilter rhs = (JMSSelectorFilter) obj;
+ return new EqualsBuilder().append(_selector, rhs._selector).isEquals();
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/filter/JMSSelectorFilterTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/filter/JMSSelectorFilterTest.java
new file mode 100644
index 0000000000..91002edfc6
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/filter/JMSSelectorFilterTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.qpid.server.filter;
+
+import junit.framework.TestCase;
+
+public class JMSSelectorFilterTest extends TestCase
+{
+ public void testEqualsAndHashCodeUsingSelectorString() throws Exception
+ {
+ final String selectorString = "1 = 1";
+
+ JMSSelectorFilter filter1 = new JMSSelectorFilter(new String(selectorString));
+ JMSSelectorFilter filter2 = new JMSSelectorFilter(new String(selectorString));
+
+ assertEquals(filter1 + " should equal itself", filter1, filter1);
+ assertFalse(filter1 + " should not equal null", filter1.equals(null));
+ assertEqualsAndHashcodeMatch(filter1, filter2);
+
+ JMSSelectorFilter differentFilter = new JMSSelectorFilter("2 = 2");
+ assertNotEqual(filter1, differentFilter);
+ }
+
+ private void assertEqualsAndHashcodeMatch(JMSSelectorFilter filter1, JMSSelectorFilter filter2)
+ {
+ String message = filter1 + " and " + filter2 + " should be equal";
+
+ assertEquals(message, filter1, filter2);
+ assertEquals(message, filter2, filter1);
+
+ assertEquals("Hashcodes of " + filter1 + " and " + filter2 + " should be equal",
+ filter1.hashCode(), filter2.hashCode());
+ }
+
+ private void assertNotEqual(JMSSelectorFilter filter, JMSSelectorFilter differentFilter)
+ {
+ assertFalse(filter.equals(differentFilter));
+ assertFalse(differentFilter.equals(filter));
+ }
+}