Skip to content

Commit 7737c58

Browse files
Initial tests for ConnectionFactory#CreateConnection with host lists
1 parent 07e53bb commit 7737c58

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

projects/client/RabbitMQ.Client/src/client/impl/AutorecoveringConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ protected void RecoverConnectionDelegate()
783783
Thread.Sleep(m_factory.NetworkRecoveryInterval);
784784
#endif
785785
// TODO: provide a way to handle these exceptions
786+
System.Diagnostics.Debug.WriteLine(e);
786787
}
787788
}
788789
}

projects/client/RabbitMQ.Client/src/client/impl/ExtensionMethods.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public static class ExtensionMethods
5454
/// <returns></returns>
5555
public static T RandomItem<T>(this IList<T> list)
5656
{
57-
System.Diagnostics.Debug.WriteLine("List: {0}", list);
5857
var n = list.Count;
5958
if (n == 0)
6059
{

projects/client/Unit/src/unit/TestConnectionRecovery.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public void TestBasicConnectionRecovery()
9696
Assert.IsTrue(Conn.IsOpen);
9797
}
9898

99+
[Test]
100+
public void TestBasicConnectionRecoveryWithHostnameList()
101+
{
102+
var c = CreateAutorecoveringConnection(new List<string>() { "127.0.0.1", "localhost" });
103+
Assert.IsTrue(c.IsOpen);
104+
CloseAndWaitForRecovery(c);
105+
Assert.IsTrue(c.IsOpen);
106+
}
107+
99108
[Test]
100109
public void TestBasicConnectionRecoveryOnBrokerRestart()
101110
{
@@ -851,6 +860,11 @@ protected AutorecoveringConnection CreateAutorecoveringConnection()
851860
return CreateAutorecoveringConnection(RECOVERY_INTERVAL);
852861
}
853862

863+
protected AutorecoveringConnection CreateAutorecoveringConnection(IList<string> hostnames)
864+
{
865+
return CreateAutorecoveringConnection(RECOVERY_INTERVAL, hostnames);
866+
}
867+
854868
protected AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interval)
855869
{
856870
var cf = new ConnectionFactory();
@@ -859,6 +873,14 @@ protected AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan inter
859873
return (AutorecoveringConnection)cf.CreateConnection();
860874
}
861875

876+
protected AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interval, IList<string> hostnames)
877+
{
878+
var cf = new ConnectionFactory();
879+
cf.AutomaticRecoveryEnabled = true;
880+
cf.NetworkRecoveryInterval = interval;
881+
return (AutorecoveringConnection)cf.CreateConnection(hostnames);
882+
}
883+
862884
protected AutorecoveringConnection CreateAutorecoveringConnectionWithTopologyRecoveryDisabled()
863885
{
864886
var cf = new ConnectionFactory();

0 commit comments

Comments
 (0)