Author: tabish
Date: Thu Aug  5 20:56:04 2010
New Revision: 982781

URL: http://svn.apache.org/viewvc?rev=982781&view=rev
Log:
Adds a new Test for MessageProducer to ensure that RequestTimeout works and the 
send will timeout as expected.

Added:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
   (with props)
Modified:
    
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/Mock/MockTransportFactory.cs

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=982781&r1=982780&r2=982781&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
 Thu Aug  5 20:56:04 2010
@@ -37,6 +37,9 @@ namespace Apache.NMS.ActiveMQ.Transport.
 
         private string name;
         private bool failOnSendMessage = false;
+        private int numMessagesToRespondTo = -1;
+        private int numMessagesRespondedTo = 0;
+        private bool respondToMessages = true;
         private int numSentMessagesBeforeFail = -1;
         private int numSentMessages = 0;
         private bool failOnReceiveMessage = false;
@@ -170,9 +173,21 @@ namespace Apache.NMS.ActiveMQ.Transport.
             }
             
             // Process and send any new Commands back.
+            List<Command> results = new List<Command>();
 
             // Let the Response Builder give us the Commands to send to the 
Client App.
-            List<Command> results = 
this.responseBuilder.BuildIncomingCommands(command);
+            if( command.IsMessage )
+            {
+                if( this.respondToMessages && this.NumMessagesToRespondTo < 
this.numMessagesRespondedTo )
+                {
+                    results = 
this.responseBuilder.BuildIncomingCommands(command);
+                    this.numMessagesRespondedTo++;
+                }
+            }
+            else
+            {
+                results = this.responseBuilder.BuildIncomingCommands(command);
+            }
             
             lock(this.receiveQueue)
             {
@@ -364,6 +379,24 @@ namespace Apache.NMS.ActiveMQ.Transport.
             set { numSentKeppAliveInfos = value; }
         }
 
+        public int NumMessagesToRespondTo
+        {
+            get { return numMessagesToRespondTo; }
+            set { numMessagesToRespondTo = value; }
+        }
+
+        public int NumMessagesRespondedTo
+        {
+            get { return numMessagesRespondedTo; }
+            set { numMessagesRespondedTo = value; }
+        }
+
+        public bool RespondToMessages
+        {
+            get { return respondToMessages; }
+            set { respondToMessages = value; }
+        }
+
         public bool IsFaultTolerant
         {
             get{ return false; }

Modified: 
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=982781&r1=982780&r2=982781&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
 Thu Aug  5 20:56:04 2010
@@ -81,6 +81,20 @@ namespace Apache.NMS.ActiveMQ.Transport.
             set { this.name = value; }
         }
 
+        private int numMessagesToRespondTo = -1;
+        public int NumMessagesToRespondTo
+        {
+            get { return numMessagesToRespondTo; }
+            set { numMessagesToRespondTo = value; }
+        }
+
+        private bool respondToMessages = true;
+        public bool RespondToMessages
+        {
+            get { return respondToMessages; }
+            set { respondToMessages = value; }
+        }
+
                #endregion
 
                public ITransport CreateTransport(Uri location)
@@ -116,6 +130,8 @@ namespace Apache.NMS.ActiveMQ.Transport.
                        transport.FailOnSendMessage = this.FailOnSendMessage;
                        transport.NumSentMessagesBeforeFail = 
this.NumSentMessagesBeforeFail;
             transport.Name = this.Name;
+            transport.RespondToMessages = this.respondToMessages;
+            transport.NumMessagesToRespondTo = this.numMessagesToRespondTo;
 
                        return transport;
                }

Added: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs?rev=982781&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MessageProducerTest.cs
 Thu Aug  5 20:56:04 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.Timers;
+using NUnit.Framework;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+    [TestFixture]
+    public class MessageProducerTest
+    {
+        [Test]
+        public void TestProducerSendWithTimeout()
+        {
+            Uri uri = new 
Uri("mock://localhost:61616?connection.RequestTimeout=100&transport.respondToMessages=false");
+
+            ConnectionFactory factory = new ConnectionFactory(uri);
+            using(IConnection connection = factory.CreateConnection())
+            {
+                ISession session = connection.CreateSession();
+                IDestination destination = session.GetTopic("Test");
+                IMessageProducer producer = 
session.CreateProducer(destination);
+
+                ITextMessage message = session.CreateTextMessage("Hello 
World");
+
+                for(int i = 0; i < 10; ++i)
+                {
+                    DateTime start = DateTime.Now;
+
+                    producer.Send(message);
+
+                    DateTime end = DateTime.Now;
+    
+                    TimeSpan elapsed = end - start;
+    
+                    // We test for something close since its a bit hard to be 
exact here
+                    Assert.AreEqual(100.0, elapsed.TotalMilliseconds, 10.0);
+                }
+            }
+        }
+    }
+}
+

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


Reply via email to