You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/05/24 23:38:04 UTC

svn commit: r1486225 - in /activemq/trunk: activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java

Author: tabish
Date: Fri May 24 21:38:04 2013
New Revision: 1486225

URL: http://svn.apache.org/r1486225
Log:
fix and test for: https://issues.apache.org/jira/browse/AMQ-4554

Added:
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java   (with props)
Modified:
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java?rev=1486225&r1=1486224&r2=1486225&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java (original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/filter/PropertyExpression.java Fri May 24 21:38:04 2013
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 
 import org.apache.activemq.command.ActiveMQDestination;
@@ -32,8 +31,6 @@ import org.apache.activemq.util.JMSExcep
 
 /**
  * Represents a property expression
- * 
- * 
  */
 public class PropertyExpression implements Expression {
 
@@ -46,6 +43,7 @@ public class PropertyExpression implemen
     static {
         JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 ActiveMQDestination dest = message.getOriginalDestination();
                 if (dest == null) {
@@ -59,6 +57,7 @@ public class PropertyExpression implemen
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 if (message.getReplyTo() == null) {
                     return null;
@@ -68,24 +67,28 @@ public class PropertyExpression implemen
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSType", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return message.getType();
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return message.isPersistent() ? "PERSISTENT" : "NON_PERSISTENT";
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Integer.valueOf(message.getPriority());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 if (message.getMessageId() == null) {
                     return null;
@@ -95,48 +98,56 @@ public class PropertyExpression implemen
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Long.valueOf(message.getTimestamp());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return message.getCorrelationId();
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Long.valueOf(message.getExpiration());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Boolean.valueOf(message.isRedelivered());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSXDeliveryCount", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Integer.valueOf(message.getRedeliveryCounter() + 1);
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupID", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return message.getGroupID();
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSXGroupSeq", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return new Integer(message.getGroupSequence());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSXProducerTXID", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 TransactionId txId = message.getOriginalTransactionId();
                 if (txId == null) {
@@ -145,23 +156,26 @@ public class PropertyExpression implemen
                 if (txId == null) {
                     return null;
                 }
-                return new Integer(txId.toString());
+                return txId.toString();
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerInTime", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Long.valueOf(message.getBrokerInTime());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerOutTime", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Long.valueOf(message.getBrokerOutTime());
             }
         });
         JMS_PROPERTY_EXPRESSIONS.put("JMSActiveMQBrokerPath", new SubExpression() {
 
+            @Override
             public Object evaluate(Message message) {
                 return Arrays.toString(message.getBrokerPath());
             }
@@ -176,6 +190,7 @@ public class PropertyExpression implemen
         jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
     }
 
+    @Override
     public Object evaluate(MessageEvaluationContext message) throws JMSException {
         try {
             if (message.isDropped()) {
@@ -214,6 +229,7 @@ public class PropertyExpression implemen
     /**
      * @see java.lang.Object#toString()
      */
+    @Override
     public String toString() {
         return name;
     }
@@ -221,6 +237,7 @@ public class PropertyExpression implemen
     /**
      * @see java.lang.Object#hashCode()
      */
+    @Override
     public int hashCode() {
         return name.hashCode();
     }
@@ -228,13 +245,12 @@ public class PropertyExpression implemen
     /**
      * @see java.lang.Object#equals(java.lang.Object)
      */
+    @Override
     public boolean equals(Object o) {
 
         if (o == null || !this.getClass().equals(o.getClass())) {
             return false;
         }
-        return name.equals(((PropertyExpression)o).name);
-
+        return name.equals(((PropertyExpression) o).name);
     }
-
 }

Added: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java?rev=1486225&view=auto
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java (added)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java Fri May 24 21:38:04 2013
@@ -0,0 +1,107 @@
+/**
+ * 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.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test for simple App.
+ */
+public class AMQ4554Test extends TestCase {
+
+    private final Logger LOG = LoggerFactory.getLogger(AMQ4554Test.class);
+
+    private String connectionURI;
+    private BrokerService broker;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        broker = new BrokerService();
+        connectionURI = broker.addConnector("tcp://0.0.0.0:0?maximumConnections=1").getPublishableConnectString();
+        broker.setPersistent(false);
+        broker.start();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        broker.stop();
+        super.tearDown();
+    }
+
+    /**
+     * Create the test case
+     *
+     * @param testName
+     *            name of the test case
+     */
+    public AMQ4554Test(String testName) {
+        super(testName);
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite() {
+        return new TestSuite(AMQ4554Test.class);
+    }
+
+    public void testMSXProducerTXID() throws Exception {
+
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
+        Connection connection = factory.createConnection();
+        connection.start();
+
+        Session producerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
+        MessageProducer producer = producerSession.createProducer(producerSession.createQueue("myQueue"));
+        TextMessage producerMessage = producerSession.createTextMessage("Test Message");
+        producer.send(producerMessage);
+        producer.close();
+        producerSession.commit();
+        producerSession.close();
+
+        Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
+        MessageConsumer consumer = consumerSession.createConsumer(consumerSession.createQueue("myQueue"));
+        Message consumerMessage = consumer.receive(1000);
+        try {
+            String txId = consumerMessage.getStringProperty("JMSXProducerTXID");
+            assertNotNull(txId);
+        } catch(Exception e) {
+            LOG.info("Caught Exception that was not expected:", e);
+            fail("Should not throw");
+        }
+        consumer.close();
+        consumerSession.commit();
+        consumerSession.close();
+        connection.close();
+    }
+
+}

Propchange: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4554Test.java
------------------------------------------------------------------------------
    svn:eol-style = native