activemq-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=661426&view=rev
Log:
Added Durable transactional test from Demis Bellot.
Additional fixes made to base NMSTestSupport.
Fixes [AMQNET-65]. (See https://issues.apache.org/activemq/browse/AMQNET-65)

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.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=661426&r1=661425&r2=661426&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:06:23
2008
@@ -19,89 +19,130 @@
 
 namespace Apache.NMS.Test
 {
-    [TestFixture]
-    public abstract class DurableTest : NMSTestSupport
-    {
-        private static string TOPIC = "TestTopic";
-        private static String CLIENT_ID = "DurableClientId";
-        private static String CONSUMER_ID = "ConsumerId";
-
-        private int count = 0;
-
-        public void RegisterDurableConsumer()
-        {
-            using (IConnection connection = Factory.CreateConnection())
-            {
-                connection.ClientId = CLIENT_ID;
-                connection.Start();
-
-                using (ISession session = connection.CreateSession(
-                    AcknowledgementMode.DupsOkAcknowledge))
-                {
-                    ITopic topic = session.GetTopic(TOPIC);
-                    IMessageConsumer consumer = session.CreateDurableConsumer(
-                        topic, CONSUMER_ID, "2 > 1", false);
-                    consumer.Dispose();
-                }
-
-                connection.Stop();
-            }
-        }
-
-        public void SendPersistentMessage()
-        {
-            using (IConnection connection = Factory.CreateConnection())
-            {
-                connection.Start();
-                using (ISession session = connection.CreateSession(
-                    AcknowledgementMode.DupsOkAcknowledge))
-                {
-                    ITopic topic = session.GetTopic(TOPIC);
-                    ITextMessage message = session.CreateTextMessage("Hello");
-                    message.NMSPersistent = true;
-                    IMessageProducer producer = session.CreateProducer();
-                    producer.Send(topic, message);
-                    producer.Dispose();
-                }
-
-                connection.Stop();
-            }
-        }
-
-        [Test]
-        public void TestMe()
-        {
-            count = 0;
-
-            RegisterDurableConsumer();
-            SendPersistentMessage();
-
-            using (IConnection connection = Factory.CreateConnection())
-            {
-                connection.ClientId = CLIENT_ID;
-                connection.Start();
-
-                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();
-                }
-            }
-        }
-
-        /// <summary>
-        ///
-        /// </summary>
-        /// <param name="message"></param>
-        private void consumer_Listener(IMessage message)
-        {
-            ++count;
-        }
-    }
-}
\ No newline at end of file
+	[TestFixture]
+	public abstract class DurableTest : NMSTestSupport
+	{
+		private static string TOPIC = "TestTopic";
+		private static String CLIENT_ID = "DurableClientId";
+		private static String CONSUMER_ID = "ConsumerId";
+
+		private int count = 0;
+
+		public void RegisterDurableConsumer()
+		{
+			using (IConnection connection = Factory.CreateConnection())
+			{
+				connection.ClientId = CLIENT_ID;
+				connection.Start();
+
+				using (ISession session = connection.CreateSession(
+					AcknowledgementMode.DupsOkAcknowledge))
+				{
+					ITopic topic = session.GetTopic(TOPIC);
+					IMessageConsumer consumer = session.CreateDurableConsumer(
+						topic, CONSUMER_ID, "2 > 1", false);
+					consumer.Dispose();
+				}
+
+				connection.Stop();
+			}
+		}
+
+		public void SendPersistentMessage()
+		{
+			using (IConnection connection = Factory.CreateConnection())
+			{
+				connection.Start();
+				using (ISession session = connection.CreateSession(
+					AcknowledgementMode.DupsOkAcknowledge))
+				{
+					ITopic topic = session.GetTopic(TOPIC);
+					ITextMessage message = session.CreateTextMessage("Hello");
+					message.NMSPersistent = true;
+					IMessageProducer producer = session.CreateProducer();
+					producer.Send(topic, message);
+					producer.Dispose();
+				}
+
+				connection.Stop();
+			}
+		}
+
+		[Test]
+		public void TestMe()
+		{
+			count = 0;
+
+			RegisterDurableConsumer();
+			SendPersistentMessage();
+
+			using (IConnection connection = Factory.CreateConnection())
+			{
+				connection.ClientId = CLIENT_ID;
+				connection.Start();
+
+				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();
+				}
+			}
+		}
+
+		[Test]
+		public void TestMeTransactional()
+		{
+			count = 0;
+
+			RegisterDurableConsumer();
+			SendPersistentMessage();
+
+			using (IConnection connection = Factory.CreateConnection())
+			{
+				connection.ClientId = CLIENT_ID;
+				connection.Start();
+
+				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();
+				}
+			}
+		}
+
+		/// <summary>
+		///
+		/// </summary>
+		/// <param name="message"></param>
+		private void consumer_Listener(IMessage message)
+		{
+			++count;
+		}
+	}
+}

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=661426&r1=661425&r2=661426&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs Thu May 29
11:06:23 2008
@@ -37,7 +37,7 @@
 		private ISession session;
 		private IDestination destination;
 
-		protected TimeSpan receiveTimeout = TimeSpan.FromMilliseconds(1000);
+		protected TimeSpan receiveTimeout = TimeSpan.FromMilliseconds(5000);
 		protected string clientId;
 		protected bool persistent = true;
 		protected DestinationType destinationType = DestinationType.Queue;
@@ -51,7 +51,6 @@
 		[TearDown]
 		public virtual void TearDown()
 		{
-			destination = null;
 			Disconnect();
 		}
 
@@ -63,7 +62,10 @@
 			{
 				if(value)
 				{
-					Connect();
+					if(connection == null)
+					{
+						Connect();
+					}
 				}
 				else
 				{
@@ -106,7 +108,7 @@
 				if(session == null)
 				{
 					session = Connection.CreateSession(acknowledgementMode);
-					Assert.IsNotNull(connection != null, "no session created");
+					Assert.IsNotNull(session, "no session created");
 				}
 				return session;
 			}
@@ -120,11 +122,11 @@
 			Assert.IsNotNull(connection, "no connection created");
 			connection.Start();
 			WriteLine("Connected.");
-			Assert.IsNotNull(connection, "no connection created");
 		}
 
 		protected virtual void Disconnect()
 		{
+			destination = null;
 			if(session != null)
 			{
 				session.Dispose();



Mime
View raw message