activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r830334 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
Date Tue, 27 Oct 2009 20:54:41 GMT
Author: tabish
Date: Tue Oct 27 20:54:41 2009
New Revision: 830334

URL: http://svn.apache.org/viewvc?rev=830334&view=rev
Log:
Add tests for Client Ack Mode to ensure unacked messages are redelivered.

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs

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=830334&r1=830333&r2=830334&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 Tue Oct 27 20:54:41
2009
@@ -258,7 +258,104 @@
                 Assert.IsNull(consumer.ReceiveNoWait());
             }
         }
-            
+
+        [Test]
+        public void TestAckedMessageAreConsumed()
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {            
+                connection.Start();
+                ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+                IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
+                IMessageProducer producer = session.CreateProducer(queue);
+                producer.Send(session.CreateTextMessage("Hello"));
+        
+                // Consume the message...
+                IMessageConsumer consumer = session.CreateConsumer(queue);
+                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                msg.Acknowledge();
+        
+                // Reset the session.
+                session.Close();
+                session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+        
+                // Attempt to Consume the message...
+                consumer = session.CreateConsumer(queue);
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNull(msg);
+        
+                session.Close();
+            }
+        }
+
+        [Test]
+        public void TestLastMessageAcked()
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {            
+                connection.Start();
+                ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+                IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
+                IMessageProducer producer = session.CreateProducer(queue);
+                producer.Send(session.CreateTextMessage("Hello"));
+                producer.Send(session.CreateTextMessage("Hello2"));
+                producer.Send(session.CreateTextMessage("Hello3"));
+        
+                // Consume the message...
+                IMessageConsumer consumer = session.CreateConsumer(queue);
+                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);        
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                msg.Acknowledge();
+        
+                // Reset the session.
+                session.Close();
+                session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+        
+                // Attempt to Consume the message...
+                consumer = session.CreateConsumer(queue);
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNull(msg);
+        
+                session.Close();
+            }
+        }
+
+        [Test]
+        public void TestUnAckedMessageAreNotConsumedOnSessionClose() 
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {            
+                connection.Start();
+                ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+                IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
+                IMessageProducer producer = session.CreateProducer(queue);
+                producer.Send(session.CreateTextMessage("Hello"));
+        
+                // Consume the message...
+                IMessageConsumer consumer = session.CreateConsumer(queue);
+                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);        
+                // Don't ack the message.
+                
+                // Reset the session.  This should cause the unacknowledged message to be
re-delivered.
+                session.Close();
+                session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
+                        
+                // Attempt to Consume the message...
+                consumer = session.CreateConsumer(queue);
+                msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+                Assert.IsNotNull(msg);        
+                msg.Acknowledge();
+                
+                session.Close();
+            }
+        }
+
 #endif
 
 	}



Mime
View raw message