activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1346564 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Commands/ActiveMQObjectMessage.cs test/csharp/Commands/MessageCompressionTest.cs
Date Tue, 05 Jun 2012 20:13:11 GMT
Author: tabish
Date: Tue Jun  5 20:13:11 2012
New Revision: 1346564

URL: http://svn.apache.org/viewvc?rev=1346564&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQNET-388

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQObjectMessage.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/MessageCompressionTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQObjectMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQObjectMessage.cs?rev=1346564&r1=1346563&r2=1346564&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQObjectMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQObjectMessage.cs
Tue Jun  5 20:13:11 2012
@@ -18,6 +18,7 @@
 using System.IO;
 
 #if !(PocketPC||NETCF||NETCF_2_0)
+using Apache.NMS.Util;
 using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters.Binary;
 #endif
@@ -61,8 +62,21 @@ namespace Apache.NMS.ActiveMQ.Commands
             {
 #if !(PocketPC||NETCF||NETCF_2_0)
                 if (body == null)
-                {
-                    body = Formatter.Deserialize(new MemoryStream(Content));
+                {                
+                    if(base.Content == null)
+                    {
+                        return null;
+                    }
+
+                    byte[] data = base.Content;
+                    Stream target = new MemoryStream(data, false);
+                
+                    if(this.Connection != null && this.Compressed == true)
+                    {
+                        target = this.Connection.CompressionPolicy.CreateDecompressionStream(target);
+                    }
+
+                    body = Formatter.Deserialize(target);
                 }
                 return body;
 #else
@@ -89,9 +103,17 @@ namespace Apache.NMS.ActiveMQ.Commands
             }
             else
             {
-                MemoryStream stream = new MemoryStream();
-                Formatter.Serialize(stream, body);
-                Content = stream.ToArray();
+                MemoryStream result = new MemoryStream();
+                Stream target = result;
+                if(this.Connection != null && this.Connection.UseCompression)
+                {
+                    this.Compressed = true;
+                    target = this.Connection.CompressionPolicy.CreateCompressionStream(target);
                   
+                }
+
+                Formatter.Serialize(target, body);
+                target.Close();
+                Content = result.ToArray();
             }
 
             //Console.WriteLine("BeforeMarshalling, content is: " + Content);

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/MessageCompressionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/MessageCompressionTest.cs?rev=1346564&r1=1346563&r2=1346564&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/MessageCompressionTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/MessageCompressionTest.cs
Tue Jun  5 20:13:11 2012
@@ -17,6 +17,7 @@
 
 using System;
 using System.IO;
+using Apache.NMS;
 using Apache.NMS.Test;
 using Apache.NMS.ActiveMQ.Commands;
 using NUnit.Framework;
@@ -86,6 +87,36 @@ namespace Apache.NMS.ActiveMQ.Test
         }
 
         [Test]
+        public void TestObjectMessageCompression()
+        {
+            using(Connection connection = CreateConnection(TEST_CLIENT_ID) as Connection)
+            {
+                connection.UseCompression = true;
+                connection.Start();
+
+                Assert.IsTrue(connection.UseCompression);
+
+                using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+                {
+                    IObjectMessage message = session.CreateObjectMessage(TEXT);
+
+                    IDestination destination = session.CreateTemporaryQueue();
+                    
+                    IMessageProducer producer = session.CreateProducer(destination);
+                    IMessageConsumer consumer = session.CreateConsumer(destination);
+
+                    producer.Send(message);
+
+                    message = consumer.Receive(TimeSpan.FromMilliseconds(6000)) as IObjectMessage;
+                    
+                    Assert.IsNotNull(message);
+                    Assert.IsTrue(((ActiveMQMessage) message).Compressed);
+                    Assert.AreEqual(TEXT, message.Body);
+                }
+            }
+        }
+
+        [Test]
         public void TestStreamMessageCompression()
         {
             using(Connection connection = CreateConnection(TEST_CLIENT_ID) as Connection)



Mime
View raw message