You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/01/06 17:36:35 UTC

svn commit: r896516 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk: src/test/csharp/NMSPropertyTest.cs src/test/csharp/TempDestinationTest.cs vs2008-stomp-test.csproj

Author: tabish
Date: Wed Jan  6 16:36:34 2010
New Revision: 896516

URL: http://svn.apache.org/viewvc?rev=896516&view=rev
Log:
Adds a port of the NMSPropertyTest and TempDestinationTest

Added:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TempDestinationTest.cs   (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs?rev=896516&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs Wed Jan  6 16:36:34 2010
@@ -0,0 +1,84 @@
+/*
+ * 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 Apache.NMS.Test;
+using Apache.NMS.Util;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.Stomp.Test
+{
+    [TestFixture]
+    public class NMSPropertyTest : NMSTestSupport
+    {
+        protected static string DESTINATION_NAME = "NMSPropsDestination";
+        protected static string TEST_CLIENT_ID = "NMSPropsClientId";
+
+        // standard NMS properties
+        protected string expectedText = "Hey this works!";
+        protected string correlationID = "FooBar";
+        protected MsgPriority priority = MsgPriority.Normal;
+        protected String type = "FooType";
+        protected String groupID = "BarGroup";
+        protected int groupSeq = 1;
+
+        [RowTest]
+        [Row(MsgDeliveryMode.Persistent)]
+        [Row(MsgDeliveryMode.NonPersistent)]
+        public void SendReceiveNMSProperties(MsgDeliveryMode deliveryMode)
+        {
+            using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
+            {
+                connection.Start();
+                using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+                {
+                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+                    using(IMessageConsumer consumer = session.CreateConsumer(destination))
+                    using(IMessageProducer producer = session.CreateProducer(destination))
+                    {
+                        producer.Priority = priority;
+                        producer.DeliveryMode = deliveryMode;
+                        producer.RequestTimeout = receiveTimeout;
+                        ITextMessage request = session.CreateTextMessage(expectedText);
+
+                        // Set the headers
+                        request.NMSCorrelationID = correlationID;
+                        request.NMSType = type;
+                        request.Properties["NMSXGroupID"] = groupID;
+                        request.Properties["NMSXGroupSeq"] = groupSeq;
+
+                        producer.Send(request);
+
+                        ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage;
+
+                        Assert.IsNotNull(message, "Did not receive an ITextMessage!");
+                        Assert.AreEqual(expectedText, message.Text, "Message text does not match.");
+
+                        // compare standard NMS headers
+                        Assert.AreEqual(correlationID, message.NMSCorrelationID, "NMSCorrelationID does not match");
+                        Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+                        Assert.AreEqual(priority, message.NMSPriority, "NMSPriority does not match");
+                        Assert.AreEqual(type, message.NMSType, "NMSType does not match");
+                        Assert.AreEqual(groupID, message.Properties["NMSXGroupID"], "NMSXGroupID does not match");
+                        Assert.AreEqual(groupSeq, message.Properties["NMSXGroupSeq"], "NMSXGroupSeq does not match");
+                    }
+                }
+            }
+        }
+    }
+}

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

Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/NMSPropertyTest.cs
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TempDestinationTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TempDestinationTest.cs?rev=896516&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TempDestinationTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TempDestinationTest.cs Wed Jan  6 16:36:34 2010
@@ -0,0 +1,158 @@
+/*
+ * 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.Threading;
+using System.Collections;
+using Apache.NMS.Util;
+using Apache.NMS.Test;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.Stomp.Test
+{
+    [TestFixture]
+    public class TempDestinationTest : NMSTestSupport
+    {
+        private IConnection connection;
+        private IList connections = ArrayList.Synchronized(new ArrayList());
+
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+
+            this.connection = CreateConnection();
+            this.connections.Add(connection);
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            foreach(IConnection conn in this.connections)
+            {
+                try
+                {
+                    conn.Close();
+                }
+                catch
+                {
+                }
+            }
+
+            connections.Clear();
+
+            base.TearDown();
+        }
+
+        [Test]
+        public void TestTempDestOnlyConsumedByLocalConn()
+        {
+            connection.Start();
+
+            ISession tempSession = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITemporaryQueue queue = tempSession.CreateTemporaryQueue();
+            IMessageProducer producer = tempSession.CreateProducer(queue);
+            producer.DeliveryMode = (MsgDeliveryMode.NonPersistent);
+            ITextMessage message = tempSession.CreateTextMessage("First");
+            producer.Send(message);
+
+            // temp destination should not be consume when using another connection
+            IConnection otherConnection = CreateConnection();
+            connections.Add(otherConnection);
+            ISession otherSession = otherConnection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITemporaryQueue otherQueue = otherSession.CreateTemporaryQueue();
+            IMessageConsumer consumer = otherSession.CreateConsumer(otherQueue);
+            IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(3000));
+            Assert.IsNull(msg);
+
+            // should be able to consume temp destination from the same connection
+            consumer = tempSession.CreateConsumer(queue);
+            msg = consumer.Receive(TimeSpan.FromMilliseconds(3000));
+            Assert.IsNotNull(msg);
+        }
+
+        [Test]
+        public void TestTempQueueHoldsMessagesWithConsumers()
+        {
+            ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITemporaryQueue queue = session.CreateTemporaryQueue();
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            connection.Start();
+
+            IMessageProducer producer = session.CreateProducer(queue);
+            producer.DeliveryMode = (MsgDeliveryMode.NonPersistent);
+            ITextMessage message = session.CreateTextMessage("Hello");
+            producer.Send(message);
+
+            IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNotNull(message2);
+            Assert.IsTrue(message2 is ITextMessage, "Expected message to be a ITextMessage");
+            Assert.IsTrue(((ITextMessage)message2).Text == message.Text, "Expected message to be a '" + message.Text + "'");
+        }
+
+        [Test]
+        public void TestTempQueueHoldsMessagesWithoutConsumers()
+        {
+            ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITemporaryQueue queue = session.CreateTemporaryQueue();
+            IMessageProducer producer = session.CreateProducer(queue);
+            producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
+            ITextMessage message = session.CreateTextMessage("Hello");
+            producer.Send(message);
+
+            connection.Start();
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(3000));
+            Assert.IsNotNull(message2);
+            Assert.IsTrue(message2 is ITextMessage, "Expected message to be a ITextMessage");
+            Assert.IsTrue(((ITextMessage)message2).Text == message.Text, "Expected message to be a '" + message.Text + "'");
+        }
+
+        [Test]
+        public void TestTmpQueueWorksUnderLoad()
+        {
+            int count = 250;
+            int dataSize = 1024;
+
+            ArrayList list = new ArrayList(count);
+            ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITemporaryQueue queue = session.CreateTemporaryQueue();
+            IMessageProducer producer = session.CreateProducer(queue);
+            producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
+
+            byte[] data = new byte[dataSize];
+            for(int i = 0; i < count; i++)
+            {
+                IBytesMessage message = session.CreateBytesMessage();
+                message.WriteBytes(data);
+                message.Properties.SetInt("c", i);
+                producer.Send(message);
+                list.Add(message);
+            }
+
+            connection.Start();
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            for(int i = 0; i < count; i++)
+            {
+                IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(2000));
+                Assert.IsTrue(message2 != null);
+                Assert.AreEqual(i, message2.Properties.GetInt("c"));
+            }
+        }
+    }
+}

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

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj?rev=896516&r1=896515&r2=896516&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj Wed Jan  6 16:36:34 2010
@@ -83,5 +83,7 @@
     <Compile Include="src\test\csharp\TextMessageTest.cs" />
     <Compile Include="src\test\csharp\ConsumerTest.cs" />
     <Compile Include="src\test\csharp\DurableTest.cs" />
+    <Compile Include="src\test\csharp\NMSPropertyTest.cs" />
+    <Compile Include="src\test\csharp\TempDestinationTest.cs" />
   </ItemGroup>
 </Project>
\ No newline at end of file