You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2009/04/08 02:34:49 UTC

svn commit: r763055 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/ Apache.NMS.ActiveMQ/trunk/src/test/csharp/ Apache.NMS/trunk/ Apache.NMS/trunk/src/test/csharp/

Author: jgomes
Date: Wed Apr  8 00:34:49 2009
New Revision: 763055

URL: http://svn.apache.org/viewvc?rev=763055&view=rev
Log:
Added virtual topic unit test.
Fixes [AMQNET-153]. (See https://issues.apache.org/activemq/browse/AMQNET-153)

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/VirtualTopicTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/XmlMessageTest.cs
      - copied unchanged from r762914, activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/XmlMessage.cs
Removed:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/XmlMessage.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
    activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/VirtualTopicTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/VirtualTopicTest.cs?rev=763055&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/VirtualTopicTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/VirtualTopicTest.cs Wed Apr  8 00:34:49 2009
@@ -0,0 +1,131 @@
+/*
+ * 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 Apache.NMS.Util;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+using System.Threading;
+
+namespace Apache.NMS.Test
+{
+	[TestFixture]
+	public class VirtualTopicTest : NMSTestSupport
+	{
+		protected static string PRODUCER_DESTINATION_NAME = "topic://VirtualTopic.TestDestination";
+		protected static string CONSUMER_A_DESTINATION_NAME = "queue://Consumer.A.VirtualTopic.TestDestination";
+		protected static string CONSUMER_B_DESTINATION_NAME = "queue://Consumer.B.VirtualTopic.TestDestination";
+		protected static string TEST_CLIENT_ID = "VirtualTopicClientId";
+
+		protected const int totalMsgs = 100;
+		protected AcknowledgementMode currentAckMode;
+		protected int receivedA;
+		protected int receivedB;
+
+#if !NET_1_1
+		[RowTest]
+		[Row(AcknowledgementMode.AutoAcknowledge, false)]
+		[Row(AcknowledgementMode.ClientAcknowledge, false)]
+		[Row(AcknowledgementMode.Transactional, false)]
+
+		[Row(AcknowledgementMode.AutoAcknowledge, true)]
+		[Row(AcknowledgementMode.ClientAcknowledge, true)]
+		// Do not use listeners with transactional processing.
+#endif
+		public void SendReceiveVirtualTopicMessage(AcknowledgementMode ackMode, bool useListeners)
+		{
+			currentAckMode = ackMode;
+			receivedA = 0;
+			receivedB = 0;
+
+			using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+			{
+				connection.Start();
+				using(ISession session = connection.CreateSession(currentAckMode))
+				{
+					using(IMessageConsumer consumerA = session.CreateConsumer(SessionUtil.GetDestination(session, CONSUMER_A_DESTINATION_NAME)))
+					using(IMessageConsumer consumerB = session.CreateConsumer(SessionUtil.GetDestination(session, CONSUMER_B_DESTINATION_NAME)))
+					using(IMessageProducer producer = session.CreateProducer(SessionUtil.GetDestination(session, PRODUCER_DESTINATION_NAME)))
+					{
+						producer.RequestTimeout = receiveTimeout;
+						if(useListeners)
+						{
+							consumerA.Listener += MessageListenerA;
+							consumerB.Listener += MessageListenerB;
+						}
+
+						for(int index = 0; index < totalMsgs; index++)
+						{
+							producer.Send(session.CreateTextMessage("Message #" + index));
+							if(AcknowledgementMode.Transactional == currentAckMode)
+							{
+								session.Commit();
+							}
+
+							if(!useListeners)
+							{
+								IMessage messageA = consumerA.Receive(receiveTimeout);
+								IMessage messageB = consumerB.Receive(receiveTimeout);
+
+								Assert.IsNotNull(messageA, "Did not receive message for consumer A.");
+								Assert.IsNotNull(messageB, "Did not receive message for consumer B.");
+
+								if(AcknowledgementMode.Transactional == currentAckMode)
+								{
+									session.Commit();
+								}
+								else if(AcknowledgementMode.ClientAcknowledge == currentAckMode)
+								{
+									messageA.Acknowledge();
+									messageB.Acknowledge();
+								}
+							}
+						}
+
+						int waitCount = 0;
+						while(receivedA < totalMsgs && receivedB < totalMsgs)
+						{
+							if(waitCount++ > 50)
+							{
+								Assert.Fail("Timed out waiting for message consumers.  A = " + receivedA + ", B = " + receivedB);
+							}
+
+							Thread.Sleep(250);
+						}
+					}
+				}
+			}
+		}
+
+		private void MessageListenerA(IMessage message)
+		{
+			receivedA++;
+			if(AcknowledgementMode.ClientAcknowledge == currentAckMode)
+			{
+				message.Acknowledge();
+			}
+		}
+
+		private void MessageListenerB(IMessage message)
+		{
+			receivedB++;
+			if(AcknowledgementMode.ClientAcknowledge == currentAckMode)
+			{
+				message.Acknowledge();
+			}
+		}
+	}
+}

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=763055&r1=763054&r2=763055&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 Wed Apr  8 00:34:49 2009
@@ -2,7 +2,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.21022</ProductVersion>
+    <ProductVersion>9.0.30729</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{EB943C69-2C9B-45E7-B95B-FB916E7057ED}</ProjectGuid>
     <OutputType>Library</OutputType>
@@ -79,6 +79,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\test\csharp\StompHelperTest.cs" />
+    <Compile Include="src\test\csharp\VirtualTopicTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="nmsprovider-test.config">

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj?rev=763055&r1=763054&r2=763055&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj Wed Apr  8 00:34:49 2009
@@ -103,7 +103,7 @@
     <Compile Include="src\test\csharp\TransactionTest.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="src\test\csharp\XmlMessage.cs" />
+    <Compile Include="src\test\csharp\XmlMessageTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="vs2008-nms.csproj">