You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/03/10 21:16:33 UTC

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

Author: tabish
Date: Wed Mar 10 20:16:32 2010
New Revision: 921548

URL: http://svn.apache.org/viewvc?rev=921548&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQNET-242

options added "timeout" causes oneway to throw an IOException is timeout is set and time to send exceeds timeout.

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=921548&r1=921547&r2=921548&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 Wed Mar 10 20:16:32 2010
@@ -55,6 +55,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
         private TaskRunner reconnectTask = null;
         private bool started;
 
+        private int timeout = -1;
         private int initialReconnectDelay = 10;
         private int maxReconnectDelay = 1000 * 30;
         private int backOffMultiplier = 2;
@@ -72,8 +73,8 @@ namespace Apache.NMS.ActiveMQ.Transport.
         private List<BackupTransport> backups = new List<BackupTransport>();
         private int backupPoolSize = 1;
         private bool trackMessages = false;
-        private int maxCacheSize = 256;
         private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
+        private int maxCacheSize = 256;
         private volatile Exception failure;
         private readonly object mutex = new object();
 
@@ -180,12 +181,18 @@ namespace Apache.NMS.ActiveMQ.Transport.
             }
         }
 
+        public int Timeout
+        {
+            get { return this.timeout; }
+            set { this.timeout = value; }
+        }
+
         public TimeSpan RequestTimeout
         {
             get { return requestTimeout; }
             set { requestTimeout = value; }
         }
-
+        
         public int InitialReconnectDelay
         {
             get { return initialReconnectDelay; }
@@ -548,9 +555,20 @@ namespace Apache.NMS.ActiveMQ.Transport.
                     {
                         // Wait for transport to be connected.
                         ITransport transport = ConnectedTransport;
+                        DateTime start = DateTime.Now;                            
+                        bool timedout = false;
                         while(transport == null && !disposed && connectionFailure == null)
                         {
                             Tracer.Info("Waiting for transport to reconnect.");
+
+                            int elapsed = (int)(DateTime.Now - start).TotalMilliseconds;
+                            if( this.timeout > 0 && elapsed > timeout )
+                            {
+                                timedout = true;
+                                Tracer.DebugFormat("FailoverTransport.oneway - timed out after {0} mills", elapsed );
+                                break;
+                            }
+                            
                             // Release so that the reconnect task can run
                             try
                             {
@@ -576,6 +594,10 @@ namespace Apache.NMS.ActiveMQ.Transport.
                             {
                                 error = connectionFailure;
                             }
+                            else if(timedout)
+                            {
+                                error = new IOException("Failover oneway timed out after "+ timeout +" milliseconds.");
+                            }
                             else
                             {
                                 error = new IOException("Unexpected 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=921548&r1=921547&r2=921548&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 Wed Mar 10 20:16:32 2010
@@ -334,6 +334,42 @@ namespace Apache.NMS.ActiveMQ.Test
         }
 
         [Test]
+        public void FailoverTransportSendOnewayTimeoutTest()
+        {
+            Uri uri = new Uri(
+                "failover:(mock://localhost:61616?failOnCreate=true)?timeout=1000");
+
+            FailoverTransportFactory factory = new FailoverTransportFactory();
+
+            ITransport transport = factory.CreateTransport( uri );
+            Assert.IsNotNull( transport );
+            transport.Command = new CommandHandler(OnCommand);
+            transport.Exception = new ExceptionHandler(OnException);
+
+            FailoverTransport failover = (FailoverTransport) transport.Narrow(typeof(FailoverTransport));
+            Assert.IsNotNull(failover);
+            Assert.AreEqual(1000, failover.Timeout);
+
+            transport.Start();
+
+            Thread.Sleep(1000);
+
+            ActiveMQMessage message = new ActiveMQMessage();
+            
+            try
+            {
+                transport.Oneway(message);
+                Assert.Fail("Should have thrown an IOException after timeout.");
+            }
+            catch
+            {
+            }
+
+            transport.Stop();
+            transport.Dispose();
+        }
+        
+        [Test]
         public void FailoverTransportSendRequestFailTest()
         {
             Uri uri = new Uri(