activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AMQ-5281) Incorrect handling of unknown values in selectors
Date Sun, 17 Aug 2014 17:26:18 GMT

    [ https://issues.apache.org/jira/browse/AMQ-5281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14099992#comment-14099992
] 

ASF GitHub Bot commented on AMQ-5281:
-------------------------------------

GitHub user traylz opened a pull request:

    https://github.com/apache/activemq/pull/44

    AMQ-5281: Incorrect handling of unknown values in selectors

    See https://issues.apache.org/jira/browse/AMQ-5281 for details.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/traylz/activemq trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/activemq/pull/44.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #44
    
----
commit b018d89875a4cc8e92b355aeb087ba112872c1e2
Author: Grigory <gstraylz@gmail.com>
Date:   2014-08-17T17:17:48Z

    AMQ-5281: Incorrect handling of unknown values in selectors (=, <>, or, and)

----


> Incorrect handling of unknown values in selectors
> -------------------------------------------------
>
>                 Key: AMQ-5281
>                 URL: https://issues.apache.org/jira/browse/AMQ-5281
>             Project: ActiveMQ
>          Issue Type: Bug
>    Affects Versions: 5.8.0, 5.x
>            Reporter: Grigroy Sobko
>
> Due to JmsMessage specification :
> http://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html
> There are rules how unknown Values evaluates. 
> There how AND operator should handle unknown:
> - UNKNOWN AND FALSE => FALSE 
> - FALSE AND UNKNOWN => FALSE 
> And that's how it is handled in ActiveMQ:
> - UNKNOWN AND FALSE => UNKNOWN (!!!)
> - FALSE AND UNKNOWN => FALSE 
> I've wrote test to reproduce this:
> {code}
> package org.activemq.test;
> import org.apache.activemq.command.ActiveMQMessage;
> import org.apache.activemq.command.ActiveMQTopic;
> import org.apache.activemq.filter.BooleanExpression;
> import org.apache.activemq.filter.MessageEvaluationContext;
> import org.apache.activemq.selector.SelectorParser;
> import org.junit.Before;
> import org.junit.Test;
> import javax.jms.JMSException;
> import javax.jms.Message;
> import static org.junit.Assert.assertEquals;
> import static org.junit.Assert.assertTrue;
> public class SelectorUnknownHandlingTest {
>     private Message message;
>     @Before
>     public void setUp() throws Exception {
>         message = createMessage();
>     }
>     @Test
>     public void testUnknown() throws Exception {
>         // Some unset property with gt operator => unknown
>         assertSelectorEvaluatesToUnknown(message, "(unknownProp > 0)");
>     }
>     @Test
>     public void testUnknownAndFalse() throws Exception {
>         // false and unknown => false
>         assertSelectorEvaluatesToFalse(message, "(falseProp AND unknownProp > 0)");
>         // THIS ASSERTION FAILS !! IT EVALUATES TO UNKNOWN INSTEAD
>         // unknown and false => false
>         assertSelectorEvaluatesToFalse(message, "(unknownProp > 0 AND falseProp)");
>     }
>     @Test
>     public void testUnknownOrTrue() throws Exception {
>         // unknown or true => true
>         assertSelectorEvaluatesToTrue(message, "(unknownProp > 0 OR trueProp)");
>         // true or unknown => true
>         assertSelectorEvaluatesToTrue(message, "(trueProp OR unknownProp > 0)");
>     }
>     private void assertSelectorEvaluatesToUnknown(Message message, String selector) throws
JMSException {
>         assertSelector(message, selector, false);
>         assertSelector(message, "not(" + selector + ")", false);
>     }
>     private void assertSelectorEvaluatesToFalse(Message message, String selector) throws
JMSException {
>         assertSelector(message, selector, false);
>         assertSelector(message, "not(" + selector + ")", true);
>     }
>     private void assertSelectorEvaluatesToTrue(Message message, String selector) throws
JMSException {
>         assertSelector(message, selector, true);
>         assertSelector(message, "not(" + selector + ")", false);
>     }
>     protected Message createMessage() throws JMSException {
>         Message message = createMessage("FOO.BAR");
>         message.setJMSType("selector-test");
>         message.setJMSMessageID("connection:1:1:1:1");
>         message.setBooleanProperty("trueProp", true);
>         message.setBooleanProperty("falseProp", false);
>         return message;
>     }
>     protected void assertSelector(Message message, String text, boolean expected) throws
JMSException {
>         BooleanExpression selector = SelectorParser.parse(text);
>         assertTrue("Created a valid selector", selector != null);
>         MessageEvaluationContext context = new MessageEvaluationContext();
>         context.setMessageReference((org.apache.activemq.command.Message)message);
>         boolean value = selector.matches(context);
>         assertEquals("Selector for: " + text, expected, value);
>     }
>     protected Message createMessage(String subject) throws JMSException {
>         ActiveMQMessage message = new ActiveMQMessage();
>         message.setJMSDestination(new ActiveMQTopic(subject));
>         return message;
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message