You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2019/06/06 16:30:21 UTC

[qpid-jms] branch master updated: QPIDJMS-460: expand accepted types for x-opt-delivery-time message annotation on recieved messages

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-jms.git


The following commit(s) were added to refs/heads/master by this push:
     new 94a236b  QPIDJMS-460: expand accepted types for x-opt-delivery-time message annotation on recieved messages
94a236b is described below

commit 94a236b51d59530f49563ee129100b2aac4532bd
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Thu Jun 6 17:25:23 2019 +0100

    QPIDJMS-460: expand accepted types for x-opt-delivery-time message annotation on recieved messages
---
 .../amqp/message/AmqpJmsMessageFacade.java         |  9 ++++--
 .../jms/integration/MessageIntegrationTest.java    | 37 ++++++++++++++++++----
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
index c26fb00..2ef7d40 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.jms.JMSException;
+import javax.jms.JMSRuntimeException;
 import javax.jms.MessageFormatException;
 
 import org.apache.qpid.jms.JmsDestination;
@@ -549,8 +550,12 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
     @Override
     public long getDeliveryTime() {
         Object deliveryTime = getMessageAnnotation(JMS_DELIVERY_TIME);
-        if (deliveryTime != null) {
-            return (long) deliveryTime;
+        if (deliveryTime instanceof Number) {
+            return ((Number) deliveryTime).longValue();
+        } else if (deliveryTime instanceof Date) {
+            return ((Date) deliveryTime).getTime();
+        } else if (deliveryTime != null) {
+            throw new JMSRuntimeException("Unexpected delivery time annotation type: " + deliveryTime.getClass());
         }
 
         return syntheticDeliveryTime;
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
index 58b21e1..a9d7190 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
@@ -2273,15 +2273,28 @@ public class MessageIntegrationTest extends QpidJmsTestCase
 
     @Test(timeout = 20000)
     public void testReceivedMessageWithDeliveryTimeAnnotation() throws Exception {
-        doReceivedMessageDeliveryTimeTestImpl(true);
+        long deliveryTime = System.currentTimeMillis() + 13526;
+        doReceivedMessageDeliveryTimeTestImpl(true, deliveryTime);
+    }
+
+    @Test(timeout = 20000)
+    public void testReceivedMessageWithDeliveryTimeAnnotationTimestampValue() throws Exception {
+        Date deliveryTime = new Date(System.currentTimeMillis() + 13526);
+        doReceivedMessageDeliveryTimeTestImpl(true, deliveryTime);
+    }
+
+    @Test(timeout = 20000)
+    public void testReceivedMessageWithDeliveryTimeAnnotationUnsignedLongValue() throws Exception {
+        UnsignedLong deliveryTime = new UnsignedLong(System.currentTimeMillis() + 13526);
+        doReceivedMessageDeliveryTimeTestImpl(true, deliveryTime);
     }
 
     @Test(timeout = 20000)
     public void testReceivedMessageWithoutDeliveryTimeAnnotation() throws Exception {
-        doReceivedMessageDeliveryTimeTestImpl(false);
+        doReceivedMessageDeliveryTimeTestImpl(false, null);
     }
 
-    private void doReceivedMessageDeliveryTimeTestImpl(boolean setDeliveryTimeAnnotation) throws JMSException, InterruptedException, Exception, IOException {
+    private void doReceivedMessageDeliveryTimeTestImpl(boolean setDeliveryTimeAnnotation, Object annotationValue) throws Exception {
         try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
             Connection connection = testFixture.establishConnecton(testPeer);
             connection.start();
@@ -2292,12 +2305,25 @@ public class MessageIntegrationTest extends QpidJmsTestCase
             Queue queue = session.createQueue("myQueue");
 
             final long creationTime = System.currentTimeMillis();
-            final long deliveryTime = creationTime + 13526;
+            final long expectedDeliveryTime;
+            if (setDeliveryTimeAnnotation) {
+                if (annotationValue instanceof Long) {
+                    expectedDeliveryTime = (Long) annotationValue;
+                } else if (annotationValue instanceof Date) {
+                    expectedDeliveryTime = ((Date) annotationValue).getTime();
+                } else if (annotationValue instanceof UnsignedLong) {
+                    expectedDeliveryTime = ((UnsignedLong) annotationValue).longValue();
+                } else {
+                    throw new IllegalArgumentException("Unexpected annotation value");
+                }
+            } else {
+                expectedDeliveryTime = creationTime;
+            }
 
             MessageAnnotationsDescribedType msgAnnotations = null;
             if (setDeliveryTimeAnnotation) {
                 msgAnnotations = new MessageAnnotationsDescribedType();
-                msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_DELIVERY_TIME.toString(), deliveryTime);
+                msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_DELIVERY_TIME.toString(), annotationValue);
             }
 
             PropertiesDescribedType props = new PropertiesDescribedType();
@@ -2320,7 +2346,6 @@ public class MessageIntegrationTest extends QpidJmsTestCase
 
             assertNotNull("should have recieved a message", receivedMessage);
 
-            long expectedDeliveryTime = setDeliveryTimeAnnotation ? deliveryTime : creationTime;
             assertEquals("Unexpected delivery time", expectedDeliveryTime, receivedMessage.getJMSDeliveryTime());
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org