Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5A951200C3F for ; Tue, 7 Mar 2017 16:33:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5969F160B5F; Tue, 7 Mar 2017 15:33:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DE5FA160B8F for ; Tue, 7 Mar 2017 16:33:49 +0100 (CET) Received: (qmail 62431 invoked by uid 500); 7 Mar 2017 15:33:48 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 62062 invoked by uid 99); 7 Mar 2017 15:33:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2017 15:33:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 76C6EDFF4E; Tue, 7 Mar 2017 15:33:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: tabish@apache.org To: commits@activemq.apache.org Date: Tue, 07 Mar 2017 15:33:59 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [12/25] activemq-nms-ems git commit: 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 archived-at: Tue, 07 Mar 2017 15:33:51 -0000 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. Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/commit/8c927a24 Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/tree/8c927a24 Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/diff/8c927a24 Branch: refs/heads/1.5.x Commit: 8c927a24544c5b0d3a31c02e6079c383f290e89f Parents: ef70785 Author: Jim Gomes Authored: Tue Sep 20 00:11:02 2011 +0000 Committer: Jim Gomes Committed: Tue Sep 20 00:11:02 2011 +0000 ---------------------------------------------------------------------- src/main/csharp/MapMessage.cs | 14 +++--- src/main/csharp/MessageConsumer.cs | 11 ++++- src/test/csharp/ReqResponseTempQueue.cs | 71 ++++++++++++++++++++++++++++ vs2008-ems-test.csproj | 1 + 4 files changed, 88 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/blob/8c927a24/src/main/csharp/MapMessage.cs ---------------------------------------------------------------------- diff --git a/src/main/csharp/MapMessage.cs b/src/main/csharp/MapMessage.cs index 2232421..49b642f 100644 --- a/src/main/csharp/MapMessage.cs +++ b/src/main/csharp/MapMessage.cs @@ -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)); } http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/blob/8c927a24/src/main/csharp/MessageConsumer.cs ---------------------------------------------------------------------- diff --git a/src/main/csharp/MessageConsumer.cs b/src/main/csharp/MessageConsumer.cs index 16e227e..cf5ca6f 100644 --- a/src/main/csharp/MessageConsumer.cs +++ b/src/main/csharp/MessageConsumer.cs @@ -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(); } } http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/blob/8c927a24/src/test/csharp/ReqResponseTempQueue.cs ---------------------------------------------------------------------- diff --git a/src/test/csharp/ReqResponseTempQueue.cs b/src/test/csharp/ReqResponseTempQueue.cs new file mode 100644 index 0000000..9d5da37 --- /dev/null +++ b/src/test/csharp/ReqResponseTempQueue.cs @@ -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(); + } + } + } + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-nms-ems/blob/8c927a24/vs2008-ems-test.csproj ---------------------------------------------------------------------- diff --git a/vs2008-ems-test.csproj b/vs2008-ems-test.csproj index 5f2bdb7..1ddf024 100644 --- a/vs2008-ems-test.csproj +++ b/vs2008-ems-test.csproj @@ -75,6 +75,7 @@ +