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 2015/10/08 12:52:54 UTC

qpid-jms git commit: QPIDJMS-105: add some extra tests around message id handling when producers have the disableMessageID hint set

Repository: qpid-jms
Updated Branches:
  refs/heads/master 9fe2d7410 -> 26a87e762


QPIDJMS-105: add some extra tests around message id handling when producers have the disableMessageID hint set


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

Branch: refs/heads/master
Commit: 26a87e762e08e8312675aa3f3e0ce9eab3f53429
Parents: 9fe2d74
Author: Robert Gemmell <ro...@apache.org>
Authored: Thu Oct 8 11:52:19 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Thu Oct 8 11:52:19 2015 +0100

----------------------------------------------------------------------
 .../ForeignMessageIntegrationTest.java          | 52 ++++++++++++++++++++
 .../integration/ProducerIntegrationTest.java    | 27 ++++++++--
 2 files changed, 76 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/26a87e76/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ForeignMessageIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ForeignMessageIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ForeignMessageIntegrationTest.java
index fcb7d89..b84c722 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ForeignMessageIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ForeignMessageIntegrationTest.java
@@ -19,6 +19,9 @@
 package org.apache.qpid.jms.integration;
 
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 import javax.jms.Connection;
 import javax.jms.MessageProducer;
@@ -74,4 +77,53 @@ public class ForeignMessageIntegrationTest extends QpidJmsTestCase {
             producer.send(foreign);
         }
     }
+
+    /**
+     * Test that after sending a message with the disableMessageID hint set, which already had
+     * a JMSMessageID value, that the message object then has a null JMSMessageID value, and no
+     * message-id field value was set.
+     */
+    @Test(timeout = 20000)
+    public void testSendForeignMessageWithDisableMessageIDHintAndExistingMessageID() throws Exception {
+        try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+            Connection connection = testFixture.establishConnecton(testPeer);
+            testPeer.expectBegin();
+            testPeer.expectSenderAttach();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue("myQueue");
+            MessageProducer producer = session.createProducer(queue);
+
+            byte[] content = "myBytes".getBytes();
+
+            MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
+            MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
+            MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
+            propertiesMatcher.withMessageId(nullValue()); // Check there is no message-id value;
+            TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+            messageMatcher.setHeadersMatcher(headersMatcher);
+            messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
+            messageMatcher.setPropertiesMatcher(propertiesMatcher);
+            messageMatcher.setMessageContentMatcher(new EncodedDataMatcher(new Binary(content)));
+
+            testPeer.expectTransfer(messageMatcher);
+
+            // Create a foreign message, [erroneously] set a JMSMessageID value
+            ForeignJmsBytesMessage foreign = new ForeignJmsBytesMessage();
+            foreign.writeBytes(content);
+
+            assertNull("JMSMessageID should not yet be set", foreign.getJMSMessageID());
+            String existingMessageId = "ID:this-should-be-overwritten-in-send";
+            foreign.setJMSMessageID(existingMessageId);
+            assertEquals("JMSMessageID should now be set", existingMessageId, foreign.getJMSMessageID());
+
+            // Toggle the DisableMessageID hint, then send it
+            producer.setDisableMessageID(true);
+            producer.send(foreign);
+
+            assertNull("JMSMessageID should now be null", foreign.getJMSMessageID());
+
+            testPeer.waitForAllHandlersToComplete(2000);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/26a87e76/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
index 6306f19..1cc54b3 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
@@ -638,6 +638,20 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
      */
     @Test(timeout = 20000)
     public void testSendingMessageWithDisableMessageIDHint() throws Exception {
+        doSendingMessageWithDisableMessageIDHintTestImpl(false);
+    }
+
+    /**
+     * Test that after sending a message with the disableMessageID hint set, which already had
+     * a JMSMessageID value, that the message object then has a null JMSMessageID value, and no
+     * message-id field value was set.
+     */
+    @Test(timeout = 20000)
+    public void testSendingMessageWithDisableMessageIDHintAndExistingMessageID() throws Exception {
+        doSendingMessageWithDisableMessageIDHintTestImpl(true);
+    }
+
+    private void doSendingMessageWithDisableMessageIDHintTestImpl(boolean existingId) throws JMSException, InterruptedException, Exception, IOException {
         try(TestAmqpPeer testPeer = new TestAmqpPeer();) {
             Connection connection = testFixture.establishConnecton(testPeer);
             testPeer.expectBegin();
@@ -664,12 +678,19 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
 
             assertNull("JMSMessageID should not yet be set", message.getJMSMessageID());
 
-            producer.setDisableMessageID(true);
+            if (existingId) {
+                // [erroneously] set a JMSMessageID value
+                String existingMessageId = "ID:this-should-be-overwritten-in-send";
+                message.setJMSMessageID(existingMessageId);
+                assertEquals("JMSMessageID should now be set", existingMessageId, message.getJMSMessageID());
+            }
 
+            producer.setDisableMessageID(true);
             producer.send(message);
-            testPeer.waitForAllHandlersToComplete(1000);
 
-            assertNull("JMSMessageID should still not yet be set", message.getJMSMessageID());
+            assertNull("JMSMessageID should be null", message.getJMSMessageID());
+
+            testPeer.waitForAllHandlersToComplete(2000);
         }
     }
 


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