activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1144736 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/Queue.java test/java/org/apache/activemq/bugs/AMQ2528Test.java
Date Sat, 09 Jul 2011 20:35:39 GMT
Author: tabish
Date: Sat Jul  9 20:35:38 2011
New Revision: 1144736

URL: http://svn.apache.org/viewvc?rev=1144736&view=rev
Log:
Fix and test for: https://issues.apache.org/jira/browse/AMQ-2528

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java 
 (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java?rev=1144736&r1=1144735&r2=1144736&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
Sat Jul  9 20:35:38 2011
@@ -1491,6 +1491,17 @@ public class Queue extends BaseDestinati
     }
 
     protected MessageReferenceFilter createSelectorFilter(String selector) throws InvalidSelectorException
{
+
+        if (selector == null || selector.isEmpty()) {
+            return new MessageReferenceFilter() {
+
+                @Override
+                public boolean evaluate(ConnectionContext context, MessageReference messageReference)
throws JMSException {
+                    return true;
+                }
+            };
+        }
+
         final BooleanExpression selectorExpression = SelectorParser.parse(selector);
 
         return new MessageReferenceFilter() {

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java?rev=1144736&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java Sat
Jul  9 20:35:38 2011
@@ -0,0 +1,81 @@
+/**
+ * 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.bugs;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.activemq.EmbeddedBrokerTestSupport;
+import org.apache.activemq.broker.region.Queue;
+import org.junit.Assert;
+
+/**
+ * This test demonstrates a bug in which calling
+ * Queue#removeMatchingMessages("") generates an exception, whereas the JMS
+ * specification states that an empty selector is valid.
+ */
+public class AMQ2528Test extends EmbeddedBrokerTestSupport {
+
+	/**
+	 * Setup the test so that the destination is a queue.
+	 */
+	protected void setUp() throws Exception {
+		useTopic = false;
+		super.setUp();
+	}
+
+	/**
+	 * This test enqueues test messages to destination and then verifies that
+	 * {@link Queue#removeMatchingMessages("")} removes all the messages.
+	 */
+	public void testRemoveMatchingMessages() throws Exception {
+		final int NUM_MESSAGES = 100;
+		final String MESSAGE_ID = "id";
+
+		// Enqueue the test messages.
+		Connection conn = createConnection();
+		try {
+			conn.start();
+			Session session = conn.createSession(false,
+					Session.AUTO_ACKNOWLEDGE);
+			MessageProducer producer = session.createProducer(destination);
+			for (int id = 0; id < NUM_MESSAGES; id++) {
+				Message message = session.createMessage();
+				message.setIntProperty(MESSAGE_ID, id);
+				producer.send(message);
+			}
+			producer.close();
+			session.close();
+		} finally {
+			conn.close();
+		}
+
+		// Verify that half of the messages can be removed by selector.
+		Queue queue = (Queue) broker.getRegionBroker().getDestinations(
+				destination).iterator().next();
+
+		Assert.assertEquals(NUM_MESSAGES / 2, queue
+				.removeMatchingMessages(MESSAGE_ID + " < " + NUM_MESSAGES / 2));
+
+		// Verify that the remainder of the messages can be removed by empty
+		// selector.
+		Assert.assertEquals(NUM_MESSAGES - NUM_MESSAGES / 2, queue
+				.removeMatchingMessages(""));
+	}
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2528Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message