Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 84788 invoked from network); 19 Aug 2009 20:25:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Aug 2009 20:25:07 -0000 Received: (qmail 66946 invoked by uid 500); 19 Aug 2009 20:25:26 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 66908 invoked by uid 500); 19 Aug 2009 20:25:26 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 66899 invoked by uid 99); 19 Aug 2009 20:25:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2009 20:25:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2009 20:25:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8425623888AD; Wed, 19 Aug 2009 20:25:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r805963 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Transport/ main/csharp/Transport/Failover/ main/csharp/Transport/Mock/ main/csharp/Transport/Tcp/ test/csharp/Transport/Mock/ test/csharp/Transport/failover/ Date: Wed, 19 Aug 2009 20:25:01 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090819202501.8425623888AD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Wed Aug 19 20:25:00 2009 New Revision: 805963 URL: http://svn.apache.org/viewvc?rev=805963&view=rev Log: http://issues.apache.org/activemq/browse/AMQNET-180 Updates to the transport layer to improve the ability to test the code, also some minor cleanup. Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs (with props) Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.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=805963&r1=805962&r2=805963&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 Aug 19 20:25:00 2009 @@ -257,8 +257,11 @@ { reconnectMutex.ReleaseMutex(); } - - this.Interrupted( transport ); + + if( this.Interrupted != null ) + { + this.Interrupted( transport ); + } } } @@ -736,19 +739,32 @@ return ConnectedTransportURI == null ? "unconnected" : ConnectedTransportURI.ToString(); } - public String RemoteAddress + public Uri RemoteAddress { get { - FailoverTransport transport = ConnectedTransport as FailoverTransport; - if(transport != null) + if(ConnectedTransport != null) { - return transport.RemoteAddress; + return ConnectedTransport.RemoteAddress; } return null; } } + public Object Narrow(Type type) + { + if(this.GetType().Equals(type)) + { + return this; + } + else if(ConnectedTransport != null) + { + return ConnectedTransport.Narrow(type); + } + + return null; + } + public bool IsFaultTolerant { get { return true; } @@ -801,8 +817,11 @@ ConnectedTransport = t; connectFailures = 0; connected = true; - this.Resumed( t ); - Tracer.InfoFormat("Successfully reconnected to backup {0}", uri.ToString()); + if( this.Resumed != null ) + { + this.Resumed( t ); + } + Tracer.InfoFormat("Successfully reconnected to backup {0}", uri.ToString()); return false; } catch(Exception e) @@ -837,7 +856,11 @@ restoreTransport(t); } - this.Resumed( t ); + if( this.Resumed != null ) + { + this.Resumed( t ); + } + Tracer.Debug("Connection established"); ReconnectDelay = InitialReconnectDelay; ConnectedTransportURI = uri; @@ -881,7 +904,6 @@ if(!disposed) { - Tracer.DebugFormat("Waiting {0}ms before attempting connection.", ReconnectDelay); try { @@ -912,7 +934,6 @@ return !disposed; } - private bool buildBackups() { try @@ -973,7 +994,7 @@ get { return disposed; } } - public bool Connected + public bool IsConnected { get { return connected; } } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs?rev=805963&r1=805962&r2=805963&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs Wed Aug 19 20:25:00 2009 @@ -26,23 +26,87 @@ public delegate void ResumedHandler(ITransport sender); /// - /// Represents the logical networking transport layer. + /// Represents the logical networking transport layer. Transports implment the low + /// level protocol specific portion of the Communication between the Client and a Broker + /// such as TCP, UDP, etc. Transports make use of WireFormat objects to handle translateing + /// the cononical OpenWire Commands used in this client into binary wire level packets that + /// can be sent to the Broker or Service that the Transport connects to. /// public interface ITransport : IStartable, IDisposable, IStoppable { + /// + /// Sends a Command object on the Wire but does not wait for any response from the + /// receiver before returning. + /// + /// + /// A + /// void Oneway(Command command); + /// + /// Sends a Command object which requires a response from the Broker but does not + /// wait for the response, instead a FutureResponse object is returned that the + /// caller can use to wait on the Broker's response. + /// + /// + /// A + /// + /// + /// A + /// FutureResponse AsyncRequest(Command command); - TimeSpan RequestTimeout - { - get; - set; - } - + /// + /// Sends a Command to the Broker and waits for a Response to that Command before + /// returning, this version waits indefinitely for a response. + /// + /// + /// A + /// + /// + /// A + /// Response Request(Command command); + + /// + /// Sends a Command to the Broker and waits for the given TimeSpan to expire for a + /// response before returning. + /// + /// + /// A + /// + /// + /// A + /// + /// + /// A + /// Response Request(Command command, TimeSpan timeout); + /// + /// Allows a caller to find a specific type of Transport in the Chain of + /// Transports that is created. This allows a caller to find a specific + /// object in the Transport chain and set or get properties on that specific + /// instance. If the requested type isn't in the chain than Null is returned. + /// + /// + /// A + /// + /// + /// A + /// + Object Narrow(Type type); + + /// + /// The time that the Transport waits before considering a request to have + /// failed and throwing an exception. + /// + TimeSpan RequestTimeout + { + get; + set; + } + CommandHandler Command { get; @@ -66,11 +130,42 @@ get; set; } - + + /// + /// Indicates if this Transport has already been disposed and can no longer + /// be used. + /// bool IsDisposed { get; } + + /// + /// Indicates if this Transport is Fault Tolerant or not. A fault Tolerant + /// Transport handles low level connection errors internally allowing a client + /// to remain unaware of wire level disconnection and reconnection details. + /// + bool IsFaultTolerant + { + get; + } + + /// + /// Indiciates if the Transport is current Connected to is assigned URI. + /// + bool IsConnected + { + get; + } + + /// + /// The Remote Address that this transport is currently connected to. + /// + Uri RemoteAddress + { + get; + } + } } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs?rev=805963&r1=805962&r2=805963&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs Wed Aug 19 20:25:00 2009 @@ -91,11 +91,13 @@ if( this.parent.FailOnReceiveMessage && this.parent.NumReceivedMessages > this.parent.NumReceivedMessagesBeforeFail ) { + Tracer.Debug("MockTransport Async Task: Performing configured receive failure." ); this.parent.Exception(this.parent, new IOException( "Failed to Receive Message.")); } } // Send all the responses. + Tracer.Debug("MockTransport Async Task: Simulate receive of Command: " + command.ToString() ); this.parent.Command(this.parent, command); return parent.receiveQueue.Count != 0; @@ -123,6 +125,8 @@ public Response Request(Command command, TimeSpan timeout) { + Tracer.Debug("MockTransport sending Request Command: " + command.ToString() ); + if( command.IsMessage ) { this.numSentMessages++; @@ -142,10 +146,13 @@ public void Oneway(Command command) { + Tracer.Debug("MockTransport sending oneway Command: " + command.ToString() ); + if( command.IsMessage ) { this.numSentMessages++; if( this.failOnSendMessage && this.numSentMessages > this.numSentMessagesBeforeFail ) { + Tracer.Debug("MockTransport Oneway send, failing as per configuration." ); throw new IOException( "Failed to Send Message."); } } @@ -166,7 +173,10 @@ this.asyncResponseTask.wakeup(); // Send the Command to the Outgoing Command Snoop Hook. - this.OutgoingCommand(this, command); + if( this.OutgoingCommand != null ) { + Tracer.Debug("MockTransport Oneway, Notifying Outgoing linstener." ); + this.OutgoingCommand(this, command); + } } public FutureResponse AsyncRequest(Command command) @@ -229,6 +239,16 @@ this.asyncResponseTask.wakeup(); } + + public Object Narrow(Type type) + { + if( this.GetType().Equals(type) ) + { + return this; + } + + return null; + } #region Property Accessors @@ -313,7 +333,22 @@ get { return numReceivedMessages; } set { numReceivedMessages = value; } } - + + public bool IsFaultTolerant + { + get{ return false; } + } + + public bool IsConnected + { + get{ return true; } + } + + public Uri RemoteAddress + { + get{ return null; } + } + #endregion } } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs?rev=805963&r1=805962&r2=805963&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs Wed Aug 19 20:25:00 2009 @@ -41,6 +41,7 @@ private AtomicBoolean closed = new AtomicBoolean(false); private volatile bool seenShutdown; private TimeSpan maxWait = TimeSpan.FromMilliseconds(Timeout.Infinite); + private Uri connectedUri; private CommandHandler commandHandler; private ExceptionHandler exceptionHandler; @@ -48,8 +49,9 @@ private ResumedHandler resumedHandler; private TimeSpan MAX_THREAD_WAIT = TimeSpan.FromMilliseconds(30000); - public TcpTransport(Socket socket, IWireFormat wireformat) + public TcpTransport(Uri uri, Socket socket, IWireFormat wireformat) { + this.connectedUri = uri; this.socket = socket; this.wireformat = wireformat; } @@ -377,6 +379,32 @@ get { return wireformat; } set { wireformat = value; } } + + public bool IsFaultTolerant + { + get{ return false; } + } + + public bool IsConnected + { + get{ return socket.Connected; } + } + + public Uri RemoteAddress + { + get{ return connectedUri; } + } + + public Object Narrow(Type type) + { + if( this.GetType().Equals(type) ) + { + return this; + } + + return null; + } + } } 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=805963&r1=805962&r2=805963&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 Wed Aug 19 20:25:00 2009 @@ -121,7 +121,7 @@ #endif IWireFormat wireformat = CreateWireFormat(map); - ITransport transport = new TcpTransport(socket, wireformat); + ITransport transport = new TcpTransport(location, socket, wireformat); wireformat.Transport = transport; Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs?rev=805963&r1=805962&r2=805963&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs Wed Aug 19 20:25:00 2009 @@ -182,6 +182,32 @@ public virtual void Stop() { } - } + + public Object Narrow(Type type) + { + if( this.GetType().Equals( type ) ) { + return this; + } else if( this.next != null ) { + return this.next.Narrow( type ); + } + + return null; + } + + public bool IsFaultTolerant + { + get{ return next.IsFaultTolerant; } + } + + public bool IsConnected + { + get{ return next.IsConnected; } + } + + public Uri RemoteAddress + { + get{ return next.RemoteAddress; } + } + } } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs?rev=805963&r1=805962&r2=805963&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs Wed Aug 19 20:25:00 2009 @@ -38,6 +38,13 @@ ITransport transport = factory.CreateTransport(location); Assert.IsNotNull(transport); + + Assert.IsInstanceOfType(typeof(MockTransport), transport.Narrow(typeof(MockTransport))); + + MockTransport mock = (MockTransport) transport.Narrow(typeof(MockTransport)); + + Assert.IsTrue( mock.IsConnected ); + Assert.IsFalse( mock.IsFaultTolerant ); } [Test] Added: 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=805963&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs Wed Aug 19 20:25:00 2009 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Threading; +using System.Collections; +using System.Collections.Generic; +using Apache.NMS; +using Apache.NMS.ActiveMQ.Transport; +using Apache.NMS.ActiveMQ.Transport.Mock; +using Apache.NMS.ActiveMQ.Transport.Failover; +using Apache.NMS.ActiveMQ.Commands; +using NUnit.Framework; +using NUnit.Framework.Extensions; + +namespace Apache.NMS.ActiveMQ.Test +{ + internal class ConsoleTracer : ITrace + { + public bool IsDebugEnabled { get { return true; } } + public bool IsInfoEnabled { get { return true; } } + public bool IsWarnEnabled { get { return true; } } + public bool IsErrorEnabled { get { return true; } } + public bool IsFatalEnabled { get { return true; } } + public void Debug(string message) { Console.WriteLine("DEBUG:" + message); } + public void Info(string message) { Console.WriteLine("INFO:" + message); } + public void Warn(string message) { Console.WriteLine("WARN:" + message); } + public void Error(string message) { Console.WriteLine("ERROR:" + message); } + public void Fatal(string message) { Console.WriteLine("FATAL:" + message); } + } + + [TestFixture] + public class FailoverTransportTest + { + private List received = new List(); + private List exceptions = new List(); + + public void OnException(ITransport transport, Exception exception) + { + exceptions.Add( exception ); + } + + public void OnCommand(ITransport transport, Command command) + { + received.Add( command ); + } + + [Test] + public void FailoverTransportCreateTest() + { + Uri uri = new Uri("failover:(mock://localhost:61616)?randomize=false"); + Tracer.Trace = new ConsoleTracer(); + + 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.IsFalse(failover.Randomize); + + transport.Start(); + + Thread.Sleep(1000); + Assert.IsTrue(failover.IsConnected); + + transport.Stop(); + + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/failover/FailoverTransportTest.cs ------------------------------------------------------------------------------ svn:eol-style = native