activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r1629997 - /activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs
Date Wed, 08 Oct 2014 00:57:04 GMT
Author: jgomes
Date: Wed Oct  8 00:57:04 2014
New Revision: 1629997

URL: http://svn.apache.org/r1629997
Log:
Sample to show convention of new "using" syntax for Destinations.

Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs?rev=1629997&r1=1629996&r2=1629997&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/AsyncConsumeTest.cs Wed Oct
 8 00:57:04 2014
@@ -36,7 +36,7 @@ namespace Apache.NMS.Test
 			semaphore = new AutoResetEvent(false);
 			received = false;
 			receivedMsg = null;
-			
+
 			RESPONSE_CLIENT_ID = GetTestClientId() + ":RESPONSE";
 		}
 
@@ -56,22 +56,20 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
-				{
-					IDestination destination = CreateDestination(session, DestinationType.Queue);
-					using(IMessageConsumer consumer = session.CreateConsumer(destination))
-					using(IMessageProducer producer = session.CreateProducer(destination))
-					{
-						producer.DeliveryMode = deliveryMode;
-						consumer.Listener += new MessageListener(OnMessage);
+				using(IDestination destination = CreateDestination(session, DestinationType.Queue))
+				using(IMessageConsumer consumer = session.CreateConsumer(destination))
+				using(IMessageProducer producer = session.CreateProducer(destination))
+				{
+					producer.DeliveryMode = deliveryMode;
+					consumer.Listener += new MessageListener(OnMessage);
+
+					IMessage request = session.CreateMessage();
+					request.NMSCorrelationID = "AsyncConsume";
+					request.NMSType = "Test";
+					producer.Send(request);
 
-						IMessage request = session.CreateMessage();
-						request.NMSCorrelationID = "AsyncConsume";
-						request.NMSType = "Test";
-						producer.Send(request);
-
-						WaitForMessageToArrive();
-						Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
-					}
+					WaitForMessageToArrive();
+					Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
 				}
 			}
 		}
@@ -85,23 +83,21 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+				using(IDestination destination = CreateDestination(session, DestinationType.Queue))
+				using(IMessageProducer producer = session.CreateProducer(destination))
 				{
-					IDestination destination = CreateDestination(session, DestinationType.Queue);
-					using(IMessageProducer producer = session.CreateProducer(destination))
-					{
-						producer.DeliveryMode = deliveryMode;
+					producer.DeliveryMode = deliveryMode;
 
-						IMessage request = session.CreateMessage();
-						request.NMSCorrelationID = "AsyncConsumeAfterSend";
-						request.NMSType = "Test";
-						producer.Send(request);
+					IMessage request = session.CreateMessage();
+					request.NMSCorrelationID = "AsyncConsumeAfterSend";
+					request.NMSType = "Test";
+					producer.Send(request);
 
-						using(IMessageConsumer consumer = session.CreateConsumer(destination))
-						{
-							consumer.Listener += new MessageListener(OnMessage);
-							WaitForMessageToArrive();
-							Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
-						}
+					using(IMessageConsumer consumer = session.CreateConsumer(destination))
+					{
+						consumer.Listener += new MessageListener(OnMessage);
+						WaitForMessageToArrive();
+						Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
 					}
 				}
 			}
@@ -116,23 +112,21 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
-				{
-					IDestination destination = CreateDestination(session, DestinationType.Queue);
-					using(IMessageConsumer consumer = session.CreateConsumer(destination))
-					using(IMessageProducer producer = session.CreateProducer(destination))
-					{
-						producer.DeliveryMode = deliveryMode;
-
-						IMessage request = session.CreateMessage();
-						request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener";
-						request.NMSType = "Test";
-						producer.Send(request);
-
-						// now lets add the listener
-						consumer.Listener += new MessageListener(OnMessage);
-						WaitForMessageToArrive();
-						Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
-					}
+				using(IDestination destination = CreateDestination(session, DestinationType.Queue))
+				using(IMessageConsumer consumer = session.CreateConsumer(destination))
+				using(IMessageProducer producer = session.CreateProducer(destination))
+				{
+					producer.DeliveryMode = deliveryMode;
+
+					IMessage request = session.CreateMessage();
+					request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener";
+					request.NMSType = "Test";
+					producer.Send(request);
+
+					// now lets add the listener
+					consumer.Listener += new MessageListener(OnMessage);
+					WaitForMessageToArrive();
+					Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
 				}
 			}
 		}
@@ -146,28 +140,26 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+				using(IDestination destination = CreateDestination(session, DestinationType.Queue))
+				using(IMessageConsumer consumer = session.CreateConsumer(destination))
 				{
-					IDestination destination = CreateDestination(session, DestinationType.Queue);
-					using(IMessageConsumer consumer = session.CreateConsumer(destination))
+					consumer.Listener += new MessageListener(OnMessage);
+					using(IMessageProducer producer = session.CreateProducer(destination))
 					{
-						consumer.Listener += new MessageListener(OnMessage);
-						using(IMessageProducer producer = session.CreateProducer(destination))
-						{
-							producer.DeliveryMode = deliveryMode;
-
-							ITextMessage request = session.CreateTextMessage("Hello, World!");
-							request.NMSCorrelationID = "AsyncConsumeTextMessage";
-							request.Properties["NMSXGroupID"] = "cheese";
-							request.Properties["myHeader"] = "James";
-
-							producer.Send(request);
-
-							WaitForMessageToArrive();
-							Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
-							Assert.AreEqual(request.Properties["NMSXGroupID"], receivedMsg.Properties["NMSXGroupID"],
"Invalid NMSXGroupID.");
-							Assert.AreEqual(request.Properties["myHeader"], receivedMsg.Properties["myHeader"],
"Invalid myHeader.");
-							Assert.AreEqual(request.Text, ((ITextMessage) receivedMsg).Text, "Invalid text body.");
-						}
+						producer.DeliveryMode = deliveryMode;
+
+						ITextMessage request = session.CreateTextMessage("Hello, World!");
+						request.NMSCorrelationID = "AsyncConsumeTextMessage";
+						request.Properties["NMSXGroupID"] = "cheese";
+						request.Properties["myHeader"] = "James";
+
+						producer.Send(request);
+
+						WaitForMessageToArrive();
+						Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
+						Assert.AreEqual(request.Properties["NMSXGroupID"], receivedMsg.Properties["NMSXGroupID"],
"Invalid NMSXGroupID.");
+						Assert.AreEqual(request.Properties["myHeader"], receivedMsg.Properties["myHeader"],
"Invalid myHeader.");
+						Assert.AreEqual(request.Text, ((ITextMessage) receivedMsg).Text, "Invalid text body.");
 					}
 				}
 			}
@@ -182,27 +174,24 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
-				{
-					IDestination destination = CreateDestination(session, DestinationType.Queue);
-					ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue();
-
-					using(IMessageConsumer consumer = session.CreateConsumer(destination))
-					using(IMessageConsumer tempConsumer = session.CreateConsumer(tempReplyDestination))
-					using(IMessageProducer producer = session.CreateProducer(destination))
-					{
-						producer.DeliveryMode = deliveryMode;
-						tempConsumer.Listener += new MessageListener(OnMessage);
-						consumer.Listener += new MessageListener(OnQueueMessage);
+				using(ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue())
+				using(IDestination destination = CreateDestination(session, DestinationType.Queue))
+				using(IMessageConsumer consumer = session.CreateConsumer(destination))
+				using(IMessageConsumer tempConsumer = session.CreateConsumer(tempReplyDestination))
+				using(IMessageProducer producer = session.CreateProducer(destination))
+				{
+					producer.DeliveryMode = deliveryMode;
+					tempConsumer.Listener += new MessageListener(OnMessage);
+					consumer.Listener += new MessageListener(OnQueueMessage);
+
+					IMessage request = session.CreateMessage();
+					request.NMSCorrelationID = "TemqQueueAsyncConsume";
+					request.NMSType = "Test";
+					request.NMSReplyTo = tempReplyDestination;
+					producer.Send(request);
 
-						IMessage request = session.CreateMessage();
-						request.NMSCorrelationID = "TemqQueueAsyncConsume";
-						request.NMSType = "Test";
-						request.NMSReplyTo = tempReplyDestination;
-						producer.Send(request);
-
-						WaitForMessageToArrive();
-						Assert.AreEqual("TempQueueAsyncResponse", receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
-					}
+					WaitForMessageToArrive();
+					Assert.AreEqual("TempQueueAsyncResponse", receivedMsg.NMSCorrelationID, "Invalid correlation
ID.");
 				}
 			}
 		}
@@ -214,16 +203,14 @@ namespace Apache.NMS.Test
 			{
 				connection.Start();
 				using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+				using(IMessageProducer producer = session.CreateProducer(message.NMSReplyTo))
 				{
-					using(IMessageProducer producer = session.CreateProducer(message.NMSReplyTo))
-					{
-						producer.DeliveryMode = message.NMSDeliveryMode;
+					producer.DeliveryMode = message.NMSDeliveryMode;
 
-						ITextMessage response = session.CreateTextMessage("Asynchronous Response Message Text");
-						response.NMSCorrelationID = "TempQueueAsyncResponse";
-						response.NMSType = message.NMSType;
-						producer.Send(response); 
-					}
+					ITextMessage response = session.CreateTextMessage("Asynchronous Response Message Text");
+					response.NMSCorrelationID = "TempQueueAsyncResponse";
+					response.NMSType = message.NMSType;
+					producer.Send(response);
 				}
 			}
 		}



Mime
View raw message