activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r991197 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageConsumerTest.cs
Date Tue, 31 Aug 2010 14:09:04 GMT
Author: tabish
Date: Tue Aug 31 14:09:03 2010
New Revision: 991197

URL: http://svn.apache.org/viewvc?rev=991197&view=rev
Log:
Do a proper cleanup of Consumers, Producers, and Session so that the DeleteDestination actually
succeeds for all the different variations of the test.

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

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageConsumerTest.cs?rev=991197&r1=991196&r2=991197&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageConsumerTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageConsumerTest.cs
Tue Aug 31 14:09:03 2010
@@ -24,109 +24,114 @@ using Apache.NMS.Util;
 
 namespace Apache.NMS.ActiveMQ.Test
 {
-	public enum ExpirationOptions
-	{
-		DEFAULT,
-		IGNORE,
-		DO_NOT_IGNORE
-	}
-
-	[TestFixture]
-	public class MessageConsumerTest : NMSTestSupport
-	{
-		protected static string DESTINATION_NAME = "queue://TestDestination";
-		protected static string TEST_CLIENT_ID = "MessageConsumerTestClientId";
-
-		[Test]
-		public void TestReceiveIgnoreExpirationMessage(
-			[Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
-				AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
-			AcknowledgementMode ackMode,
-			[Values(MsgDeliveryMode.NonPersistent, MsgDeliveryMode.Persistent)]
-			MsgDeliveryMode deliveryMode,
-			[Values(ExpirationOptions.DEFAULT, ExpirationOptions.IGNORE, ExpirationOptions.DO_NOT_IGNORE)]
-			ExpirationOptions expirationOption)
-		{
-			using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
-			{
-				connection.Start();
-				using(Session session = connection.CreateSession(ackMode) as Session)
-				{
-					string destinationName = DESTINATION_NAME;
-
-					if(ExpirationOptions.IGNORE == expirationOption)
-					{
-						destinationName += "?consumer.nms.ignoreExpiration=true";
-					}
-					else if(ExpirationOptions.DO_NOT_IGNORE == expirationOption)
-					{
-						destinationName += "?consumer.nms.ignoreExpiration=false";
-					}
-
-					try
-					{
-						IDestination destination = SessionUtil.GetDestination(session, destinationName);
-
-						using(IMessageConsumer consumer = session.CreateConsumer(destination))
-						using(IMessageProducer producer = session.CreateProducer(destination))
-						{
-							producer.DeliveryMode = deliveryMode;
-
-							string msgText = "ExpiredMessage:" + Guid.NewGuid().ToString();
-
-							ActiveMQTextMessage msg = session.CreateTextMessage(msgText) as ActiveMQTextMessage;
-
-							// Give it two seconds to live.
-							msg.NMSTimeToLive = TimeSpan.FromMilliseconds(2000);
-
-							producer.Send(msg);
-
-							if(AcknowledgementMode.Transactional == ackMode)
-							{
-								session.Commit();
-							}
-
-							// Wait for four seconds before processing it.  The broker will have sent it to our
local
-							// client dispatch queue, but we won't attempt to process the message until it has
had
-							// a chance to expire within our internal queue system.
-							Thread.Sleep(4000);
-
-							ActiveMQTextMessage rcvMsg = consumer.ReceiveNoWait() as ActiveMQTextMessage;
-
-							if(ExpirationOptions.IGNORE == expirationOption)
-							{
-								Assert.IsNotNull(rcvMsg, "Did not receive expired message.");
-								rcvMsg.Acknowledge();
-
-								Assert.AreEqual(msgText, rcvMsg.Text, "Message text does not match.");
-								Assert.IsTrue(rcvMsg.IsExpired());
-
-								if(AcknowledgementMode.Transactional == ackMode)
-								{
-									session.Commit();
-								}
-							}
-							else
-							{
-								// Should not receive a message.
-								Assert.IsNull(rcvMsg, "Received an expired message!");
-							}
-						}
-					}
-					finally
-					{
-						try
-						{
-							// Give the Broker some time to remove the subscriptions.
-							Thread.Sleep(2000);
-							SessionUtil.DeleteDestination(session, destinationName);
-						}
-						catch
-						{
-						}
-					}
-				}
-			}
-		}
-	}
+    public enum ExpirationOptions
+    {
+        DEFAULT,
+        IGNORE,
+        DO_NOT_IGNORE
+    }
+
+    [TestFixture]
+    public class MessageConsumerTest : NMSTestSupport
+    {
+        protected static string DESTINATION_NAME = "queue://MessageConsumerTestDestination";
+        protected static string TEST_CLIENT_ID = "MessageConsumerTestClientId";
+
+        [Test]
+        public void TestReceiveIgnoreExpirationMessage(
+            [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
+                AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
+            AcknowledgementMode ackMode,
+            [Values(MsgDeliveryMode.NonPersistent, MsgDeliveryMode.Persistent)]
+            MsgDeliveryMode deliveryMode,
+            [Values(ExpirationOptions.DEFAULT, ExpirationOptions.IGNORE, ExpirationOptions.DO_NOT_IGNORE)]
+            ExpirationOptions expirationOption)
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {
+                connection.Start();
+                using(Session session = connection.CreateSession(ackMode) as Session)
+                {
+                    string destinationName = DESTINATION_NAME;
+
+                    if(ExpirationOptions.IGNORE == expirationOption)
+                    {
+                        destinationName += "?consumer.nms.ignoreExpiration=true";
+                    }
+                    else if(ExpirationOptions.DO_NOT_IGNORE == expirationOption)
+                    {
+                        destinationName += "?consumer.nms.ignoreExpiration=false";
+                    }
+
+                    try
+                    {
+                        IDestination destination = SessionUtil.GetDestination(session, destinationName);
+
+                        using(IMessageConsumer consumer = session.CreateConsumer(destination))
+                        using(IMessageProducer producer = session.CreateProducer(destination))
+                        {
+                            producer.DeliveryMode = deliveryMode;
+
+                            string msgText = "ExpiredMessage:" + Guid.NewGuid().ToString();
+
+                            ActiveMQTextMessage msg = session.CreateTextMessage(msgText)
as ActiveMQTextMessage;
+
+                            // Give it two seconds to live.
+                            msg.NMSTimeToLive = TimeSpan.FromMilliseconds(2000);
+
+                            producer.Send(msg);
+
+                            if(AcknowledgementMode.Transactional == ackMode)
+                            {
+                                session.Commit();
+                            }
+
+                            // Wait for four seconds before processing it.  The broker will
have sent it to our local
+                            // client dispatch queue, but we won't attempt to process the
message until it has had
+                            // a chance to expire within our internal queue system.
+                            Thread.Sleep(4000);
+
+                            ActiveMQTextMessage rcvMsg = consumer.ReceiveNoWait() as ActiveMQTextMessage;
+
+                            if(ExpirationOptions.IGNORE == expirationOption)
+                            {
+                                Assert.IsNotNull(rcvMsg, "Did not receive expired message.");
+                                rcvMsg.Acknowledge();
+
+                                Assert.AreEqual(msgText, rcvMsg.Text, "Message text does
not match.");
+                                Assert.IsTrue(rcvMsg.IsExpired());
+
+                                if(AcknowledgementMode.Transactional == ackMode)
+                                {
+                                    session.Commit();
+                                }
+                            }
+                            else
+                            {
+                                // Should not receive a message.
+                                Assert.IsNull(rcvMsg, "Received an expired message!");
+                            }
+
+                            consumer.Close();
+                            producer.Close();
+                        }
+                    }
+                    finally
+                    {
+                        try
+                        {
+                            // Ensure that Session resources on the Broker release transacted
Consumers.
+                            session.Close();
+                            // Give the Broker some time to remove the subscriptions.
+                            Thread.Sleep(2000);
+                            SessionUtil.DeleteDestination(session, destinationName);
+                        }
+                        catch
+                        {
+                        }
+                    }
+                }
+            }
+        }
+    }
 }



Mime
View raw message