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 2014/10/01 17:24:03 UTC

[2/4] git commit: add tests for sending messges with ttl override in effect

add tests for sending messges with ttl override in effect


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/d3b311fe
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/d3b311fe
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/d3b311fe

Branch: refs/heads/master
Commit: d3b311fe51ff4c05637a918ed31ee43a222aeeea
Parents: 92ad4eb
Author: Robert Gemmell <ro...@apache.org>
Authored: Wed Oct 1 15:48:19 2014 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Wed Oct 1 15:48:19 2014 +0100

----------------------------------------------------------------------
 .../jms/integration/SenderIntegrationTest.java  | 59 +++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d3b311fe/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SenderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SenderIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SenderIntegrationTest.java
index d43d6d0..d1fac47 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SenderIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SenderIntegrationTest.java
@@ -23,12 +23,12 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.Matchers.isA;
 import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Date;
 
 import javax.jms.Connection;
@@ -265,6 +265,63 @@ public class SenderIntegrationTest extends QpidJmsTestCase {
         }
     }
 
+    @Test(timeout = 10000)
+    public void testSendingMessageWithJMS_AMQP_TTLSetPositive() throws Exception {
+        sendingMessageWithJMS_AMQP_TTLSetTestImpl(100_000, 20_000);
+    }
+
+    @Test(timeout = 10000)
+    public void testSendingMessageWithJMS_AMQP_TTLSetZero() throws Exception {
+        sendingMessageWithJMS_AMQP_TTLSetTestImpl(50_000, 0);
+    }
+
+    public void sendingMessageWithJMS_AMQP_TTLSetTestImpl(long jmsTtl, long amqpTtl) throws Exception {
+        try (TestAmqpPeer testPeer = new TestAmqpPeer(IntegrationTestFixture.PORT);) {
+            Connection connection = testFixture.establishConnecton(testPeer);
+            testPeer.expectBegin(true);
+            testPeer.expectSenderAttach();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            String queueName = "myQueue";
+            Queue queue = session.createQueue(queueName);
+            MessageProducer producer = session.createProducer(queue);
+
+            long currentTime = System.currentTimeMillis();
+            Date expirationLower = new Date(currentTime + jmsTtl);
+            Date expirationUpper = new Date(currentTime + jmsTtl + 3000);
+
+            // Create matcher to expect the absolute-expiry-time field of the properties section to
+            // be set to a value greater than 'now'+ttl, within a delta.
+            Matcher<Date> inRange = both(greaterThanOrEqualTo(expirationLower)).and(lessThanOrEqualTo(expirationUpper));
+
+            String text = "myMessage";
+            MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true);
+            headersMatcher.withDurable(equalTo(true));
+            // verify the ttl field matches the JMS_AMQP_TTL value, rather than the standard JMS send TTL value.
+            if (amqpTtl == 0) {
+                headersMatcher.withTtl(nullValue());
+            } else {
+                headersMatcher.withTtl(equalTo(UnsignedInteger.valueOf(amqpTtl)));
+            }
+            MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
+            MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true)
+                    .withAbsoluteExpiryTime(inRange);
+            TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+            messageMatcher.setHeadersMatcher(headersMatcher);
+            messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
+            messageMatcher.setPropertiesMatcher(propsMatcher);
+            messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text));
+            testPeer.expectTransfer(messageMatcher);
+
+            Message message = session.createTextMessage(text);
+            message.setLongProperty(AmqpMessageSupport.JMS_AMQP_TTL, amqpTtl);
+
+            producer.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, jmsTtl);
+
+            testPeer.waitForAllHandlersToComplete(2000);
+        }
+    }
+
     /**
      * Test that when a message is sent with default priority of 4, the emitted AMQP message has no value in the header
      * priority field, since the default for that field is already 4.


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