You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by mi...@apache.org on 2019/08/30 22:28:37 UTC

[activemq-nms-amqp] branch master updated: AMQNET-603: AmqpProvider shouldn't signal exception when connection is explicitly closed

This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git


The following commit(s) were added to refs/heads/master by this push:
     new e2b03e3  AMQNET-603: AmqpProvider shouldn't signal exception when connection is explicitly closed
     new bfa1a79  Merge pull request #24 from Havret/connection_close_should_not_throw_exception
e2b03e3 is described below

commit e2b03e3e2d4c8f0da92244de957425a29064cb70
Author: Havret <h4...@gmail.com>
AuthorDate: Fri Aug 30 23:17:56 2019 +0200

    AMQNET-603: AmqpProvider shouldn't signal exception when connection is explicitly closed
---
 src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs             |  2 +-
 src/NMS.AMQP/Provider/Amqp/AmqpProvider.cs               |  8 ++++++--
 .../Integration/ConnectionIntegrationTest.cs             | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
index 38f16d4..03ca15e 100644
--- a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
+++ b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
@@ -71,7 +71,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp
             Address address = UriUtil.ToAddress(remoteUri, Info.username, Info.password);
             this.tsc = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
             underlyingConnection = await transport.CreateAsync(address, new AmqpHandler(this)).ConfigureAwait(false);
-            underlyingConnection.AddClosedCallback(Provider.OnInternalClosed);
+            underlyingConnection.AddClosedCallback((sender, error) => Provider.OnConnectionClosed(error));
             
             // Wait for connection to be opened
             await tsc.Task;
diff --git a/src/NMS.AMQP/Provider/Amqp/AmqpProvider.cs b/src/NMS.AMQP/Provider/Amqp/AmqpProvider.cs
index 64397e7..24022a8 100644
--- a/src/NMS.AMQP/Provider/Amqp/AmqpProvider.cs
+++ b/src/NMS.AMQP/Provider/Amqp/AmqpProvider.cs
@@ -56,9 +56,13 @@ namespace Apache.NMS.AMQP.Provider.Amqp
             return connection.Start();
         }
 
-        internal void OnInternalClosed(IAmqpObject sender, Error error)
+        internal void OnConnectionClosed(Error error)
         {
-            Listener?.OnConnectionFailure(ExceptionSupport.GetException(error));
+            bool connectionExplicitlyClosed = error == null;
+            if (!connectionExplicitlyClosed)
+            {
+                Listener?.OnConnectionFailure(ExceptionSupport.GetException(error));
+            }
         }
 
         internal void FireConnectionEstablished()
diff --git a/test/Apache-NMS-AMQP-Test/Integration/ConnectionIntegrationTest.cs b/test/Apache-NMS-AMQP-Test/Integration/ConnectionIntegrationTest.cs
index 0dac25a..e9849a5 100644
--- a/test/Apache-NMS-AMQP-Test/Integration/ConnectionIntegrationTest.cs
+++ b/test/Apache-NMS-AMQP-Test/Integration/ConnectionIntegrationTest.cs
@@ -40,6 +40,22 @@ namespace NMS.AMQP.Test.Integration
         }
 
         [Test, Timeout(20_000)]
+        public void TestExplicitConnectionCloseListenerIsNotInvoked()
+        {
+            using (TestAmqpPeer testPeer = new TestAmqpPeer())
+            {
+                ManualResetEvent exceptionFired = new ManualResetEvent(false);
+                IConnection connection = EstablishConnection(testPeer);
+                connection.ExceptionListener += exception => { exceptionFired.Set(); };
+                
+                testPeer.ExpectClose();
+                connection.Close();
+                
+                Assert.IsFalse(exceptionFired.WaitOne(TimeSpan.FromMilliseconds(100)));
+            }
+        }
+        
+        [Test, Timeout(20_000)]
         public void TestCreateAutoAckSession()
         {
             using (TestAmqpPeer testPeer = new TestAmqpPeer())