- Fix for selector configured using destination options is not set
- Test case to demonstrate issue

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@487187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian T. Co 2006-12-14 12:25:49 +00:00
parent e413e8711b
commit 87d15d6b98
2 changed files with 80 additions and 3 deletions

View File

@ -162,7 +162,6 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
}
this.session = session;
this.selector = selector;
this.redeliveryPolicy = session.connection.getRedeliveryPolicy();
setTransformer(session.getTransformer());
@ -174,6 +173,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
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 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
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);

View File

@ -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) {
}
}
}