activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r805544 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Transport/Mock/ test/csharp/Transport/ test/csharp/Transport/Mock/
Date Tue, 18 Aug 2009 19:23:56 GMT
Author: tabish
Date: Tue Aug 18 19:23:56 2009
New Revision: 805544

URL: http://svn.apache.org/viewvc?rev=805544&view=rev
Log:
Add the initial implementation of the MockTransport

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs
  (with props)

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs?rev=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.Collections;
+using System.Collections.Generic;
+using Apache.NMS.ActiveMQ.Commands;
+
+namespace Apache.NMS.ActiveMQ.Transport.Mock
+{    
+    /// <summary>
+    /// Defines an Interface for a Command Response Builder used by the MockTransport
+    /// to answer Commands sent via the Request and AsnycRequest methods.
+    /// </summary>
+    public interface IResponseBuilder
+    {
+        /// <summary>
+        /// Given a Command, check if it requires a response and return the
+        /// appropriate Response that the Broker would send for this Command
+        /// </summary>
+        Response BuildResponse(Command command);
+
+        /// <summary>
+        /// When called the ResponseBuilder must construct all the Responses or 
+        /// Asynchronous commands that would be sent to this client by the Broker 
+        /// upon receipt of the passed command.
+        /// </summary>
+        List<Command> BuildIncomingCommands(Command command);
+            
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/IResponseBuilder.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,319 @@
+/*
+ * 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.Collections;
+using System.Collections.Generic;
+using System.Threading;
+using Apache.NMS.ActiveMQ.Commands;
+using Apache.NMS.ActiveMQ.Transport;
+using Apache.NMS.ActiveMQ.Threads;
+using Apache.NMS.Util;
+
+#if NETCF
+using ThreadInterruptedException = System.Exception;
+#endif
+
+namespace Apache.NMS.ActiveMQ.Transport.Mock
+{	
+	/// <summary>
+	/// Transport used for testing, mimics the behaviour of a normal Transport and allows
+	/// messages to be sent and received 
+	/// </summary>
+	public class MockTransport : ITransport
+	{
+        #region Properties
+        
+        private bool failOnSendMessage = false;
+        private int numSentMessagesBeforeFail = -1;
+        private int numSentMessages = 0;
+        private bool failOnReceiveMessage = false;
+        private int numReceivedMessagesBeforeFail = 0;
+        private int numReceivedMessages = 0;
+        private int nextCommandId = 0;
+        private CommandHandler commandHandler;
+        private CommandHandler outgoingCommandHandler;
+        private ExceptionHandler exceptionHandler;
+        private InterruptedHandler interruptedHandler;
+        private ResumedHandler resumedHandler;
+        private bool disposed = false;
+        private bool started = false;
+        private TimeSpan requestTimeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
+        private TaskRunner asyncResponseTask;
+        private Queue<Command> receiveQueue = new Queue<Command>();
+        private IResponseBuilder responseBuilder = new OpenWireResponseBuilder();
+
+        #endregion   
+        
+        #region Async Response Task
+        
+        private class AsyncResponseTask : Task
+        {
+            private MockTransport parent;
+            
+            public AsyncResponseTask( MockTransport parent )
+            {
+                this.parent = parent;
+            }
+            
+            public bool iterate()
+            {   
+                Command command = null;
+                
+                lock(this.parent.receiveQueue)
+                {
+                    if( this.parent.receiveQueue.Count == 0 )
+                    {
+                        return false;
+                    }
+                    
+                    // Grab everything that's currently in the Queue, 
+                    command = this.parent.receiveQueue.Dequeue();
+                }
+                
+                if( command.IsMessage ) {
+                    this.parent.NumReceivedMessages++;
+
+                    if( this.parent.FailOnReceiveMessage && 
+                        this.parent.NumReceivedMessages > this.parent.NumReceivedMessagesBeforeFail
) {
+                        
+                        this.parent.Exception(this.parent, new IOException( "Failed to Receive
Message."));
+                    }
+                }                
+                             
+                // Send all the responses.
+                this.parent.Command(this.parent, command);
+                
+                return parent.receiveQueue.Count != 0;
+            }
+        }
+        
+        #endregion        
+
+        public MockTransport()
+        {
+            Tracer.Debug("Creating Async Response task");
+            asyncResponseTask = DefaultThreadPools.DefaultTaskRunnerFactory.CreateTaskRunner(new
AsyncResponseTask(this),
+                                "ActiveMQ MockTransport Worker: " + this.GetHashCode().ToString());
           
+        }
+        
+        ~MockTransport()
+        {
+            Dispose(false);
+        }
+        
+        public Response Request(Command command)
+        {
+            return this.Request(command, TimeSpan.FromMilliseconds(Timeout.Infinite));
+        }
+
+        public Response Request(Command command, TimeSpan timeout)
+        {
+            if( command.IsMessage ) {
+                this.numSentMessages++;
+    
+                if( this.failOnSendMessage && this.numSentMessages > this.numSentMessagesBeforeFail
) {
+                    throw new IOException( "Failed to Send Message.");
+                }
+            }
+
+            // Notify external Client of command that we "sent"
+            this.OutgoingCommand(this, command);            
+
+            command.CommandId = Interlocked.Increment(ref this.nextCommandId);
+            command.ResponseRequired = true;
+            
+            return this.responseBuilder.BuildResponse(command);
+        }
+        
+        public void Oneway(Command command)
+        {
+            if( command.IsMessage ) {
+                this.numSentMessages++;
+    
+                if( this.failOnSendMessage && this.numSentMessages > this.numSentMessagesBeforeFail
) {
+                    throw new IOException( "Failed to Send Message.");
+                }
+            }
+    
+            // Process and send any new Commands back.
+
+            // Let the Response Builder give us the Commands to send to the Client App.
+            List<Command> results = this.responseBuilder.BuildIncomingCommands(command);
+            
+            lock(this.receiveQueue)
+            {
+                foreach( Command result in results )
+                {
+                    this.receiveQueue.Enqueue(result);
+                }
+            }
+            
+            this.asyncResponseTask.wakeup();
+            
+            // Send the Command to the Outgoing Command Snoop Hook.
+            this.OutgoingCommand(this, command);            
+        }
+        
+        public FutureResponse AsyncRequest(Command command)
+        {
+            FutureResponse response = new FutureResponse();
+            
+            // Delegate to the Request method, it doesn't block.
+            response.Response = this.Request(command);
+            
+            return response;
+        }
+        
+        public void Start()
+        {
+            if(commandHandler == null)
+            {
+                throw new InvalidOperationException("command cannot be null when Start is
called.");
+            }
+
+            if(exceptionHandler == null)
+            {
+                throw new InvalidOperationException("exception cannot be null when Start
is called.");
+            }
+
+            this.started = true;
+        }
+                
+        public void Stop()
+        {
+            this.started = false;
+        }
+        
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            this.started = false;
+            this.disposed = true;
+        }
+        
+        /// <summary>
+        /// Injects a Command into the Transports inbound message queue, the Commands in
the
+        /// inbound Queue are dispatched to the registered CommnadHandler instance for 
+        /// processing, this simulates receiving a message from an external source, e.g.
+        /// receiving a new message from the Broker.
+        /// </summary>
+        /// <param name="command">
+        /// A <see cref="Command"/>
+        /// </param>
+        public void InjectCommand(Command command)
+        {
+            lock(this.receiveQueue)
+            {
+                this.receiveQueue.Enqueue(command);
+            }
+            
+            this.asyncResponseTask.wakeup();
+        }
+        
+		#region Property Accessors
+		
+        public TimeSpan RequestTimeout
+        {
+            get{ return requestTimeout; }
+            set{ this.requestTimeout = value; }
+        }
+
+        public CommandHandler Command
+        {
+            get { return commandHandler; }
+            set { this.commandHandler = value; }
+        }
+
+        public CommandHandler OutgoingCommand
+        {
+            get { return outgoingCommandHandler; }
+            set { this.outgoingCommandHandler = value; }
+        }
+        
+        public ExceptionHandler Exception
+        {
+            get { return exceptionHandler; }
+            set { this.exceptionHandler = value; }
+        }
+
+        public InterruptedHandler Interrupted
+        {
+            get { return interruptedHandler; }
+            set { this.interruptedHandler = value; }
+        }
+        
+        public ResumedHandler Resumed
+        {
+            get { return resumedHandler; }
+            set { this.resumedHandler = value; }
+        }
+        
+        public bool IsDisposed
+        {
+            get{ return this.disposed; }
+        }
+        
+        public bool IsStarted
+        {
+            get{ return this.started; }
+        }
+                
+		public bool FailOnSendMessage
+		{
+			get{ return failOnSendMessage; }
+			set{ this.failOnSendMessage = value; }			
+		}
+		
+		public int NumSentMessagesBeforeFail
+		{
+			get { return numSentMessagesBeforeFail ; }
+			set { numSentMessagesBeforeFail = value; }
+		}
+		
+		public int NumSentMessages
+		{
+			get { return numSentMessages; }
+			set { numSentMessages = value; }
+		}
+		
+		public bool FailOnReceiveMessage
+		{
+			get { return failOnReceiveMessage; }
+			set { failOnReceiveMessage = value; }
+		}
+		
+		public int NumReceivedMessagesBeforeFail
+		{
+			get { return numReceivedMessagesBeforeFail; }
+			set { numReceivedMessagesBeforeFail = value; }			
+		}
+		
+		public int NumReceivedMessages
+		{
+			get { return numReceivedMessages; }
+			set { numReceivedMessages = value; }
+		}
+	
+        #endregion
+	}
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs?rev=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,127 @@
+/*
+ * 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.Collections.Generic;
+using System.Collections.Specialized;
+using Apache.NMS.Util;
+using Apache.NMS.ActiveMQ.Commands;
+using Apache.NMS.ActiveMQ.Transport;
+
+namespace Apache.NMS.ActiveMQ.Transport.Mock
+{
+	/// <summary>
+	/// Factory class to create the MockTransport when given on a URI as mock://XXX
+	/// </summary>
+	public class MockTransportFactory
+	{		
+		public MockTransportFactory()
+		{
+		}
+
+        #region Properties
+        
+        private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
+        public int RequestTimeout
+        {
+            get { return (int) requestTimeout.TotalMilliseconds; }
+            set { requestTimeout = TimeSpan.FromMilliseconds(value); }
+        }
+        
+        private bool useLogging = false;
+        public bool UseLogging
+        {
+            get { return useLogging; }
+            set { useLogging = value; }
+        }
+
+        private string wireFormat = "OpenWire";
+        public string WireFormat
+        {
+            get { return wireFormat; }
+            set { wireFormat = value; }
+        }
+        
+        private bool failOnReceiveMessage = false;
+        public bool FailOnReceiveMessage
+        {
+            get { return failOnReceiveMessage; }
+            set { failOnReceiveMessage = value; }
+        }
+
+        private int numReceivedMessagesBeforeFail = 0;
+        public int NumReceivedMessagesBeforeFail
+        {
+            get { return numReceivedMessagesBeforeFail; }
+            set { numReceivedMessagesBeforeFail = value; }           
+        }
+        
+        private bool failOnSendMessage = false;
+        public bool FailOnSendMessage
+        {
+            get{ return failOnSendMessage; }
+            set{ this.failOnSendMessage = value; }          
+        }
+        
+        private int numSentMessagesBeforeFail = 0;
+        public int NumSentMessagesBeforeFail
+        {
+            get { return numSentMessagesBeforeFail ; }
+            set { numSentMessagesBeforeFail = value; }
+        }
+        
+        #endregion
+        
+		public ITransport CreateTransport(Uri location) 
+		{
+			ITransport transport = CompositeConnect(location);
+
+			transport = new MutexTransport(transport);
+			transport = new ResponseCorrelator(transport);
+			transport.RequestTimeout = this.requestTimeout;
+
+			return transport;			
+		}
+		
+		public ITransport CompositeConnect(Uri location)
+		{
+			// Extract query parameters from broker Uri
+			StringDictionary map = URISupport.ParseQuery(location.Query);
+
+            // Set transport. properties on this (the factory)
+            URISupport.SetProperties(this, map, "transport.");
+         
+            Console.WriteLine( "Specified WireFormat is: " + this.wireFormat );
+            if(String.Compare(this.wireFormat, "stomp", true) != 0 &&
+               String.Compare(this.wireFormat, "openwire", true) != 0)
+            {
+                throw new IOException("Unsupported WireFormat Supplied for MockTransport");
+            }
+            
+            // Create the Mock Transport
+            MockTransport transport = new MockTransport();
+            
+            transport.FailOnReceiveMessage = this.FailOnReceiveMessage;
+            transport.NumReceivedMessagesBeforeFail = this.NumReceivedMessagesBeforeFail;
+            transport.FailOnSendMessage = this.FailOnSendMessage;
+            transport.NumSentMessagesBeforeFail = this.NumSentMessagesBeforeFail;
+
+            return transport;
+		}
+		
+	}
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs?rev=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.Collections;
+using System.Collections.Generic;
+using Apache.NMS.ActiveMQ.Commands;
+
+namespace Apache.NMS.ActiveMQ.Transport.Mock
+{    
+    /// <summary>
+    /// Builds responses using the internal Cononical OpenWire Commands format.
+    /// </summary>
+    public class OpenWireResponseBuilder : IResponseBuilder
+    {
+        public Response BuildResponse(Command command)
+        {
+            if( command.ResponseRequired ) 
+            {
+                // These Commands just require a response that matches their command IDs
+                Response response = new Response();
+                response.CorrelationId = command.CommandId;
+                return response;
+            }
+            
+            return null;
+        }
+
+        public List<Command> BuildIncomingCommands(Command command)
+        {
+            List<Command> commands = new List<Command>();
+            
+            // Delegate this to buildResponse
+            if( command.ResponseRequired ) 
+            {
+                commands.Add( this.BuildResponse( command ) );
+            }
+        
+            if( command.IsWireFormatInfo ) 
+            {
+                // Return a copy of the callers own requested WireFormatInfo
+                // so they get exactly the settings they asked for.
+                commands.Add( (Command) command.Clone() );
+            }
+            
+            return commands;
+        }              
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/OpenWireResponseBuilder.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,57 @@
+/*
+ * 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 Apache.NMS;
+using Apache.NMS.ActiveMQ.Transport;
+using Apache.NMS.ActiveMQ.Transport.Mock;
+using Apache.NMS.ActiveMQ.Commands;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+    [TestFixture]
+    public class MockTransportFactoryTest
+    {
+        [Test]
+        public void CreateMockTransportTest()
+        {
+            MockTransportFactory factory = new MockTransportFactory();
+            
+            Uri location = new Uri("mock://0.0.0.0:61616");
+            
+            ITransport transport = factory.CreateTransport(location);
+            
+            Assert.IsNotNull(transport);
+        }
+        
+        [Test]
+        public void CreateMockTransportWithParamsTest()
+        {
+            MockTransportFactory factory = new MockTransportFactory();
+            
+            Uri location = new Uri("mock://0.0.0.0:61616?transport.failOnSendMessage=true&transport.numSentMessagesBeforeFail=20");
+            
+            MockTransport transport = (MockTransport) factory.CompositeConnect(location);
+            
+            Assert.IsNotNull(transport);
+            Assert.IsTrue(transport.FailOnSendMessage);
+            Assert.AreEqual(20, transport.NumSentMessagesBeforeFail);
+        }        
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportFactoryTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs?rev=805544&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs
Tue Aug 18 19:23:56 2009
@@ -0,0 +1,201 @@
+/*
+ * 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.Collections;
+using System.Collections.Generic;
+using System.Threading;
+using Apache.NMS;
+using Apache.NMS.ActiveMQ.Transport;
+using Apache.NMS.ActiveMQ.Transport.Mock;
+using Apache.NMS.ActiveMQ.Commands;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+    [TestFixture]
+    public class MockTransportTest
+    {
+        private List<Command> sent = new List<Command>();
+        private List<Command> received = new List<Command>();
+        private List<Exception> exceptions = new List<Exception>();
+        
+        private MockTransport transport;
+        
+        public void OnException(ITransport transport, Exception exception)
+        {
+            exceptions.Add( exception );
+        }
+        
+        public void OnCommand(ITransport transport, Command command)
+        {
+            received.Add( command );
+        }
+        
+        public void OnOutgoingCommand(ITransport transport, Command command)
+        {
+            sent.Add( command );
+        }
+
+        [SetUp]
+        public void Init()
+        {
+            this.transport = new MockTransport();
+
+            transport.Command = new CommandHandler(OnCommand);
+            transport.Exception = new ExceptionHandler(OnException);
+            transport.OutgoingCommand = new CommandHandler(OnOutgoingCommand);
+        }
+        
+        [Test]
+        public void CreateMockTransportTest()
+        {
+            MockTransport transport = new MockTransport();
+            
+            Assert.IsNotNull(transport);
+            Assert.IsFalse(transport.IsStarted);
+            Assert.IsFalse(transport.IsDisposed);
+        }
+
+        [Test]
+        public void StartItializedTransportTest()
+        {
+            MockTransport transport = new MockTransport();
+
+            transport.Command = new CommandHandler(OnCommand);
+            transport.Exception = new ExceptionHandler(OnException);
+
+            transport.Start();
+        }
+        
+        [Test]
+        [ExpectedException( "System.InvalidOperationException" )]
+        public void StartUnitializedTransportTest()
+        {
+            MockTransport transport = new MockTransport();
+            transport.Start();
+        }
+        
+        [Test]
+        public void OneWaySendMessageTest()
+        {
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            transport.Oneway( message );
+            Assert.IsTrue(transport.NumSentMessages == 1);
+        }
+        
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void OneWayFailOnSendMessageTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            transport.Oneway( message );
+        }
+
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void RequestFailOnSendMessageTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            Assert.IsNotNull( transport.Request( message ) );
+        }
+        
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void AsyncRequestFailOnSendMessageTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            Assert.IsNotNull( transport.AsyncRequest( message ) );
+        }
+        
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void OnewayFailOnSendTwoMessagesTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.NumSentMessagesBeforeFail = 2;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            transport.Oneway( message );
+            transport.Oneway( message );
+            transport.Oneway( message );
+        }        
+
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void RequestFailOnSendTwoMessagesTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.NumSentMessagesBeforeFail = 2;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            transport.Request( message );
+            transport.Request( message );
+            transport.Request( message );
+        }        
+        
+        [Test]
+        [ExpectedException( "Apache.NMS.ActiveMQ.IOException" )]
+        public void AsyncRequestFailOnSendTwoMessagesTest()
+        {
+            transport.FailOnSendMessage = true;
+            transport.NumSentMessagesBeforeFail = 2;
+            transport.Start();
+            ActiveMQTextMessage message = new ActiveMQTextMessage();
+            transport.AsyncRequest( message );
+            transport.AsyncRequest( message );
+            transport.AsyncRequest( message );
+        }
+        
+        [Test]
+        public void InjectCommandTest()
+        {
+            ActiveMQMessage message = new ActiveMQMessage();
+            
+            transport.Start();            
+            transport.InjectCommand(message);
+            
+            Thread.Sleep( 1000 );
+            
+            Assert.IsTrue(this.received.Count > 0 );
+            Assert.IsTrue(transport.NumReceivedMessages == 1);
+        }
+        
+        [Test]
+        public void FailOnReceiveMessageTest()
+        {
+            ActiveMQMessage message = new ActiveMQMessage();
+            
+            transport.FailOnReceiveMessage = true;
+            transport.Start();
+            transport.InjectCommand(message);
+            
+            Thread.Sleep( 1000 );
+            
+            Assert.IsTrue(this.exceptions.Count > 0 );
+            Assert.IsTrue(transport.NumReceivedMessages == 1);
+        }        
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Transport/Mock/MockTransportTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message