activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r781196 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Transport/Tcp/TcpTransportFactory.cs test/csharp/NMSConnectionFactoryTest.cs
Date Tue, 02 Jun 2009 22:38:57 GMT
Author: jgomes
Date: Tue Jun  2 22:38:57 2009
New Revision: 781196

URL: http://svn.apache.org/viewvc?rev=781196&view=rev
Log:
Added tests for non-existant broker host machines.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs?rev=781196&r1=781195&r2=781196&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
Tue Jun  2 22:38:57 2009
@@ -271,56 +271,63 @@
 			Socket socket = null;
 			IPAddress ipaddress;
 
-			if(TryParseIPAddress(host, out ipaddress))
+			try
 			{
-				socket = ConnectSocket(ipaddress, port);
-			}
-			else
-			{
-				// Looping through the AddressList allows different type of connections to be tried
-				// (IPv6, IPv4 and whatever else may be available).
-				IPHostEntry hostEntry = GetIPHostEntry(host);
-
-				if(null != hostEntry)
+				if(TryParseIPAddress(host, out ipaddress))
 				{
-					// Prefer IPv6 first.
-					ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetworkV6);
 					socket = ConnectSocket(ipaddress, port);
-					if(null == socket)
+				}
+				else
+				{
+					// Looping through the AddressList allows different type of connections to be tried
+					// (IPv6, IPv4 and whatever else may be available).
+					IPHostEntry hostEntry = GetIPHostEntry(host);
+
+					if(null != hostEntry)
 					{
-						// Try IPv4 next.
-						ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetwork);
+						// Prefer IPv6 first.
+						ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetworkV6);
 						socket = ConnectSocket(ipaddress, port);
 						if(null == socket)
 						{
-							// Try whatever else there is.
-							foreach(IPAddress address in hostEntry.AddressList)
+							// Try IPv4 next.
+							ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetwork);
+							socket = ConnectSocket(ipaddress, port);
+							if(null == socket)
 							{
-								if(AddressFamily.InterNetworkV6 == address.AddressFamily
-									|| AddressFamily.InterNetwork == address.AddressFamily)
+								// Try whatever else there is.
+								foreach(IPAddress address in hostEntry.AddressList)
 								{
-									// Already tried these protocols.
-									continue;
-								}
-
-								socket = ConnectSocket(address, port);
-								if(null != socket)
-								{
-									ipaddress = address;
-									break;
+									if(AddressFamily.InterNetworkV6 == address.AddressFamily
+										|| AddressFamily.InterNetwork == address.AddressFamily)
+									{
+										// Already tried these protocols.
+										continue;
+									}
+
+									socket = ConnectSocket(address, port);
+									if(null != socket)
+									{
+										ipaddress = address;
+										break;
+									}
 								}
 							}
 						}
 					}
 				}
-			}
 
-			if(null == socket)
+				if(null == socket)
+				{
+					throw new SocketException();
+				}
+			}
+			catch(Exception ex)
 			{
-				throw new SocketException();
+				throw new NMSConnectionException(String.Format("Error connecting to {0}:{1}.", host,
port), ex);
 			}
 
-			Tracer.DebugFormat("Connected to {0}:{1} using {0} protocol.", host, port, ipaddress.AddressFamily.ToString());
+			Tracer.DebugFormat("Connected to {0}:{1} using {2} protocol.", host, port, ipaddress.AddressFamily.ToString());
 			return socket;
 		}
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs?rev=781196&r1=781195&r2=781196&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
Tue Jun  2 22:38:57 2009
@@ -16,9 +16,10 @@
  */
 
 using System;
+using System.Net.Sockets;
+using Apache.NMS.Test;
 using NUnit.Framework;
 using NUnit.Framework.Extensions;
-using Apache.NMS.Test;
 
 namespace Apache.NMS.ActiveMQ.Test
 {
@@ -30,9 +31,17 @@
 		[Row("activemq:tcp://${activemqhost}:61616")]
 		[Row("activemq:tcp://${activemqhost}:61616?connection.asyncclose=false")]
 		[Row("activemq:failover:tcp://${activemqhost}:61616")]
+		[Row("activemq:failover:(tcp://${activemqhost}:61616)")]
 		[Row("activemq:failover:(tcp://${activemqhost}:61616,tcp://${activemqhost}:61616)")]
 		// ?? [Row("activemq:discovery://${activemqhost}:6155")]
 
+		[Row("tcp://InvalidHost:61616", ExpectedException = typeof(NMSConnectionException))]
+		[Row("activemq:tcp://InvalidHost:61616", ExpectedException = typeof(NMSConnectionException))]
+		[Row("activemq:tcp://InvalidHost:61616?connection.asyncclose=false", ExpectedException
= typeof(NMSConnectionException))]
+		[Row("activemq:failover:tcp://InvalidHost:61616", ExpectedException = typeof(NMSConnectionException))]
+		[Row("activemq:failover:(tcp://InvalidHost:61616)", ExpectedException = typeof(NMSConnectionException))]
+		[Row("activemq:failover:(tcp://InvalidHost:61616,tcp://InvalidHost:61616)", ExpectedException
= typeof(NMSConnectionException))]
+
 		[Row("tcp://${activemqhost}:61616?connection.InvalidParameter=true", ExpectedException
= typeof(NMSException))]
 		[Row("activemq:tcp://${activemqhost}:61616?connection.InvalidParameter=true", ExpectedException
= typeof(NMSException))]
 		[Row("activemq:failover:tcp://${activemqhost}:61616?connection.InvalidParameter=true",
ExpectedException = typeof(NMSException))]



Mime
View raw message