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 2009/11/30 20:27:50 UTC

svn commit: r885550 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src: main/csharp/Commands/MessageDispatch.cs test/csharp/IndividualAckTest.cs

Author: tabish
Date: Mon Nov 30 19:27:49 2009
New Revision: 885550

URL: http://svn.apache.org/viewvc?rev=885550&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQNET-215

Add equality checks for the MessageDispatch command so that the command can be correctly used in collections.  Add new tests to the IndividualAckTest.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/main/csharp/Commands/MessageDispatch.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/test/csharp/IndividualAckTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/main/csharp/Commands/MessageDispatch.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/main/csharp/Commands/MessageDispatch.cs?rev=885550&r1=885549&r2=885550&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/main/csharp/Commands/MessageDispatch.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/main/csharp/Commands/MessageDispatch.cs Mon Nov 30 19:27:49 2009
@@ -91,6 +91,48 @@
             set { this.redeliveryCounter = value; }
         }
 
+        public override int GetHashCode()
+        {
+            int answer = 0;
+
+            answer = (answer * 37) + HashCode(ConsumerId);
+            answer = (answer * 37) + HashCode(Destination);
+            answer = (answer * 37) + HashCode(Message);
+            answer = (answer * 37) + HashCode(RedeliveryCounter);
+
+            return answer;
+        }
+
+        public override bool Equals(object that)
+        {
+            if(that is MessageDispatch)
+            {
+                return Equals((MessageDispatch) that);
+            }
+            return false;
+        }
+
+        public virtual bool Equals(MessageDispatch that)
+        {
+            if(!Equals(this.ConsumerId, that.ConsumerId))
+            {
+                return false;
+            }
+            if(!Equals(this.Destination, that.Destination))
+            {
+                return false;
+            }
+            if(!Equals(this.Message, that.Message))
+            {
+                return false;
+            }
+            if(!Equals(this.RedeliveryCounter, that.RedeliveryCounter))
+            {
+                return false;
+            }
+
+            return true;
+        }
         ///
         /// <summery>
         ///  Return an answer of true to the isMessageDispatch() query.

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/test/csharp/IndividualAckTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/test/csharp/IndividualAckTest.cs?rev=885550&r1=885549&r2=885550&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/test/csharp/IndividualAckTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.2.x/src/test/csharp/IndividualAckTest.cs Mon Nov 30 19:27:49 2009
@@ -182,6 +182,84 @@
             Assert.IsNull(fetchedMessage2);
             consumer.Close();
 	    }
+
+        [Test]
+        public void TestManyMessageAckedAfterMessageConsumption()
+        {
+            int messageCount = 20;
+            IMessage msg;
+
+            ISession session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge);
+            ITemporaryQueue queue = session.CreateTemporaryQueue();
+            IMessageProducer producer = session.CreateProducer(queue);
+            for(int i = 0; i < messageCount; i++)
+            {
+                msg = session.CreateTextMessage("msg" + i);
+                producer.Send(msg);
+            }
+
+            // Consume the message...
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            for(int i = 0; i < messageCount; i++)
+            {
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                msg.Acknowledge();
+            }
+            msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNull(msg);
+
+            // Reset the session.
+            session.Close();
+            session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge);
+
+            // Attempt to Consume the message...
+            consumer = session.CreateConsumer(queue);
+            msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNull(msg);
+            session.Close();
+        }
 		
+        [Test]
+        public void TestManyMessageAckedAfterAllConsumption()
+        {
+            int messageCount = 20;
+            IMessage msg;
+
+            ISession session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge);
+            ITemporaryQueue queue = session.CreateTemporaryQueue();
+            IMessageProducer producer = session.CreateProducer(queue);
+            for(int i = 0; i < messageCount; i++)
+            {
+                msg = session.CreateTextMessage("msg" + i);
+                producer.Send(msg);
+            }
+
+            // Consume the message...
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            IMessage[] consumedMessages = new IMessage[messageCount];
+            for(int i = 0; i < messageCount; i++)
+            {
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                consumedMessages[i] = msg;
+            }
+            for(int i = 0; i < messageCount; i++)
+            {
+                consumedMessages[i].Acknowledge();
+            }
+            msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNull(msg);
+
+            // Reset the session.
+            session.Close();
+            session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge);
+
+            // Attempt to Consume the message...
+            consumer = session.CreateConsumer(queue);
+            msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNull(msg);
+            session.Close();
+        }
     }
 }