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 2017/03/08 23:12:43 UTC

[41/50] [abbrv] activemq-nms-openwire git commit: Ensure that the message body is always marshaled. Fixes case of a single message -> receive -> send -> receive which would lose its body on the re-send.

Ensure that the message body is always marshaled.  Fixes case of a single message -> receive -> send -> receive which would lose its body on the re-send.  

AMQNET-514
Fixes [AMQNET-AMQNET-514]. (See https://issues.apache.org/jira/browse/AMQNET-AMQNET-514)



Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/commit/44f43190
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/tree/44f43190
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/diff/44f43190

Branch: refs/heads/master
Commit: 44f43190fb3714c908f5d759501ba50958f172f9
Parents: 78d40fd
Author: Timothy A. Bish <ta...@apache.org>
Authored: Tue Jan 5 17:17:31 2016 +0000
Committer: Timothy A. Bish <ta...@apache.org>
Committed: Tue Jan 5 17:17:31 2016 +0000

----------------------------------------------------------------------
 src/main/csharp/Commands/ActiveMQMapMessage.cs  |  6 +--
 .../csharp/Commands/ActiveMQMapMessageTest.cs   | 53 ++++++++++++++++++--
 2 files changed, 49 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/44f43190/src/main/csharp/Commands/ActiveMQMapMessage.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Commands/ActiveMQMapMessage.cs b/src/main/csharp/Commands/ActiveMQMapMessage.cs
index 7bdebdf..2b9a057 100644
--- a/src/main/csharp/Commands/ActiveMQMapMessage.cs
+++ b/src/main/csharp/Commands/ActiveMQMapMessage.cs
@@ -91,11 +91,7 @@ namespace Apache.NMS.ActiveMQ.Commands
 
 		public override void BeforeMarshall(OpenWireFormat wireFormat)
 		{
-			if(body == null)
-			{
-				Content = null;
-			}
-			else
+            if (this.Content == null && this.body != null && this.body.Count > 0)
 			{
 				MemoryStream buffer = new MemoryStream();
 				Stream target = buffer;

http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/44f43190/src/test/csharp/Commands/ActiveMQMapMessageTest.cs
----------------------------------------------------------------------
diff --git a/src/test/csharp/Commands/ActiveMQMapMessageTest.cs b/src/test/csharp/Commands/ActiveMQMapMessageTest.cs
index 016822f..ecde5a6 100644
--- a/src/test/csharp/Commands/ActiveMQMapMessageTest.cs
+++ b/src/test/csharp/Commands/ActiveMQMapMessageTest.cs
@@ -19,15 +19,17 @@ using System;
 using System.Collections;
 using System.Globalization;
 using System.Text;
+using Apache.NMS;
+using Apache.NMS.Test;
+using Apache.NMS.Util;
 using Apache.NMS.ActiveMQ.Commands;
 using NUnit.Framework;
 
 namespace Apache.NMS.ActiveMQ.Test.Commands
 {    
     [TestFixture]
-    public class ActiveMQMapMessageTest
+    public class ActiveMQMapMessageTest : NMSTestSupport
     {
-
         private string name = "testName";
         
         [Test]
@@ -305,7 +307,6 @@ namespace Apache.NMS.ActiveMQ.Test.Commands
             catch(MessageFormatException)
             {
             }
-    
         }
     
         [Test]
@@ -457,7 +458,8 @@ namespace Apache.NMS.ActiveMQ.Test.Commands
             {
             }
             
-            try {
+            try 
+            {
                 msg.Body.SetFloat("float", 1.5f);
                 Assert.Fail("should throw exception");
             } 
@@ -543,6 +545,47 @@ namespace Apache.NMS.ActiveMQ.Test.Commands
             msg.Body.GetShort("short");
             msg.Body.GetString("string");
         }
-        
+
+        [Test]
+        public void TestMessageQueueDequeQueueDequeue()
+        {
+            using (IConnection connection = CreateConnection())
+            using (ISession session = connection.CreateSession())
+            {
+                IDestination destination = session.GetQueue("TestMessageQueueDequeQueueDequeue");
+
+                (connection as Connection).DeleteDestination(destination);
+
+                using (IMessageConsumer consumer = session.CreateConsumer(destination))
+                using (IMessageProducer producer = session.CreateProducer(destination))
+                {
+                    connection.Start();
+
+                    producer.DeliveryMode = MsgDeliveryMode.Persistent;
+
+                    IMapMessage request = session.CreateMapMessage();
+                    request.Body.SetString("Unit-Test-Key", "Unit-Test-Value");
+                    Assert.IsNotNull(request, "request is null");
+                    Assert.IsTrue(request.Body.Contains("Unit-Test-Key"), "Unit-Test-Key does not exist");
+                    producer.Send(request);
+
+                    // Relay from Queue back again.
+                    IMessage received = consumer.Receive(TimeSpan.FromSeconds(2));
+                    Assert.IsNotNull(received);
+                    IMapMessage mapMessage = received as IMapMessage;
+                    Assert.IsNotNull(mapMessage);
+                    producer.Send(mapMessage);
+
+                    // Read it again and validate.
+                    received = consumer.Receive(TimeSpan.FromSeconds(2));
+                    Assert.IsNotNull(received);
+                    mapMessage = received as IMapMessage;
+                    Assert.IsNotNull(mapMessage, "currentMessage is null");
+
+                    // This entry in the map message should not be removed
+                    Assert.IsTrue(mapMessage.Body.Contains("Unit-Test-Key"), "Unit-Test-Key does not exist");
+                }
+            }
+        }
     }
 }