Author: jgomes
Date: Wed Nov 10 01:22:19 2010
New Revision: 1033315

URL: http://svn.apache.org/viewvc?rev=1033315&view=rev
Log:
Add Clone() override that will copy the MessagePropertyIntercepter object.
Fixes [AMQNET-292]. (See https://issues.apache.org/activemq/browse/AMQNET-292)

Modified:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/ConnectionState.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs?rev=1033315&r1=1033314&r2=1033315&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
 Wed Nov 10 01:22:19 2010
@@ -56,6 +56,14 @@ namespace Apache.NMS.ActiveMQ.Commands
                        return ID_ACTIVEMQMESSAGE;
                }
 
+               public override object Clone()
+               {
+                       ActiveMQMessage cloneMessage = (ActiveMQMessage) 
base.Clone();
+
+                       cloneMessage.propertyHelper = new 
MessagePropertyIntercepter(cloneMessage, cloneMessage.properties, 
this.ReadOnlyProperties) { AllowByteArrays = false };
+                       return cloneMessage;
+               }
+
         public override bool Equals(object that)
         {
             if(that is ActiveMQMessage)

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/ConnectionState.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/ConnectionState.cs?rev=1033315&r1=1033314&r2=1033315&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/ConnectionState.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/ConnectionState.cs
 Wed Nov 10 01:22:19 2010
@@ -106,7 +106,7 @@ namespace Apache.NMS.ActiveMQ.State
                                        return sessions[id];
                                #if DEBUG
                                }
-                               
catch(System.Collections.Generic.KeyNotFoundException ex)
+                               
catch(System.Collections.Generic.KeyNotFoundException)
                                {
                                        // Useful for dignosing missing session 
ids
                                        string sessionList = string.Empty;

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs?rev=1033315&r1=1033314&r2=1033315&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
 Wed Nov 10 01:22:19 2010
@@ -59,6 +59,61 @@ namespace Apache.NMS.ActiveMQ.Test
                                }
                        }
                }
+
+               [Test]
+               public void TestCopyOnSend()
+               {
+                       Uri uri = new 
Uri("mock://localhost:61616?connection.CopyMessageOnSend=true");
+
+                       ConnectionFactory factory = new ConnectionFactory(uri);
+                       using(IConnection connection = 
factory.CreateConnection())
+                       using(ISession session = connection.CreateSession())
+                       {
+                               IDestination destination = 
session.GetTopic("Test");
+                               using(IMessageProducer producer = 
session.CreateProducer(destination))
+                               {
+                                       ITextMessage message = 
session.CreateTextMessage();
+
+                                       for(int i = 0; i < 10; ++i)
+                                       {
+                                               
message.Properties["TribbleName"] = "Tribble" + i.ToString();
+                                               message.Text = "The Trouble 
with Tribbles - " + i.ToString();
+                                               producer.Send(message);
+                                       }
+                               }
+                       }
+               }
+
+               [Test]
+               public void TestNoCopyOnSend()
+               {
+                       Uri uri = new 
Uri("mock://localhost:61616?connection.CopyMessageOnSend=false");
+
+                       ConnectionFactory factory = new ConnectionFactory(uri);
+                       using(IConnection connection = 
factory.CreateConnection())
+                       using(ISession session = connection.CreateSession())
+                       {
+                               IDestination destination = 
session.GetTopic("Test");
+                               using(IMessageProducer producer = 
session.CreateProducer(destination))
+                               {
+                                       ITextMessage message = 
session.CreateTextMessage();
+
+                                       for(int i = 0; i < 10; ++i)
+                                       {
+                                               try
+                                               {
+                                                       
message.Properties["TribbleName"] = "Tribble" + i.ToString();
+                                                       message.Text = "The 
Trouble with Tribbles - " + i.ToString();
+                                                       producer.Send(message);
+                                               }
+                                               
catch(MessageNotWriteableException)
+                                               {
+                                                       Assert.Greater(i, 0);
+                                                       Assert.Less(i, 10);
+                                               }
+                                       }
+                               }
+                       }
+               }
        }
 }
-

Modified: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs?rev=1033315&r1=1033314&r2=1033315&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs 
(original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs 
Wed Nov 10 01:22:19 2010
@@ -161,7 +161,8 @@ namespace Apache.NMS.Test
         public void TestDoChangeSentMessage(
             [Values(AcknowledgementMode.AutoAcknowledge, 
AcknowledgementMode.ClientAcknowledge,
                 AcknowledgementMode.DupsOkAcknowledge, 
AcknowledgementMode.Transactional)]
-            AcknowledgementMode ackMode)
+            AcknowledgementMode ackMode,
+                       [Values(true, false)] bool doClear)
         {
             using(IConnection connection = CreateConnection())
             {
@@ -183,8 +184,11 @@ namespace Apache.NMS.Test
 
                             producer.Send(message);
 
-                            message.ClearBody();
-                            message.ClearProperties();
+                                                       if(doClear)
+                                                       {
+                                                               
message.ClearBody();
+                                                               
message.ClearProperties();
+                                                       }
                         }
 
                         if(ackMode == AcknowledgementMode.Transactional)


Reply via email to