activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r487187 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/ActiveMQMessageConsumer.java test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
Date Thu, 14 Dec 2006 12:25:49 GMT
Author: aco
Date: Thu Dec 14 04:25:49 2006
New Revision: 487187

URL: http://svn.apache.org/viewvc?view=rev&rev=487187
Log:
https://issues.apache.org/activemq/browse/AMQ-1097
- Fix for selector configured using destination options is not set
- Test case to demonstrate issue

Added:
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
  (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java?view=diff&rev=487187&r1=487186&r2=487187
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
Thu Dec 14 04:25:49 2006
@@ -162,7 +162,6 @@
         }
 
         this.session = session;
-        this.selector = selector;
         this.redeliveryPolicy = session.connection.getRedeliveryPolicy();
         setTransformer(session.getTransformer());
 
@@ -174,6 +173,7 @@
         this.info.setNoLocal(noLocal);
         this.info.setDispatchAsync(dispatchAsync);
         this.info.setRetroactive(this.session.connection.isUseRetroactiveConsumer());
+        this.info.setSelector(null);
 
         // Allows the options on the destination to configure the consumerInfo
         if (dest.getOptions() != null) {
@@ -184,11 +184,16 @@
         this.info.setDestination(dest);
         this.info.setBrowser(browser);
         if (selector != null && selector.trim().length() != 0) {
-            // Validate that the selector
+            // Validate the selector
             new SelectorParser().parse(selector);
             this.info.setSelector(selector);
+            this.selector = selector;
+        } else if (info.getSelector() != null) {
+            // Validate the selector
+            new SelectorParser().parse(this.info.getSelector());
+            this.selector = this.info.getSelector();
         } else {
-            this.info.setSelector(null);
+            this.selector = null;
         }
 
         this.stats = new JMSConsumerStatsImpl(session.getSessionStats(), dest);

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java?view=auto&rev=487187
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
Thu Dec 14 04:25:49 2006
@@ -0,0 +1,72 @@
+/**
+ *
+ * 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.config;
+
+import junit.framework.TestCase;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQMessageConsumer;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.InvalidSelectorException;
+
+public class ConfigUsingDestinationOptions extends TestCase {
+    public void testValidSelectorConfig() throws JMSException {
+        ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test=1");
+
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
+        Connection conn = factory.createConnection();
+        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        ActiveMQMessageConsumer cons;
+        // JMS selector should be priority
+        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test=2");
+        assertEquals("test=2", cons.getMessageSelector());
+
+        // Test setting using JMS destinations
+        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
+        assertEquals("test=1", cons.getMessageSelector());
+    }
+
+    public void testInvalidSelectorConfig() throws JMSException {
+        ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test||1");
+
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
+        Connection conn = factory.createConnection();
+        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        ActiveMQMessageConsumer cons;
+        // JMS selector should be priority
+        try {
+            cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
+            fail("Selector should be invalid");
+        } catch (InvalidSelectorException e) {
+
+        }
+
+        // Test setting using JMS destinations
+        try {
+            cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
+            fail("Selector should be invalid");
+        } catch (InvalidSelectorException e) {
+
+        }
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/ConfigUsingDestinationOptions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message