activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r682903 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/ Apache.NMS.ActiveMQ/trunk/src/main/csharp/ Apache.NMS.ActiveMQ/trunk/src/test/csharp/ Apache.NMS/trunk/src/test/csharp/
Date Tue, 05 Aug 2008 19:47:16 GMT
Author: jgomes
Date: Tue Aug  5 12:47:15 2008
New Revision: 682903

URL: http://svn.apache.org/viewvc?rev=682903&view=rev
Log:
Refactoring unit tests.
Fixes [AMQNET-92]. (See https://issues.apache.org/activemq/browse/AMQNET-92)

Removed:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConnectionTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config?rev=682903&r1=682902&r2=682903&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config Tue Aug  5
12:47:15 2008
@@ -17,9 +17,7 @@
 -->
 <configuration>
 	<defaultURI value="activemq:tcp://jgomesv1:61616">
-		<factoryParams>
-			<param type="string" value="NMSTestClient"/>
-		</factoryParams>
+		<factoryParams/>
 		<userName value="guest"/>
 		<passWord value="guest"/>
 	</defaultURI>

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs?rev=682903&r1=682902&r2=682903&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs Tue Aug
 5 12:47:15 2008
@@ -26,35 +26,26 @@
 	/// </summary>
 	public class Session : ISession
 	{
-		private readonly AcknowledgementMode acknowledgementMode;
-		private bool asyncSend;
-		private Connection connection;
 		private long consumerCounter;
 		private readonly IDictionary consumers = Hashtable.Synchronized(new Hashtable());
 		private readonly IDictionary producers = Hashtable.Synchronized(new Hashtable());
-		private bool dispatchAsync;
 		private readonly DispatchingThread dispatchingThread;
-		private bool exclusive;
 		private readonly SessionInfo info;
-		private int maximumPendingMessageLimit;
-		private int prefetchSize = 1000;
-		private byte priority;
 		private long producerCounter;
-		private bool retroactive;
-		private readonly TransactionContext transactionContext;
 		internal bool startedAsyncDelivery = false;
 		private bool disposed = false;
         private bool closed = false;
 
 		public Session(Connection connection, SessionInfo info, AcknowledgementMode acknowledgementMode)
 		{
-			this.connection = connection;
+			this.Connection = connection;
 			this.info = info;
-			this.acknowledgementMode = acknowledgementMode;
-			this.asyncSend = connection.AsyncSend;
-			transactionContext = new TransactionContext(this);
-			dispatchingThread = new DispatchingThread(new DispatchingThread.DispatchFunction(DispatchAsyncMessages));
-			dispatchingThread.ExceptionListener += new DispatchingThread.ExceptionHandler(dispatchingThread_ExceptionListener);
+			this.AcknowledgementMode = acknowledgementMode;
+			this.AsyncSend = connection.AsyncSend;
+			this.PrefetchSize = 1000;
+			this.TransactionContext = new TransactionContext(this);
+			this.dispatchingThread = new DispatchingThread(new DispatchingThread.DispatchFunction(DispatchAsyncMessages));
+			this.dispatchingThread.ExceptionListener += new DispatchingThread.ExceptionHandler(dispatchingThread_ExceptionListener);
 		}
 
 		~Session()
@@ -66,11 +57,7 @@
 		/// Sets the prefetch size, the maximum number of messages a broker will dispatch to consumers
 		/// until acknowledgements are received.
 		/// </summary>
-		public int PrefetchSize
-		{
-			get { return prefetchSize; }
-			set { this.prefetchSize = value; }
-		}
+		public int PrefetchSize { get; set; }
 
 		/// <summary>
 		/// Sets the maximum number of messages to keep around per consumer
@@ -78,72 +65,41 @@
 		/// will start to be evicted for slow consumers.
 		/// Must be > 0 to enable this feature
 		/// </summary>
-		public int MaximumPendingMessageLimit
-		{
-			get { return maximumPendingMessageLimit; }
-			set { this.maximumPendingMessageLimit = value; }
-		}
+		public int MaximumPendingMessageLimit { get; set; }
 
 		/// <summary>
 		/// Enables or disables whether asynchronous dispatch should be used by the broker
 		/// </summary>
-		public bool DispatchAsync
-		{
-			get { return dispatchAsync; }
-			set { this.dispatchAsync = value; }
-		}
+		public bool DispatchAsync { get; set; }
 
 		/// <summary>
 		/// Enables or disables exclusive consumers when using queues. An exclusive consumer means
 		/// only one instance of a consumer is allowed to process messages on a queue to preserve
order
 		/// </summary>
-		public bool Exclusive
-		{
-			get { return exclusive; }
-			set { this.exclusive = value; }
-		}
+		public bool Exclusive { get; set; }
 
 		/// <summary>
 		/// Enables or disables retroactive mode for consumers; i.e. do they go back in time or
not?
 		/// </summary>
-		public bool Retroactive
-		{
-			get { return retroactive; }
-			set { this.retroactive = value; }
-		}
+		public bool Retroactive { get; set; }
 
 		/// <summary>
 		/// Sets the default consumer priority for consumers
 		/// </summary>
-		public byte Priority
-		{
-			get { return priority; }
-			set { this.priority = value; }
-		}
+		public byte Priority { get; set; }
 
 		/// <summary>
 		/// This property indicates whether or not async send is enabled.
 		/// </summary>
-		public bool AsyncSend
-		{
-			get { return asyncSend; }
-			set { asyncSend = value; }
-		}
-
-		public Connection Connection
-		{
-			get { return connection; }
-		}
+		public bool AsyncSend { get; set; }
+		public Connection Connection { get; private set; }
 
 		public SessionId SessionId
 		{
 			get { return info.SessionId; }
 		}
 
-		public TransactionContext TransactionContext
-		{
-			get { return transactionContext; }
-		}
+		public TransactionContext TransactionContext { get; private set; }
 
 		#region ISession Members
 
@@ -189,7 +145,7 @@
 				try
 				{
 					StopAsyncDelivery();
-					connection.RemoveSession(this);
+					Connection.RemoveSession(this);
 					foreach(MessageConsumer consumer in GetConsumers())
 					{
 						consumer.Close();
@@ -207,7 +163,7 @@
 					Tracer.ErrorFormat("Error during session close: {0}", ex);
 				}
 
-				connection = null;
+				Connection = null;
 				closed = true;
 			}
 		}
@@ -231,7 +187,7 @@
 			try
 			{
 				producer = new MessageProducer(this, command);
-				connection.SyncRequest(command, requestTimeout);
+				Connection.SyncRequest(command, requestTimeout);
 				producers[producerId] = producer;
 			}
 			catch(Exception)
@@ -276,17 +232,17 @@
 		{
 			ConsumerInfo command = CreateConsumerInfo(destination, selector);
 			command.NoLocal = noLocal;
-			command.AcknowledgementMode = acknowledgementMode;
+			command.AcknowledgementMode = this.AcknowledgementMode;
 
 			ConsumerId consumerId = command.ConsumerId;
 			MessageConsumer consumer = null;
 
 			try
 			{
-				consumer = new MessageConsumer(this, command, acknowledgementMode);
+				consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
 				// lets register the consumer first in case we start dispatching messages immediately
 				consumers[consumerId] = consumer;
-				connection.SyncRequest(command, requestTimeout);
+				Connection.SyncRequest(command, requestTimeout);
 				return consumer;
 			}
 			catch(Exception)
@@ -315,10 +271,10 @@
 
 			try
 			{
-				consumer = new MessageConsumer(this, command, acknowledgementMode);
+				consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
 				// lets register the consumer first in case we start dispatching messages immediately
 				consumers[consumerId] = consumer;
-				connection.SyncRequest(command, requestTimeout);
+				Connection.SyncRequest(command, requestTimeout);
 			}
 			catch(Exception)
 			{
@@ -333,6 +289,13 @@
 			return consumer;
 		}
 
+		public void DeleteDurableConsumer(string name)
+		{
+			ConsumerInfo command = CreateConsumerInfo(null, String.Empty);
+			command.SubscriptionName = name;
+			Connection.SyncRequest(command, Connection.ITransport.RequestTimeout);
+		}
+
 		public IQueue GetQueue(string name)
 		{
 			return new ActiveMQQueue(name);
@@ -345,14 +308,14 @@
 
 		public ITemporaryQueue CreateTemporaryQueue()
 		{
-			ActiveMQTempQueue answer = new ActiveMQTempQueue(connection.CreateTemporaryDestinationName());
+			ActiveMQTempQueue answer = new ActiveMQTempQueue(Connection.CreateTemporaryDestinationName());
 			CreateTemporaryDestination(answer);
 			return answer;
 		}
 
 		public ITemporaryTopic CreateTemporaryTopic()
 		{
-			ActiveMQTempTopic answer = new ActiveMQTempTopic(connection.CreateTemporaryDestinationName());
+			ActiveMQTempTopic answer = new ActiveMQTempTopic(Connection.CreateTemporaryDestinationName());
 			CreateTemporaryDestination(answer);
 			return answer;
 		}
@@ -410,9 +373,9 @@
 			{
 				throw new InvalidOperationException(
 						"You cannot perform a Commit() on a non-transacted session. Acknowlegement mode is:
"
-						+ acknowledgementMode);
+						+ this.AcknowledgementMode);
 			}
-			transactionContext.Commit();
+			this.TransactionContext.Commit();
 		}
 
 		public void Rollback()
@@ -421,9 +384,9 @@
 			{
 				throw new InvalidOperationException(
 						"You cannot perform a Commit() on a non-transacted session. Acknowlegement mode is:
"
-						+ acknowledgementMode);
+						+ this.AcknowledgementMode);
 			}
-			transactionContext.Rollback();
+			this.TransactionContext.Rollback();
 
 			// lets ensure all the consumers redeliver any rolled back messages
 			foreach(MessageConsumer consumer in GetConsumers())
@@ -435,52 +398,49 @@
 
 		// Properties
 
-		public AcknowledgementMode AcknowledgementMode
-		{
-			get { return acknowledgementMode; }
-		}
+		public AcknowledgementMode AcknowledgementMode { get; private set; }
 
 		public bool Transacted
 		{
-			get { return acknowledgementMode == AcknowledgementMode.Transactional; }
+			get { return this.AcknowledgementMode == AcknowledgementMode.Transactional; }
 		}
 
 		#endregion
 
 		private void dispatchingThread_ExceptionListener(Exception exception)
 		{
-			connection.OnSessionException(this, exception);
+			Connection.OnSessionException(this, exception);
 		}
 
 		protected void CreateTemporaryDestination(ActiveMQDestination tempDestination)
 		{
 			DestinationInfo command = new DestinationInfo();
-			command.ConnectionId = connection.ConnectionId;
+			command.ConnectionId = Connection.ConnectionId;
 			command.OperationType = 0; // 0 is add
 			command.Destination = tempDestination;
 
-			connection.SyncRequest(command);
+			Connection.SyncRequest(command);
 		}
 
 		protected void DestroyTemporaryDestination(ActiveMQDestination tempDestination)
 		{
 			DestinationInfo command = new DestinationInfo();
-			command.ConnectionId = connection.ConnectionId;
+			command.ConnectionId = Connection.ConnectionId;
 			command.OperationType = 1; // 1 is remove
 			command.Destination = tempDestination;
 
-			connection.SyncRequest(command);
+			Connection.SyncRequest(command);
 		}
 
 		public void DoSend(ActiveMQMessage message)
 		{
 			if(AsyncSend)
 			{
-				connection.OneWay(message);
+				Connection.OneWay(message);
 			}
 			else
 			{
-				connection.SyncRequest(message);
+				Connection.SyncRequest(message);
 			}
 		}
 
@@ -491,19 +451,19 @@
 		{
 			if(Transacted)
 			{
-				transactionContext.Begin();
+				this.TransactionContext.Begin();
 			}
 		}
 
 		public void DisposeOf(ConsumerId objectId)
 		{
-			connection.DisposeOf(objectId);
+			Connection.DisposeOf(objectId);
 			consumers.Remove(objectId);
 		}
 
 		public void DisposeOf(ProducerId objectId)
 		{
-			connection.DisposeOf(objectId);
+			Connection.DisposeOf(objectId);
 			producers.Remove(objectId);
 		}
 
@@ -572,11 +532,11 @@
 			answer.ConsumerId = id;
 			answer.Destination = ActiveMQDestination.Transform(destination);
 			answer.Selector = selector;
-			answer.PrefetchSize = prefetchSize;
-			answer.Priority = priority;
-			answer.Exclusive = exclusive;
-			answer.DispatchAsync = dispatchAsync;
-			answer.Retroactive = retroactive;
+			answer.PrefetchSize = this.PrefetchSize;
+			answer.Priority = this.Priority;
+			answer.Exclusive = this.Exclusive;
+			answer.DispatchAsync = this.DispatchAsync;
+			answer.Retroactive = this.Retroactive;
 
 			// If the destination contained a URI query, then use it to set public properties
 			// on the ConsumerInfo

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs?rev=682903&r1=682902&r2=682903&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs Tue
Aug  5 12:47:15 2008
@@ -44,6 +44,21 @@
 	}
 
 	[TestFixture]
+	public class MapMessageTest : Apache.NMS.Test.MapMessageTest
+	{
+	}
+
+	[TestFixture]
+	public class MessageTest : Apache.NMS.Test.MessageTest
+	{
+	}
+
+	[TestFixture]
+	public class NMSPropertyTest : Apache.NMS.Test.NMSPropertyTest
+	{
+	}
+
+	[TestFixture]
 	public class TemporaryQueueTest : Apache.NMS.Test.TemporaryQueueTest
 	{
 	}

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj?rev=682903&r1=682902&r2=682903&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj Tue Aug
 5 12:47:15 2008
@@ -47,9 +47,7 @@
     </Compile>
     <Compile Include="src\test\csharp\CommonAssemblyInfo.cs" />
     <Compile Include="src\test\csharp\InheritedTests.cs" />
-    <Compile Include="src\test\csharp\MapMessageTest.cs" />
     <Compile Include="src\test\csharp\NMSConnectionFactoryTest.cs" />
-    <Compile Include="src\test\csharp\NMSPropertyTest.cs" />
     <Compile Include="src\test\csharp\OpenWire\BooleanStreamTest.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -60,9 +58,6 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\test\csharp\StompHelperTest.cs" />
-    <Compile Include="src\test\csharp\TestMain.cs">
-      <SubType>Code</SubType>
-    </Compile>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="vendor\Apache.NMS\vs2008-nms-test.csproj">

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=682903&r1=682902&r2=682903&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 Tue Aug  5
12:47:15 2008
@@ -30,17 +30,15 @@
 		[Test]
 		public void TwoConnections()
 		{
-			IConnection connection1 = Factory.CreateConnection();
-			connection1.Start();
-
-			IConnection connection2 = Factory.CreateConnection();
-			connection2.Start();
-
-			connection1.Stop();
-			connection1.Dispose();
-			connection2.Stop();
-			connection2.Dispose();
-			// with the bug present we'll get an exception in connection2.start()
+			using(IConnection connection1 = CreateConnection(null))
+			{
+				connection1.Start();
+				using(IConnection connection2 = CreateConnection(null))
+				{
+					// with the bug present we'll get an exception in connection2.start()
+					connection2.Start();
+				}
+			}
 		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs?rev=682903&r1=682902&r2=682903&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs Tue Aug  5 12:47:15
2008
@@ -23,81 +23,84 @@
 	public abstract class DurableTest : NMSTestSupport
 	{
 		private static string TOPIC = "TestTopicDurableConsumer";
-		private static String CLIENT_ID = "DurableClientId";
-		private static String CONSUMER_ID = "ConsumerId";
-
-		private int count = 0;
+		private static string SEND_CLIENT_ID = "SendDurableTestClientId";
+		private static string TEST_CLIENT_ID = "DurableTestClientId";
+		private static string CONSUMER_ID = "DurableTestConsumerId";
+		private static string DURABLE_SELECTOR = "2 > 1";
 
 		protected void RegisterDurableConsumer()
 		{
-			using(IConnection connection = Factory.CreateConnection())
+			using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
 			{
-				connection.ClientId = CLIENT_ID;
 				connection.Start();
-
 				using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
DURABLE_SELECTOR, false))
 					{
 					}
 				}
+			}
+		}
 
-				connection.Stop();
+		protected void UnregisterDurableConsumer()
+		{
+			using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+			{
+				connection.Start();
+				using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
+				{
+					session.DeleteDurableConsumer(CONSUMER_ID);
+				}
 			}
 		}
 
 		protected void SendPersistentMessage()
 		{
-			using(IConnection connection = Factory.CreateConnection())
+			using(IConnection connection = CreateConnection(SEND_CLIENT_ID))
 			{
 				connection.Start();
-				using (ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
+				using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
 					ITextMessage message = session.CreateTextMessage("Persistent Hello");
-					message.NMSPersistent = true;
 					using(IMessageProducer producer = session.CreateProducer())
 					{
-						producer.Send(topic, message);
+						producer.Send(topic, message, true, message.NMSPriority, receiveTimeout);
 					}
 				}
-
-				connection.Stop();
 			}
 		}
 
 		[Test]
 		public void TestDurableConsumer()
 		{
-			count = 0;
-
 			RegisterDurableConsumer();
 			SendPersistentMessage();
 
-			using (IConnection connection = Factory.CreateConnection())
+			try
 			{
-				connection.ClientId = CLIENT_ID;
-				connection.Start();
-
-				using (ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
+				using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
 				{
-					ITopic topic = session.GetTopic(TOPIC);
-					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					connection.Start();
+					using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
 					{
-						consumer.Listener += new MessageListener(consumer_Listener);
-						// Don't know how else to give the system enough time.
-						System.Threading.Thread.Sleep(5000);
-						Assert.AreEqual(1, count);
-						Console.WriteLine("Count = " + count);
-						SendPersistentMessage();
-						System.Threading.Thread.Sleep(5000);
-						Assert.AreEqual(2, count);
-						Console.WriteLine("Count = " + count);
+						ITopic topic = session.GetTopic(TOPIC);
+						using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
DURABLE_SELECTOR, false))
+						{
+							IMessage msg = consumer.Receive(receiveTimeout);
+							Assert.IsNotNull(msg, "Did not receive first durable message.");
+							SendPersistentMessage();
+
+							msg = consumer.Receive(receiveTimeout);
+							Assert.IsNotNull(msg, "Did not receive second durable message.");
+						}
 					}
 				}
-
-				connection.Stop();
+			}
+			finally
+			{
+				UnregisterDurableConsumer();
 			}
 		}
 
@@ -105,56 +108,39 @@
 		public void TestDurableConsumerTransactional()
 		{
 			RegisterDurableConsumer();
-
-			RunTestDurableConsumerTransactional();
-			// Timeout required before closing/disposing the connection otherwise orphan
-			// connection remains and test will fail when run the second time with a
-			// InvalidClientIDException: DurableClientID already connected.
-			//System.Threading.Thread.Sleep(5000); 
-			RunTestDurableConsumerTransactional();
+			try
+			{
+				RunTestDurableConsumerTransactional();
+				RunTestDurableConsumerTransactional();
+			}
+			finally
+			{
+				UnregisterDurableConsumer();
+			}
 		}
 
 		protected void RunTestDurableConsumerTransactional()
 		{
-			count = 0;
 			SendPersistentMessage();
 
-			using (IConnection connection = Factory.CreateConnection())
+			using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
 			{
-				connection.ClientId = CLIENT_ID;
 				connection.Start();
-
-				using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
+				using(ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
 				{
 					ITopic topic = session.GetTopic(TOPIC);
-					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
"2 > 1", false))
+					using(IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID,
DURABLE_SELECTOR, false))
 					{
-						consumer.Listener += new MessageListener(consumer_Listener);
-						// Don't know how else to give the system enough time. 
-
-						System.Threading.Thread.Sleep(5000);
-						Assert.AreEqual(1, count);
-						Console.WriteLine("Count = " + count);
+						IMessage msg = consumer.Receive(receiveTimeout);
+						Assert.IsNotNull(msg, "Did not receive first durable transactional message.");
 						SendPersistentMessage();
-						System.Threading.Thread.Sleep(5000);
-						Assert.AreEqual(2, count);
-						Console.WriteLine("Count = " + count);
 
+						msg = consumer.Receive(receiveTimeout);
+						Assert.IsNotNull(msg, "Did not receive second durable transactional message.");
 						session.Commit();
 					}
 				}
-
-				connection.Stop();
 			}
 		}
-
-		/// <summary>
-		/// Asynchronous listener call back method.
-		/// </summary>
-		/// <param name="message"></param>
-		private void consumer_Listener(IMessage message)
-		{
-			++count;
-		}
 	}
 }

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=682903&r1=682902&r2=682903&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 Tue Aug  5
12:47:15 2008
@@ -122,7 +122,7 @@
 		protected virtual void Connect()
 		{
 			WriteLine("Connecting...");
-			connection = CreateConnection();
+			connection = CreateConnection(this.clientId);
 			Assert.IsNotNull(connection, "no connection created");
 			connection.Start();
 			WriteLine("Connected.");
@@ -284,12 +284,13 @@
 			return null;
 		}
 
-		protected virtual IConnection CreateConnection()
+		public virtual IConnection CreateConnection(string newClientId)
 		{
 			IConnection newConnection = Factory.CreateConnection(userName, passWord);
-			if(clientId != null)
+			Assert.IsNotNull(newConnection, "connection not created");
+			if(newClientId != null)
 			{
-				newConnection.ClientId = clientId;
+				newConnection.ClientId = newClientId;
 			}
 
 			return newConnection;



Mime
View raw message