You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2012/04/13 01:51:03 UTC

svn commit: r1325572 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TempDestinationTest.cs

Author: jgomes
Date: Thu Apr 12 23:51:03 2012
New Revision: 1325572

URL: http://svn.apache.org/viewvc?rev=1325572&view=rev
Log:
Refactor TestConsumeAfterPublishFailsForDestroyedTempDestination to be deterministic in deleting the temp queue by monitoring the advisory messages instead of estimating that waiting 2 seconds is long enough for the delete to occur.  This makes the test run reliably, and it runs as fast as possible.

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

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TempDestinationTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TempDestinationTest.cs?rev=1325572&r1=1325571&r2=1325572&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TempDestinationTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TempDestinationTest.cs Thu Apr 12 23:51:03 2012
@@ -38,6 +38,9 @@ namespace Apache.NMS.ActiveMQ.Test
 		public override void SetUp()
 		{
 			base.SetUp();
+
+			this.tempDestsAdded.Clear();
+			this.tempDestsRemoved.Clear();
 		}
 
 		[TearDown]
@@ -287,23 +290,27 @@ namespace Apache.NMS.ActiveMQ.Test
 			IMessageConsumer consumer = consumerSession.CreateConsumer(consumerDestination);
 
 			consumerConnection.Start();
-			
+
 			// Purge the destination before starting.
-			while (consumer.Receive(TimeSpan.FromMilliseconds(3000)) != null)
+			while(consumer.Receive(TimeSpan.FromMilliseconds(3000)) != null)
 			{
-			}			
+			}
+
+			IMessageConsumer advisoryConsumer = consumerSession.CreateConsumer(AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC);
+			advisoryConsumer.Listener += OnAdvisoryMessage;
 
 			// The real test is whether sending a message to a deleted temp queue messes up
 			// the consumers on the same connection.
 			for(int index = 0; index < 25; index++)
 			{
+				Tracer.InfoFormat("LOOP #{0} ---------------------------------------------------", index + 1);
 				Connection producerConnection = GetNewConnection();
 				ISession producerSession = producerConnection.CreateSession(AcknowledgementMode.AutoAcknowledge);
 				IDestination producerDestination = producerSession.GetQueue(msgQueueName);
 				IMessageProducer producer = producerSession.CreateProducer(producerDestination);
 				IDestination replyDestination = producerSession.CreateTemporaryQueue();
 				IMessageConsumer replyConsumer = producerSession.CreateConsumer(replyDestination);
-				
+
 				producerConnection.Start();
 
 				IMessage sendMsg = producer.CreateTextMessage("Consumer check.");
@@ -314,11 +321,12 @@ namespace Apache.NMS.ActiveMQ.Test
 				// Will the following Receive() call fail on the second or subsequent calls?
 				IMessage receiveMsg = consumer.Receive();
 				IMessageProducer replyProducer = consumerSession.CreateProducer(receiveMsg.NMSReplyTo);
-				
+
 				replyConsumer.Close();
 				connections.Remove(producerConnection);
 				producerConnection.Close();
-				Thread.Sleep(2000); // Wait a little bit to let the delete take effect.
+
+				WaitForTempDestinationDelete(replyDestination);
 
 				// This message delivery NOT should work since the temp destination was removed by closing the connection.
 				try
@@ -334,6 +342,36 @@ namespace Apache.NMS.ActiveMQ.Test
 			}
 		}
 
+		private void WaitForTempDestinationDelete(IDestination replyDestination)
+		{
+			const int MaxLoopCount = 200;
+			int loopCount = 0;
+			bool destinationDeleted = false;
+			ActiveMQTempDestination replyTempDestination = replyDestination as ActiveMQTempDestination;
+
+			while(!destinationDeleted)
+			{
+				loopCount++;
+				if(loopCount > MaxLoopCount)
+				{
+					Assert.Fail(string.Format("Timeout waiting for delete of {0}", replyTempDestination.PhysicalName));
+				}
+
+				Thread.Sleep(10);
+				lock(this.tempDestsRemoved.SyncRoot)
+				{
+					foreach(ActiveMQTempDestination tempDest in this.tempDestsRemoved)
+					{
+						if(0 == string.Compare(tempDest.PhysicalName, replyTempDestination.PhysicalName, true))
+						{
+							destinationDeleted = true;
+							break;
+						}
+					}
+				}
+			}
+		}
+
 		/// <summary>
 		/// Test you can't delete a Destination with Active Subscribers
 		/// </summary>