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 14:40:46 UTC

[7/7] git commit: update tests to check field values are within a certain delta

update tests to check field values are within a certain delta


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

Branch: refs/heads/master
Commit: 1e6d380926fa0fe2dfe5d3e6235b3783476a7ff2
Parents: 772032f
Author: Robert Gemmell <ro...@apache.org>
Authored: Wed Oct 1 13:38:23 2014 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Wed Oct 1 13:38:23 2014 +0100

----------------------------------------------------------------------
 .../jms/integration/SenderIntegrationTest.java  | 26 ++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1e6d3809/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 8c66268..d43d6d0 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
@@ -18,11 +18,12 @@
  */
 package org.apache.qpid.jms.integration;
 
+import static org.hamcrest.Matchers.both;
 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.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -48,6 +49,7 @@ import org.apache.qpid.jms.test.testpeer.matchers.types.EncodedAmqpValueMatcher;
 import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.UnsignedByte;
 import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.hamcrest.Matcher;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -191,15 +193,19 @@ public class SenderIntegrationTest extends QpidJmsTestCase {
             Queue queue = session.createQueue(queueName);
             MessageProducer producer = session.createProducer(queue);
 
-            // Add matcher to expect the creation time field of the properties section to be set to a value greater than
-            // or equal to 'now'
-            Date currentTime = Calendar.getInstance().getTime();
+            // 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.
+            long currentTime = System.currentTimeMillis();
+            Date creationLower = new Date(currentTime);
+            Date creationUpper = new Date(currentTime + 3000);
+            Matcher<Date> inRange = both(greaterThanOrEqualTo(creationLower)).and(lessThanOrEqualTo(creationUpper));
+
             String text = "myMessage";
             MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true)
                     .withDurable(equalTo(true));
             MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
             MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true)
-                    .withCreationTime(greaterThanOrEqualTo(currentTime));
+                    .withCreationTime(inRange);
             TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
             messageMatcher.setHeadersMatcher(headersMatcher);
             messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
@@ -229,7 +235,13 @@ public class SenderIntegrationTest extends QpidJmsTestCase {
 
             long currentTime = System.currentTimeMillis();
             long ttl = 100_000;
-            Date expiration = new Date(currentTime + ttl);
+
+            Date expirationLower = new Date(currentTime + ttl);
+            Date expirationUpper = new Date(currentTime + ttl + 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);
@@ -237,7 +249,7 @@ public class SenderIntegrationTest extends QpidJmsTestCase {
             headersMatcher.withTtl(equalTo(UnsignedInteger.valueOf(ttl)));
             MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
             MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true)
-                    .withAbsoluteExpiryTime(greaterThanOrEqualTo(expiration));
+                    .withAbsoluteExpiryTime(inRange);
             TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
             messageMatcher.setHeadersMatcher(headersMatcher);
             messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);


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