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 e523178  AMQNET-622: Invoke IConnection event listeners on connection 
lost and on reconnect
     new d87646e  Merge pull request #51 from 
HavretGC/AMQNET-622_invoke-IConnection-event-listeners-on-reconnect
e523178 is described below

commit e5231786f4422c4a738bd4583ccede7dc1e0ab5f
Author: Havret <[email protected]>
AuthorDate: Mon Dec 30 15:41:30 2019 +0100

    AMQNET-622: Invoke IConnection event listeners on connection lost and on 
reconnect
---
 src/NMS.AMQP/NmsConnection.cs                      |  4 ++
 .../Integration/FailoverIntegrationTest.cs         | 53 ++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/src/NMS.AMQP/NmsConnection.cs b/src/NMS.AMQP/NmsConnection.cs
index 6ce0903..978c2f4 100644
--- a/src/NMS.AMQP/NmsConnection.cs
+++ b/src/NMS.AMQP/NmsConnection.cs
@@ -326,6 +326,8 @@ namespace Apache.NMS.AMQP
             {
                 listener.OnConnectionRestored(remoteUri);
             }
+            
+            ConnectionResumedListener?.Invoke();
         }
 
         public void OnResourceClosed(INmsResource resource, Exception error)
@@ -370,6 +372,8 @@ namespace Apache.NMS.AMQP
             
             foreach (INmsConnectionListener listener in connectionListeners)
                 listener.OnConnectionInterrupted(failedUri);
+            
+            ConnectionInterruptedListener?.Invoke();
         }
 
         private void CheckClosedOrFailed()
diff --git a/test/Apache-NMS-AMQP-Test/Integration/FailoverIntegrationTest.cs 
b/test/Apache-NMS-AMQP-Test/Integration/FailoverIntegrationTest.cs
index 2bd93ff..d853df0 100644
--- a/test/Apache-NMS-AMQP-Test/Integration/FailoverIntegrationTest.cs
+++ b/test/Apache-NMS-AMQP-Test/Integration/FailoverIntegrationTest.cs
@@ -1060,6 +1060,59 @@ namespace NMS.AMQP.Test.Integration
             }
         }
 
+        [Test, Timeout(20_000), Category("Windows")]
+        public void 
TestConnectionInterruptedInvokedWhenConnectionToBrokerLost()
+        {
+            using (TestAmqpPeer originalPeer = new TestAmqpPeer())
+            {
+                ManualResetEvent connectionInterruptedInvoked = new 
ManualResetEvent(false);
+
+                originalPeer.ExpectSaslAnonymous();
+                originalPeer.ExpectOpen();
+                originalPeer.ExpectBegin();
+                originalPeer.ExpectBegin();
+
+                NmsConnection connection = 
EstablishAnonymousConnection(originalPeer);
+
+                connection.ConnectionInterruptedListener += () => 
connectionInterruptedInvoked.Set();
+
+                connection.Start();
+                
+                originalPeer.Close();
+
+                
Assert.IsTrue(connectionInterruptedInvoked.WaitOne(TimeSpan.FromSeconds(10)));
+            }
+        }
+        
+        [Test, Timeout(20_000), Category("Windows")]
+        public void TestConnectionResumedInvokedWhenConnectionToBrokerLost()
+        {
+            using (TestAmqpPeer originalPeer = new TestAmqpPeer())
+            using (TestAmqpPeer finalPeer = new TestAmqpPeer())
+            {
+                ManualResetEvent connectionResumedInvoked = new 
ManualResetEvent(false);
+
+                originalPeer.ExpectSaslAnonymous();
+                originalPeer.ExpectOpen();
+                originalPeer.ExpectBegin();
+                originalPeer.ExpectBegin();
+
+                finalPeer.ExpectSaslAnonymous();
+                finalPeer.ExpectOpen();
+                finalPeer.ExpectBegin();
+                finalPeer.ExpectBegin();
+
+                NmsConnection connection = 
EstablishAnonymousConnection(originalPeer, finalPeer);
+
+                connection.ConnectionResumedListener += () => 
connectionResumedInvoked.Set();
+
+                connection.Start();
+                
+                originalPeer.Close();
+                
Assert.IsTrue(connectionResumedInvoked.WaitOne(TimeSpan.FromSeconds(10)));
+            }
+        }
+
         private NmsConnection EstablishAnonymousConnection(params 
TestAmqpPeer[] peers)
         {
             return EstablishAnonymousConnection(null, null, peers);

Reply via email to