activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1032572 - /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs
Date Mon, 08 Nov 2010 14:02:08 GMT
Author: tabish
Date: Mon Nov  8 14:02:07 2010
New Revision: 1032572

URL: http://svn.apache.org/viewvc?rev=1032572&view=rev
Log:
Add the test case for the CompositeTaskRunner class.

Added:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs
  (with props)

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs?rev=1032572&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Threads/CompositeTaskRunnerTest.cs
Mon Nov  8 14:02:07 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.Threading;
+using Apache.NMS.Stomp.Threads;
+using NUnit.Framework;
+
+namespace Apache.NMS.Stomp.Test.Threads
+{
+    [TestFixture]
+    public class CompositeTaskRunnerTest
+    {
+
+        class CountingTask : CompositeTask
+        {
+            private int count;
+            private int goal;
+            private string name;
+
+            public CountingTask( string name, int goal )
+            {
+                this.name = name;
+                this.goal = goal;
+            }
+
+            public string Name
+            {
+                get { return name; }
+            }
+
+            public int Count
+            {
+                get { return count; }
+            }
+
+            public bool IsPending
+            {
+                get { return count != goal; }
+            }
+
+            public bool Iterate()
+            {
+                return !( ++count == goal );
+            }
+        }
+
+        [Test]
+        public void TestCompositeTaskRunner()
+        {
+
+            int attempts = 0;
+
+            CompositeTaskRunner runner = new CompositeTaskRunner();
+
+            CountingTask task1 = new CountingTask("task1", 100);
+            CountingTask task2 = new CountingTask("task2", 200);
+
+            runner.AddTask( task1 );
+            runner.AddTask( task2 );
+
+            runner.Wakeup();
+
+            while( attempts++ != 10 )
+            {
+                Thread.Sleep( 1000 );
+
+                if(task1.Count == 100 && task2.Count == 200)
+                {
+                    break;
+                }
+            }
+
+            Assert.IsTrue(task1.Count == 100);
+            Assert.IsTrue(task2.Count == 200);
+
+            runner.RemoveTask(task1);
+            runner.RemoveTask(task2);
+        }
+    }
+}

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



Mime
View raw message