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 2011/09/20 02:11:02 UTC

svn commit: r1172914 - in /activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x: src/main/csharp/MapMessage.cs src/main/csharp/MessageConsumer.cs src/test/csharp/ReqResponseTempQueue.cs vs2008-ems-test.csproj

Author: jgomes
Date: Tue Sep 20 00:11:02 2011
New Revision: 1172914

URL: http://svn.apache.org/viewvc?rev=1172914&view=rev
Log:
Fix a spurious bug in the close consumer code.  The EMS client has a race condition when unregistering a message handler and then closing the consumer.  If it happens slowly, then it works correctly.  If it happens at full speed, then an exception is thrown.  The solution is to not unregister the delegate.  Since the consumer is being destroyed anyway, this is a safe thing to (not) do.
Updated the MapMessage API to remove calls to obsolete APIs.
Added new response temp queue unit test.

Added:
    activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/test/csharp/ReqResponseTempQueue.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MapMessage.cs
    activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/vs2008-ems-test.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MapMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MapMessage.cs?rev=1172914&r1=1172913&r2=1172914&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MapMessage.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MapMessage.cs Tue Sep 20 00:11:02 2011
@@ -87,16 +87,14 @@ namespace Apache.NMS.EMS
 			get
 			{
 				int count = 0;
+
 				try
 				{
-					IEnumerator namesEnumerator = this.tibcoMapMessage.MapNames;
+					ICollection mapNames = this.tibcoMapMessage.GetMapNames();
 
-					if(null != namesEnumerator)
+					if(null != mapNames)
 					{
-						while(namesEnumerator.MoveNext())
-						{
-							count++;
-						}
+						count = mapNames.Count;
 					}
 				}
 				catch(Exception ex)
@@ -116,7 +114,7 @@ namespace Apache.NMS.EMS
 
 				try
 				{
-					foreach(string itemName in EMSConvert.ToEnumerable(this.tibcoMapMessage.MapNames))
+					foreach(string itemName in this.tibcoMapMessage.GetMapNames())
 					{
 						keys.Add(itemName);
 					}
@@ -138,7 +136,7 @@ namespace Apache.NMS.EMS
 
 				try
 				{
-					foreach(string itemName in EMSConvert.ToEnumerable(this.tibcoMapMessage.MapNames))
+					foreach(string itemName in this.tibcoMapMessage.GetMapNames())
 					{
 						keys.Add(this.tibcoMapMessage.GetObject(itemName));
 					}

Modified: activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MessageConsumer.cs?rev=1172914&r1=1172913&r2=1172914&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MessageConsumer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/main/csharp/MessageConsumer.cs Tue Sep 20 00:11:02 2011
@@ -108,7 +108,16 @@ namespace Apache.NMS.EMS
 				{
 					if(!this.nmsSession.tibcoSession.IsClosed)
 					{
-						this.tibcoMessageConsumer.MessageHandler -= this.HandleTibcoMsg;
+						// JGomes: Calling the following message handler removal code creates an
+						// instability in the TIBCO consumer and will fail to unregister a consumer.
+						// This is a very odd bug, but it has been observed that unregistering the
+						// message handler is not necessary and can be harmful.  When the unregister is
+						// executed slowly step-by-step under a debugger, then it works correctly.  When
+						// it is run full speed, it creates a race condition.  Therefore, the code is left
+						// here in a commented out state to demonstrate what normal cleanup code should
+						// look like, but don't uncomment it.
+
+						// this.tibcoMessageConsumer.MessageHandler -= this.HandleTibcoMsg;
 						this.tibcoMessageConsumer.Close();
 					}
 				}

Added: activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/test/csharp/ReqResponseTempQueue.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/test/csharp/ReqResponseTempQueue.cs?rev=1172914&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/test/csharp/ReqResponseTempQueue.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/src/test/csharp/ReqResponseTempQueue.cs Tue Sep 20 00:11:02 2011
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+	[TestFixture]
+	public class ReqResponseTempQueueTest : NMSTestSupport
+	{
+		[Test]
+		public void TestTempQueueHoldsMessagesWithConsumers()
+		{
+			using(IConnection connection = CreateConnection())
+			{
+				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+				{
+					connection.Start();
+					ITemporaryQueue queue = session.CreateTemporaryQueue();
+					IMessageProducer producer = session.CreateProducer(queue);
+
+					producer.DeliveryMode = (MsgDeliveryMode.NonPersistent);
+
+					for(int correlationCount = 0; correlationCount < 100; correlationCount++)
+					{
+						string correlationId = string.Format("CID_{0}", correlationCount);
+						IMessageConsumer consumer = null;
+
+						try
+						{
+							ITextMessage message = session.CreateTextMessage("Hello");
+
+							consumer = session.CreateConsumer(queue, string.Format("JMSCorrelationID = '{0}'", correlationId));
+							message.NMSCorrelationID = correlationId;
+							producer.Send(message);
+
+							IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+							Assert.IsNotNull(message2);
+							Assert.AreEqual(correlationId, message2.NMSCorrelationID, "Received the wrong correlation ID message.");
+							Assert.IsInstanceOf(typeof(ITextMessage), message2);
+							Assert.AreEqual(((ITextMessage)message2).Text, message.Text);
+						}
+						finally
+						{
+							if(null != consumer)
+							{
+								consumer.Close();
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}

Modified: activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/vs2008-ems-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/vs2008-ems-test.csproj?rev=1172914&r1=1172913&r2=1172914&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/vs2008-ems-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.EMS/branches/1.5.x/vs2008-ems-test.csproj Tue Sep 20 00:11:02 2011
@@ -75,6 +75,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="src\test\csharp\CommonAssemblyInfo.cs" />
+    <Compile Include="src\test\csharp\ReqResponseTempQueue.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="vs2008-ems.csproj">