activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r984593 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp: QueueConsumerPriorityTest.cs Util/FifoMessageDispatchChannelTest.cs Util/MessageDispatchChannelTest.cs Util/SimplePriorityMessageDispatchChannelTest.cs
Date Wed, 11 Aug 2010 21:39:27 GMT
Author: tabish
Date: Wed Aug 11 21:39:26 2010
New Revision: 984593

URL: http://svn.apache.org/viewvc?rev=984593&view=rev
Log:
tests for: https://issues.apache.org/activemq/browse/AMQNET-270

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueConsumerPriorityTest.cs
  (with props)
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/FifoMessageDispatchChannelTest.cs
      - copied, changed from r984266, activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/MessageDispatchChannelTest.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs
  (with props)
Removed:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/MessageDispatchChannelTest.cs

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueConsumerPriorityTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueConsumerPriorityTest.cs?rev=984593&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueConsumerPriorityTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueConsumerPriorityTest.cs
Wed Aug 11 21:39:26 2010
@@ -0,0 +1,132 @@
+/*
+ * 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 Apache.NMS.ActiveMQ.Commands;
+using Apache.NMS.Test;
+using NUnit.Framework;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+    [TestFixture]
+    public class QueueConsumerPriorityTest : NMSTestSupport
+    {
+        protected static string DESTINATION_NAME = "QueueConsumerPriorityTestDestination";
+        protected static string TEST_CLIENT_ID = "QueueConsumerPriorityTestClientId";
+        protected static int MSG_COUNT = 50;
+        
+        private IConnection createConnection(bool start) 
+        {
+            IConnection conn = CreateConnection(TEST_CLIENT_ID);
+            if(start) 
+            {
+                conn.Start();
+            }
+            
+            return conn;
+        }
+        
+        private void PurgeQueue(IConnection conn, IDestination queue)
+        {
+            ISession session = conn.CreateSession();
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+            while(consumer.Receive(TimeSpan.FromMilliseconds(500)) != null)
+            {
+            }
+
+            consumer.Close();
+            session.Close();
+        }
+
+        class Producer
+        {
+            private readonly ISession session;
+            private readonly IDestination dest;
+            private readonly int count;
+            private readonly MsgPriority priority;
+
+            private Thread theThread;
+
+            public Producer(ISession session, IDestination dest, int count, MsgPriority priority)
+            {
+                this.session = session;
+                this.dest = dest;
+                this.count = count;
+                this.priority = priority;
+            }
+
+            public void Start()
+            {
+                theThread = new Thread(Run);
+                theThread.Start();
+            }
+
+            public void Join()
+            {
+                if(theThread != null)
+                {
+                    theThread.Join();
+                }
+            }
+
+            public void Run()
+            {
+                IMessageProducer producer = session.CreateProducer(dest);
+                producer.Priority = this.priority;
+                for(int i = 0; i < this.count; ++i)
+                {
+                    ITextMessage message = session.CreateTextMessage("Message Priority =
" + (byte) priority);
+                    producer.Send(message);
+                }
+            }
+        }
+
+        [Test]
+        public void TestPriorityConsumption()
+        {
+            IConnection conn = createConnection(true);
+
+            ISession receiverSession = conn.CreateSession();
+            ISession senderSession = conn.CreateSession();
+
+            IDestination queue = receiverSession.GetQueue(DESTINATION_NAME);
+
+            PurgeQueue(conn, queue);
+
+            IMessageConsumer consumer = receiverSession.CreateConsumer(queue);
+
+            Producer producer1 = new Producer(senderSession, queue, MSG_COUNT, MsgPriority.High);
+            Producer producer2 = new Producer(senderSession, queue, MSG_COUNT, MsgPriority.Low);
+
+            producer1.Start();
+            producer2.Start();
+
+            producer1.Join();
+            producer2.Join();
+
+            for(int i = 0; i < MSG_COUNT * 2; i++)
+            {
+                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+                Assert.IsNotNull(msg, "Message {0} was null", i);
+                Assert.AreEqual(i < MSG_COUNT ? MsgPriority.High : MsgPriority.Low, msg.NMSPriority,
+                                "Message {0} priority was wrong", i);
+            }
+        }
+    }
+}
+

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

Copied: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/FifoMessageDispatchChannelTest.cs
(from r984266, activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/MessageDispatchChannelTest.cs)
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/FifoMessageDispatchChannelTest.cs?p2=activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/FifoMessageDispatchChannelTest.cs&p1=activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/MessageDispatchChannelTest.cs&r1=984266&r2=984593&rev=984593&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/MessageDispatchChannelTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/FifoMessageDispatchChannelTest.cs
Wed Aug 11 21:39:26 2010
@@ -23,12 +23,12 @@ using NUnit.Framework;
 namespace Apache.NMS.ActiveMQ.Test
 {
     [TestFixture]
-    public class MessageDispatchChannelTest
+    public class FifoMessageDispatchChannelTest
     {
         [Test]
         public void TestCtor()
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             Assert.IsTrue( channel.Running == false );
             Assert.IsTrue( channel.Empty == true );
             Assert.IsTrue( channel.Count == 0 );
@@ -38,7 +38,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestStart() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             channel.Start();
             Assert.IsTrue( channel.Running == true );
         }
@@ -46,7 +46,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestStop() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             channel.Start();
             Assert.IsTrue( channel.Running == true );
             channel.Stop();
@@ -56,7 +56,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestClose() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             channel.Start();
             Assert.IsTrue( channel.Running == true );
             Assert.IsTrue( channel.Closed == false );
@@ -71,7 +71,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestEnqueue() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();
         
@@ -92,7 +92,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestEnqueueFront() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();
         
@@ -118,7 +118,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestPeek() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();
         
@@ -148,7 +148,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestDequeueNoWait() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
         
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();
@@ -178,7 +178,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestDequeue() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
         
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();
@@ -212,7 +212,7 @@ namespace Apache.NMS.ActiveMQ.Test
         [Test]
         public void TestRemoveAll() 
         {
-            MessageDispatchChannel channel = new MessageDispatchChannel();
+            FifoMessageDispatchChannel channel = new FifoMessageDispatchChannel();
         
             MessageDispatch dispatch1 = new MessageDispatch();
             MessageDispatch dispatch2 = new MessageDispatch();

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs?rev=984593&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs
Wed Aug 11 21:39:26 2010
@@ -0,0 +1,279 @@
+/*
+ * 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 Apache.NMS.ActiveMQ.Commands;
+using NUnit.Framework;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+    [TestFixture]
+    public class SimplePriorityMessageDispatchChannelTest
+    {
+        [Test]
+        public void TestCtor()
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            Assert.IsTrue( channel.Running == false );
+            Assert.IsTrue( channel.Empty == true );
+            Assert.IsTrue( channel.Count == 0 );
+            Assert.IsTrue( channel.Closed == false );
+        }
+        
+        [Test]
+        public void TestStart() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+        }
+        
+        [Test]
+        public void TestStop() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+            channel.Stop();
+            Assert.IsTrue( channel.Running == false );
+        }
+        
+        [Test]
+        public void TestClose() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+            Assert.IsTrue( channel.Closed == false );
+            channel.Close();
+            Assert.IsTrue( channel.Running == false );
+            Assert.IsTrue( channel.Closed == true );
+            channel.Start();
+            Assert.IsTrue( channel.Running == false );
+            Assert.IsTrue( channel.Closed == true );
+        }
+        
+        [Test]
+        public void TestEnqueue() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+        
+            Assert.IsTrue( channel.Empty == true );
+            Assert.IsTrue( channel.Count == 0 );
+        
+            channel.Enqueue( dispatch1 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 1 );
+        
+            channel.Enqueue( dispatch2 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 2 );
+        }
+        
+        [Test]
+        public void TestEnqueueFront() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+        
+            channel.Start();
+        
+            Assert.IsTrue( channel.Empty == true );
+            Assert.IsTrue( channel.Count == 0 );
+        
+            channel.EnqueueFirst( dispatch1 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 1 );
+        
+            channel.EnqueueFirst( dispatch2 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 2 );
+        
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch2 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch1 );
+        }
+        
+        [Test]
+        public void TestPeek() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+
+            Message message1 = new Message();
+            Message message2 = new Message();
+
+            message1.Priority = 2;
+            message2.Priority = 1;
+
+            dispatch1.Message = message1;
+            dispatch2.Message = message2;
+
+            Assert.IsTrue( channel.Empty == true );
+            Assert.IsTrue( channel.Count == 0 );
+        
+            channel.EnqueueFirst( dispatch1 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 1 );
+        
+            channel.EnqueueFirst( dispatch2 );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 2 );
+        
+            Assert.IsTrue( channel.Peek() == null );
+        
+            channel.Start();
+        
+            Assert.IsTrue( channel.Peek() == dispatch1 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch1 );
+            Assert.IsTrue( channel.Peek() == dispatch2 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch2 );
+        }
+        
+        [Test]
+        public void TestDequeueNoWait() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+        
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+            MessageDispatch dispatch3 = new MessageDispatch();
+
+            Message message1 = new Message();
+            Message message2 = new Message();
+            Message message3 = new Message();
+
+            message1.Priority = 1;
+            message2.Priority = 2;
+            message3.Priority = 3;
+
+            dispatch1.Message = message1;
+            dispatch2.Message = message2;
+            dispatch3.Message = message3;
+
+            Assert.IsTrue( channel.Running == false );
+            Assert.IsTrue( channel.DequeueNoWait() == null );
+        
+            channel.Enqueue( dispatch1 );
+            channel.Enqueue( dispatch2 );
+            channel.Enqueue( dispatch3 );
+        
+            Assert.IsTrue( channel.DequeueNoWait() == null );
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+        
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 3 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch3 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch2 );
+            Assert.IsTrue( channel.DequeueNoWait() == dispatch1 );
+        
+            Assert.IsTrue( channel.Count == 0 );
+            Assert.IsTrue( channel.Empty == true );
+        }
+        
+        [Test]
+        public void TestDequeue() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+        
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+            MessageDispatch dispatch3 = new MessageDispatch();
+
+            Message message1 = new Message();
+            Message message2 = new Message();
+            Message message3 = new Message();
+
+            message1.Priority = 1;
+            message2.Priority = 2;
+            message3.Priority = 3;
+
+            dispatch1.Message = message1;
+            dispatch2.Message = message2;
+            dispatch3.Message = message3;
+
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+        
+            DateTime timeStarted = DateTime.Now;
+        
+            Assert.IsTrue( channel.Dequeue(TimeSpan.FromMilliseconds(1000)) == null );
+
+            DateTime timeFinished = DateTime.Now;
+
+            TimeSpan elapsed = timeFinished - timeStarted;
+            Assert.IsTrue( elapsed.TotalMilliseconds >= 999 );
+        
+            channel.Enqueue( dispatch1 );
+            channel.Enqueue( dispatch2 );
+            channel.Enqueue( dispatch3 );
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 3 );
+            Assert.IsTrue( channel.Dequeue( TimeSpan.FromMilliseconds(Timeout.Infinite) )
== dispatch3 );
+            Assert.IsTrue( channel.Dequeue( TimeSpan.Zero ) == dispatch2 );
+            Assert.IsTrue( channel.Dequeue( TimeSpan.FromMilliseconds(1000) ) == dispatch1
);
+        
+            Assert.IsTrue( channel.Count == 0 );
+            Assert.IsTrue( channel.Empty == true );
+        }
+        
+        [Test]
+        public void TestRemoveAll() 
+        {
+            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
+        
+            MessageDispatch dispatch1 = new MessageDispatch();
+            MessageDispatch dispatch2 = new MessageDispatch();
+            MessageDispatch dispatch3 = new MessageDispatch();
+
+            Message message1 = new Message();
+            Message message2 = new Message();
+            Message message3 = new Message();
+
+            message1.Priority = 1;
+            message2.Priority = 2;
+            message3.Priority = 3;
+
+            dispatch1.Message = message1;
+            dispatch2.Message = message2;
+            dispatch3.Message = message3;
+
+            channel.Enqueue( dispatch1 );
+            channel.Enqueue( dispatch2 );
+            channel.Enqueue( dispatch3 );
+        
+            channel.Start();
+            Assert.IsTrue( channel.Running == true );
+            Assert.IsTrue( channel.Empty == false );
+            Assert.IsTrue( channel.Count == 3 );
+            Assert.IsTrue( channel.RemoveAll().Length == 3 );
+            Assert.IsTrue( channel.Count == 0 );
+            Assert.IsTrue( channel.Empty == true );
+        }
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Util/SimplePriorityMessageDispatchChannelTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message