Skip to content

Commit c589855

Browse files
Merge pull request #188 from rabbitmq/rabbtimq-dotnet-client-186
revert changes introduced for issue #157
2 parents b5333cf + 4f567d6 commit c589855

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TestResult.xml
1818
.paket/paket.exe
1919
/NuGet
2020
rabbit-mock.snk
21+
test.sh
2122

2223
#################
2324
## Visual Studio

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,7 @@ public IConnection CreateConnection(IList<string> hostnames, String clientProvid
420420
{
421421
IProtocol protocol = Protocols.DefaultProtocol;
422422
var selectedHost = this.HostnameSelector.NextFrom(hostnames);
423-
var endPoint = AmqpTcpEndpoint.Parse(selectedHost);
424-
conn = protocol.CreateConnection(this, false, CreateFrameHandler(endPoint), clientProvidedName);
423+
conn = protocol.CreateConnection(this, false, CreateFrameHandlerForHostname(selectedHost), clientProvidedName);
425424
}
426425
}
427426
catch (Exception e)
@@ -447,9 +446,7 @@ public IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint)
447446

448447
public IFrameHandler CreateFrameHandlerForHostname(string hostname)
449448
{
450-
var ep = AmqpTcpEndpoint.Parse(hostname);
451-
ep.Ssl = this.Endpoint.Ssl;
452-
return CreateFrameHandler(ep);
449+
return CreateFrameHandler(this.Endpoint.CloneWithHostname(hostname));
453450
}
454451

455452

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ public void Init(IList<string> hostnames)
562562
{
563563
try
564564
{
565-
var endPoint = CloneEndpointWithHostname(h);
566-
fh = m_factory.CreateFrameHandler(endPoint);
565+
fh = m_factory.CreateFrameHandler(m_factory.Endpoint.CloneWithHostname(h));
567566
reachableHostname = h;
568567
}
569568
catch (Exception caught)
@@ -798,8 +797,7 @@ protected void RecoverConnectionDelegate()
798797
try
799798
{
800799
var nextHostname = m_factory.HostnameSelector.NextFrom(this.hostnames);
801-
var endPoint = CloneEndpointWithHostname(nextHostname);
802-
var fh = m_factory.CreateFrameHandler(endPoint);
800+
var fh = m_factory.CreateFrameHandler(m_factory.Endpoint.CloneWithHostname(nextHostname));
803801
m_delegate = new Connection(m_factory, false, fh, this.ClientProvidedName);
804802
recovering = false;
805803
}
@@ -1006,12 +1004,5 @@ protected bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args)
10061004
// connectivity loss or abrupt shutdown
10071005
args.Initiator == ShutdownInitiator.Library);
10081006
}
1009-
1010-
private AmqpTcpEndpoint CloneEndpointWithHostname(string hostname)
1011-
{
1012-
var ate = AmqpTcpEndpoint.Parse(hostname);
1013-
ate.Ssl = m_factory.Endpoint.Ssl;
1014-
return ate;
1015-
}
10161007
}
10171008
}

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
using System;
4242
using NUnit.Framework;
43+
using RabbitMQ.Client.Exceptions;
4344

4445
namespace RabbitMQ.Client.Unit
4546
{
@@ -70,19 +71,34 @@ public void TestProperties()
7071
}
7172

7273
[Test]
73-
public void TestCreateConnectionParsesHostNameWithPort()
74+
[ExpectedException(typeof(BrokerUnreachableException))]
75+
public void TestCreateConnectionUsesSpecifiedPort()
7476
{
7577
var cf = new ConnectionFactory();
7678
cf.AutomaticRecoveryEnabled = true;
77-
cf.HostName = "not_localhost";
79+
cf.HostName = "localhost";
7880
cf.Port = 1234;
79-
var conn = cf.CreateConnection(new System.Collections.Generic.List<string> { "localhost:5672" }, "oregano");
80-
conn.Close();
81-
conn.Dispose();
82-
Assert.AreEqual("not_localhost", cf.HostName);
83-
Assert.AreEqual(1234, cf.Port);
84-
Assert.AreEqual("localhost", conn.Endpoint.HostName);
85-
Assert.AreEqual(5672, conn.Endpoint.Port);
81+
using(var conn = cf.CreateConnection());
82+
}
83+
84+
[Test]
85+
[ExpectedException(typeof(BrokerUnreachableException))]
86+
public void TestCreateConnectionWithClientProvidedNameUsesSpecifiedPort()
87+
{
88+
var cf = new ConnectionFactory();
89+
cf.AutomaticRecoveryEnabled = true;
90+
cf.HostName = "localhost";
91+
cf.Port = 1234;
92+
using(var conn = cf.CreateConnection("some_name"));
93+
}
94+
95+
[Test]
96+
public void TestCreateConnectionUsesDefaultPort()
97+
{
98+
var cf = new ConnectionFactory();
99+
cf.AutomaticRecoveryEnabled = true;
100+
cf.HostName = "localhost";
101+
using(var conn = cf.CreateConnection());
86102
}
87103

88104
[Test]
@@ -91,12 +107,11 @@ public void TestCreateConnectionWithoutAutoRecoverySelectsAHostFromTheList()
91107
var cf = new ConnectionFactory();
92108
cf.AutomaticRecoveryEnabled = false;
93109
cf.HostName = "not_localhost";
94-
cf.Port = 1234;
95110
var conn = cf.CreateConnection(new System.Collections.Generic.List<string> { "localhost" }, "oregano");
96111
conn.Close();
97112
conn.Dispose();
98113
Assert.AreEqual("not_localhost", cf.HostName);
99114
Assert.AreEqual("localhost", conn.Endpoint.HostName);
100-
}
115+
}
101116
}
102117
}

0 commit comments

Comments
 (0)