activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r830006 - in /activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp: ConnectionTest.cs ConsumerTest.cs NMSTestSupport.cs TransactionTest.cs
Date Mon, 26 Oct 2009 22:26:29 GMT
Author: tabish
Date: Mon Oct 26 22:26:28 2009
New Revision: 830006

URL: http://svn.apache.org/viewvc?rev=830006&view=rev
Log:
Added several new tests and some more utility methods into NMSTestSupport.  Tests all pass
with NMS.ActiveMQ

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs?rev=830006&r1=830005&r2=830006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs Mon Oct 26
22:26:28 2009
@@ -25,6 +25,8 @@
 	[TestFixture]
 	public class ConnectionTest : NMSTestSupport
 	{
+        protected static string TEST_CLIENT_ID = "ConnectionTestClientId";
+        
         IConnection startedConnection = null;
         IConnection stoppedConnection = null;
         
@@ -112,6 +114,31 @@
 			}
 		}
 
+        [RowTest]
+        [Row(MsgDeliveryMode.Persistent, DestinationType.Queue)]
+        [Row(MsgDeliveryMode.Persistent, DestinationType.Topic)]
+        [Row(MsgDeliveryMode.NonPersistent, DestinationType.Queue)]        
+        [Row(MsgDeliveryMode.NonPersistent, DestinationType.Topic)]        
+        public void TestStartAfterSend(MsgDeliveryMode deliveryMode, DestinationType destinationType)
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {            
+                ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+                IDestination destination = CreateDestination(session, destinationType);
+                IMessageConsumer consumer = session.CreateConsumer(destination);
+        
+                // Send the messages
+                SendMessages(session, destination, deliveryMode, 1);
+        
+                // Start the conncection after the message was sent.
+                connection.Start();
+        
+                // Make sure only 1 message was delivered.
+                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+                Assert.IsNull(consumer.ReceiveNoWait());
+            }
+        }
+        
         /// <summary>
         /// Tests if the consumer receives the messages that were sent before the
         /// connection was started. 

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs?rev=830006&r1=830005&r2=830006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs Mon Oct 26 22:26:28
2009
@@ -17,6 +17,7 @@
 
 using System;
 using System.Threading;
+using Apache.NMS;
 using Apache.NMS.Util;
 using NUnit.Framework;
 using NUnit.Framework.Extensions;
@@ -189,6 +190,25 @@
             }
         }
 
+        [RowTest]
+        [Row(MsgDeliveryMode.NonPersistent, DestinationType.Queue)]        
+        [Row(MsgDeliveryMode.NonPersistent, DestinationType.Topic)]             
+        public void TestDontStart(MsgDeliveryMode deliveryMode, DestinationType destinationType
)
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {
+                ISession session = connection.CreateSession();
+                IDestination destination = CreateDestination(session, destinationType);
+                IMessageConsumer consumer = session.CreateConsumer(destination);
+        
+                // Send the messages
+                SendMessages(session, destination, deliveryMode, 1);
+        
+                // Make sure no messages were delivered.
+                Assert.IsNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+            }
+        }
+        
 #endif
 
 	}

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=830006&r1=830005&r2=830006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs Mon Oct 26
22:26:28 2009
@@ -390,5 +390,50 @@
 		{
 			return String.Format("{0:x}", value);
 		}
+
+        public void SendMessages(IDestination destination, MsgDeliveryMode deliveryMode,
int count) 
+        {
+            IConnection connection = CreateConnection();
+            connection.Start();
+            SendMessages(connection, destination, deliveryMode, count);
+            connection.Close();
+        }
+    
+        public void SendMessages(IConnection connection, IDestination destination, MsgDeliveryMode
deliveryMode, int count) 
+        {
+            ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            SendMessages(session, destination, deliveryMode, count);
+            session.Close();
+        }
+    
+        public void SendMessages(ISession session, IDestination destination, MsgDeliveryMode
deliveryMode, int count)
+        {
+            IMessageProducer producer = session.CreateProducer(destination);
+            producer.DeliveryMode = deliveryMode;
+            for(int i = 0; i < count; i++)
+            {
+                producer.Send(session.CreateTextMessage("" + i));
+            }
+            producer.Close();
+        }
+
+        public IDestination CreateDestination(ISession session, DestinationType type)
+        {            
+            string name = "TEST." + this.GetType().Name + "." + Guid.NewGuid();
+            
+            switch(type) 
+            {
+            case DestinationType.Queue:
+                return session.GetQueue(name);
+            case DestinationType.Topic:
+                return session.GetTopic(name);
+            case DestinationType.TemporaryQueue:
+                return session.CreateTemporaryQueue();
+            case DestinationType.TemporaryTopic:
+                return session.CreateTemporaryTopic();
+            default:
+                throw new ArgumentException("type: " + type);
+            }
+        }        
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs?rev=830006&r1=830005&r2=830006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs Mon Oct 26
22:26:28 2009
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Threading;
 using System.Collections;
 using Apache.NMS.Util;
 using NUnit.Framework;
@@ -363,7 +364,86 @@
 			ITextMessage actualTextMsg = actual as ITextMessage;
 			Assert.IsNotNull(actualTextMsg, "'actual' message not a text message");
 			Assert.AreEqual(expectedTextMsg.Text, actualTextMsg.Text, message);
-		}
+		}     
+
+        [RowTest]
+        [Row(MsgDeliveryMode.Persistent)]
+        [Row(MsgDeliveryMode.NonPersistent)]
+        public void TestRedispatchOfRolledbackTx(MsgDeliveryMode deliveryMode)
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {
+                connection.Start();
+                ISession session = connection.CreateSession(AcknowledgementMode.Transactional);
+                IQueue destination = session.GetQueue("TestRedispatchOfRolledbackTx:"+Guid.NewGuid());
+                
+                SendMessages(connection, destination, deliveryMode, 2);
+                
+                IMessageConsumer consumer = session.CreateConsumer(destination);
+                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+                
+                // install another consumer while message dispatch is unacked/uncommitted
+                ISession redispatchSession = connection.CreateSession(AcknowledgementMode.Transactional);
+                IMessageConsumer redispatchConsumer = redispatchSession.CreateConsumer(destination);
+        
+                session.Rollback();
+                session.Close();
+                        
+                IMessage msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                Assert.IsTrue(msg.NMSRedelivered);
+                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
+                msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                Assert.IsTrue(msg.NMSRedelivered);
+                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
+                redispatchSession.Commit();
+                
+                Assert.IsNull(redispatchConsumer.Receive(TimeSpan.FromMilliseconds(500)));
+                redispatchSession.Close();
+            }            
+        }
+
+        [RowTest]
+        [Row(MsgDeliveryMode.Persistent)]
+        [Row(MsgDeliveryMode.NonPersistent)]        
+        public void TestRedispatchOfUncommittedTx(MsgDeliveryMode deliveryMode)
+        {    
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+            {
+                connection.Start();
+                ISession session = connection.CreateSession(AcknowledgementMode.Transactional);
+                IQueue destination = session.GetQueue("TestRedispatchOfUncommittedTx:"+Guid.NewGuid());
+                
+                SendMessages(connection, destination, deliveryMode, 2);
+                
+                IMessageConsumer consumer = session.CreateConsumer(destination);
+                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
+                
+                // install another consumer while message dispatch is unacked/uncommitted
+                ISession redispatchSession = connection.CreateSession(AcknowledgementMode.Transactional);
+                IMessageConsumer redispatchConsumer = redispatchSession.CreateConsumer(destination);
+        
+                // no commit so will auto rollback and get re-dispatched to redisptachConsumer
+                session.Close();
+                        
+                IMessage msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                Assert.IsTrue(msg.NMSRedelivered);
+                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
+                
+                msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg);
+                Assert.IsTrue(msg.NMSRedelivered);
+                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
+                redispatchSession.Commit();
+                
+                Assert.IsNull(redispatchConsumer.Receive(TimeSpan.FromMilliseconds(500)));
+                redispatchSession.Close();
+            }
+        }        
 	}
 }
 



Mime
View raw message