activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r661430 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
Date Thu, 29 May 2008 18:29:00 GMT
Author: jgomes
Date: Thu May 29 11:28:59 2008
New Revision: 661430

URL: http://svn.apache.org/viewvc?rev=661430&view=rev
Log:
Additional clean-up of durable consumers.  Added multiple run of transactional durable consumer
to test for InvalidClientIDException when reconnecting.
Fixes [AMQNET-65]. (See https://issues.apache.org/activemq/browse/AMQNET-65)

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

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs?rev=661430&r1=661429&r2=661430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs Thu May 29 11:28:59
2008
@@ -22,46 +22,45 @@
 	[TestFixture]
 	public abstract class DurableTest : NMSTestSupport
 	{
-		private static string TOPIC = "TestTopic";
+		private static string TOPIC = "TestTopicDurableConsumer";
 		private static String CLIENT_ID = "DurableClientId";
 		private static String CONSUMER_ID = "ConsumerId";
 
 		private int count = 0;
 
-		public void RegisterDurableConsumer()
+		protected void RegisterDurableConsumer()
 		{
-			using (IConnection connection = Factory.CreateConnection())
+			using(IConnection connection = Factory.CreateConnection())
 			{
 				connection.ClientId = CLIENT_ID;
 				connection.Start();
 
-				using (ISession session = connection.CreateSession(
-					AcknowledgementMode.DupsOkAcknowledge))
+				using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					IMessageConsumer consumer = session.CreateDurableConsumer(
-						topic, CONSUMER_ID, "2 > 1", false);
-					consumer.Dispose();
+					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					{
+					}
 				}
 
 				connection.Stop();
 			}
 		}
 
-		public void SendPersistentMessage()
+		protected void SendPersistentMessage()
 		{
-			using (IConnection connection = Factory.CreateConnection())
+			using(IConnection connection = Factory.CreateConnection())
 			{
 				connection.Start();
-				using (ISession session = connection.CreateSession(
-					AcknowledgementMode.DupsOkAcknowledge))
+				using (ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					ITextMessage message = session.CreateTextMessage("Hello");
+					ITextMessage message = session.CreateTextMessage("Persistent Hello");
 					message.NMSPersistent = true;
-					IMessageProducer producer = session.CreateProducer();
-					producer.Send(topic, message);
-					producer.Dispose();
+					using(IMessageProducer producer = session.CreateProducer())
+					{
+						producer.Send(topic, message);
+					}
 				}
 
 				connection.Stop();
@@ -69,7 +68,7 @@
 		}
 
 		[Test]
-		public void TestMe()
+		public void TestDurableConsumer()
 		{
 			count = 0;
 
@@ -81,26 +80,43 @@
 				connection.ClientId = CLIENT_ID;
 				connection.Start();
 
-				using (ISession session = connection.CreateSession(
-					AcknowledgementMode.DupsOkAcknowledge))
+				using (ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					IMessageConsumer consumer = session.CreateDurableConsumer(
-						topic, CONSUMER_ID, "2 > 1", false);
-					consumer.Listener += new MessageListener(consumer_Listener);
-					// Don't know how else to give the system enough time. // Thread.Sleep(5000); Assert.AreEqual(0,
count); Console.WriteLine("Count = " + count); SendPersistentMessage(); Thread.Sleep(5000);
Assert.AreEqual(2, count); Console.WriteLine("Count = " + count); consumer.Dispose(); }
-
-					connection.Stop();
+					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					{
+						consumer.Listener += new MessageListener(consumer_Listener);
+						// Don't know how else to give the system enough time.
+						System.Threading.Thread.Sleep(5000);
+						Assert.AreEqual(1, count);
+						Console.WriteLine("Count = " + count);
+						SendPersistentMessage();
+						System.Threading.Thread.Sleep(5000);
+						Assert.AreEqual(2, count);
+						Console.WriteLine("Count = " + count);
+					}
 				}
+
+				connection.Stop();
 			}
 		}
 
 		[Test]
-		public void TestMeTransactional()
+		public void TestDurableConsumerTransactional()
 		{
-			count = 0;
-
 			RegisterDurableConsumer();
+
+			RunTestDurableConsumerTransactional();
+			// Timeout required before closing/disposing the connection otherwise orphan
+			// connection remains and test will fail when run the second time with a
+			// InvalidClientIDException: DurableClientID already connected.
+			//System.Threading.Thread.Sleep(5000); 
+			RunTestDurableConsumerTransactional();
+		}
+
+		protected void RunTestDurableConsumerTransactional()
+		{
+			count = 0;
 			SendPersistentMessage();
 
 			using (IConnection connection = Factory.CreateConnection())
@@ -108,36 +124,32 @@
 				connection.ClientId = CLIENT_ID;
 				connection.Start();
 
-				using (ISession session = connection.CreateSession(
-					AcknowledgementMode.Transactional))
+				using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					IMessageConsumer consumer = session.CreateDurableConsumer(
-						topic, CONSUMER_ID, "2 > 1", false);
-					consumer.Listener += new MessageListener(consumer_Listener);
-					/// Don't know how else to give the system enough time. 
-
-					System.Threading.Thread.Sleep(3000);
-					Assert.AreEqual(1, count);
-					Console.WriteLine("Count = " + count);
-					SendPersistentMessage();
-					System.Threading.Thread.Sleep(3000);
-					Assert.AreEqual(2, count);
-					Console.WriteLine("Count = " + count);
-
-					session.Commit();
-					// Timeout required before closing/disposing the connection otherwise orphan
-					// connection remains and test will fail when run the second time with a
-					// InvalidClientIDException: DurableClientID already connected.
-					//System.Threading.Thread.Sleep(3000); 
-					consumer.Dispose();
-					connection.Stop();
+					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					{
+						consumer.Listener += new MessageListener(consumer_Listener);
+						/// Don't know how else to give the system enough time. 
+
+						System.Threading.Thread.Sleep(5000);
+						Assert.AreEqual(1, count);
+						Console.WriteLine("Count = " + count);
+						SendPersistentMessage();
+						System.Threading.Thread.Sleep(5000);
+						Assert.AreEqual(2, count);
+						Console.WriteLine("Count = " + count);
+
+						session.Commit();
+					}
 				}
+
+				connection.Stop();
 			}
 		}
 
 		/// <summary>
-		///
+		/// Asynchronous listener call back method.
 		/// </summary>
 		/// <param name="message"></param>
 		private void consumer_Listener(IMessage message)



Mime
View raw message