activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1040297 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Transport/Failover/FailoverTransport.cs test/csharp/Transport/failover/FailoverTransportTest.cs
Date Mon, 29 Nov 2010 21:07:26 GMT
Author: tabish
Date: Mon Nov 29 21:07:26 2010
New Revision: 1040297

URL: http://svn.apache.org/viewvc?rev=1040297&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQNET-295

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs?rev=1040297&r1=1040296&r2=1040297&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
Mon Nov 29 21:07:26 2010
@@ -63,7 +63,8 @@ namespace Apache.NMS.ActiveMQ.Transport.
 		private bool useExponentialBackOff = true;
 		private bool randomize = true;
 		private bool initialized;
-		private int maxReconnectAttempts;
+        private int maxReconnectAttempts;
+        private int startupMaxReconnectAttempts;
 		private int connectFailures;
 		private int reconnectDelay = 10;
 		private int asyncTimeout = 45000;
@@ -231,6 +232,12 @@ namespace Apache.NMS.ActiveMQ.Transport.
 			set { maxReconnectAttempts = value; }
 		}
 
+        public int StartupMaxReconnectAttempts
+        {
+            get { return startupMaxReconnectAttempts; }
+            set { startupMaxReconnectAttempts = value; }
+        }
+
 		public bool Randomize
 		{
 			get { return randomize; }
@@ -1034,7 +1041,17 @@ namespace Apache.NMS.ActiveMQ.Transport.
 						}
 					}
 
-					if(MaxReconnectAttempts > 0 && ++connectFailures >= MaxReconnectAttempts)
+                    int reconnectAttempts = 0;
+                    if( firstConnection ) {
+                        if( StartupMaxReconnectAttempts != 0 ) {
+                            reconnectAttempts = StartupMaxReconnectAttempts;
+                        }
+                    }
+                    if( reconnectAttempts == 0 ) {
+                        reconnectAttempts = MaxReconnectAttempts;
+                    }
+        
+					if(reconnectAttempts > 0 && ++connectFailures >= reconnectAttempts)
 					{
 						Tracer.ErrorFormat("Failed to connect to transport after {0} attempt(s)", connectFailures);
 						connectionFailure = Failure;

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs?rev=1040297&r1=1040296&r2=1040297&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs
Mon Nov 29 21:07:26 2010
@@ -160,6 +160,32 @@ namespace Apache.NMS.ActiveMQ.Test
 			}
 		}
 
+        [Test]
+        public void FailoverTransportCreateFailOnCreateTest2()
+        {
+            Uri uri = new Uri("failover:(mock://localhost:61616?transport.failOnCreate=true)?"
+
+                              "transport.useExponentialBackOff=false&transport.startupMaxReconnectAttempts=3&transport.initialReconnectDelay=100");
+            FailoverTransportFactory factory = new FailoverTransportFactory();
+
+            using(ITransport transport = factory.CreateTransport(uri))
+            {
+                Assert.IsNotNull(transport);
+                transport.Command = OnCommand;
+                transport.Exception = OnException;
+
+                FailoverTransport failover = transport.Narrow(typeof(FailoverTransport))
as FailoverTransport;
+                Assert.IsNotNull(failover);
+                Assert.IsFalse(failover.UseExponentialBackOff);
+                Assert.AreEqual(3, failover.StartupMaxReconnectAttempts);
+                Assert.AreEqual(100, failover.InitialReconnectDelay);
+
+                transport.Start();
+                Thread.Sleep(2000);
+                Assert.IsNotEmpty(this.exceptions);
+                Assert.IsFalse(failover.IsConnected);
+            }
+        }
+
 		[Test]
 		public void FailoverTransportFailOnSendMessageTest()
 		{



Mime
View raw message