Example #1
0
        public void ReturnTaskConditionAndQueueTaskWithoutNormalPriorityTest()
        {
            var taskSheduler = new HCTaskScheduler();

            taskSheduler.Initialize(3);

            foreach (var task in _GetTestDataWithoutNormalPriority(timeoutTypeOfWork))
            {
                taskSheduler.Schedule(task);
            }

            var _currenTasksList = GetField <ConcurrentDictionary <int, Task <IHCTask> > >("_currenTasksList", taskSheduler);
            var ll = _currenTasksList.Keys.ToArray();

            Assert.AreEqual(ll[0], 1);
            Assert.AreEqual(ll[1], 2);
            Assert.AreEqual(ll[2], 3);

            Thread.Sleep(110);
            ll = _currenTasksList.Keys.ToArray();

            Assert.AreEqual(ll[0], 4);
            Assert.AreEqual(ll[1], 6);
            Assert.AreEqual(ll[2], 8);

            taskSheduler.Stop();
        }
Example #2
0
        static void Main(string[] args)
        {
            int  maxNumberOfTasksAtSameTime = 0;
            int  timeoutTypeOfWork          = 1000;
            bool isNotAccept = true;

            Print.PrintEndTask = true;

            Console.WriteLine("Enter max number of tasks at same time: ");

            while (isNotAccept)
            {
                if (int.TryParse(Console.ReadLine(), out maxNumberOfTasksAtSameTime))
                {
                    isNotAccept = false;
                }
                else
                {
                    Console.WriteLine("Incorrect!");
                }
            }

            var taskSheduller = new HCTaskScheduler();

            taskSheduller.Initialize(maxNumberOfTasksAtSameTime);

            foreach (var task in HCTask.GetTestData(timeoutTypeOfWork))
            {
                taskSheduller.Schedule(task);
            }

            Console.ReadLine();
        }
Example #3
0
        public void MaxNumberOfTasksAtSameTimeTest(int maxNumberOfTasksAtSameTime)
        {
            var taskSheduler = new HCTaskScheduler();

            taskSheduler.Initialize(maxNumberOfTasksAtSameTime);

            foreach (var task in _GetTestDataWithNormalPriority(timeoutTypeOfWork))
            {
                taskSheduler.Schedule(task);
            }

            FieldInfo fieldInfo        = typeof(HCTaskScheduler).GetField("_currenTasksList", BindingFlags.Instance | BindingFlags.NonPublic);
            var       _currenTasksList = (ConcurrentDictionary <int, Task <IHCTask> >)fieldInfo.GetValue(taskSheduler);

            Assert.AreEqual(_currenTasksList.Count(), maxNumberOfTasksAtSameTime);
        }
Example #4
0
        public void StopTest()
        {
            var taskSheduler = new HCTaskScheduler();

            taskSheduler.Initialize(4);

            foreach (var task in _GetTestDataWithNormalPriority(timeoutTypeOfWork))
            {
                taskSheduler.Schedule(task);
            }
            var task1 = taskSheduler.Stop();

            task1.Wait();

            var _queue1 = GetField <Queue <(IHCTask, Task <IHCTask>)> >("_highQueue", taskSheduler);
            var _queue2 = GetField <Queue <(IHCTask, Task <IHCTask>)> >("_normalQueue", taskSheduler);
            var _queue3 = GetField <Queue <(IHCTask, Task <IHCTask>)> >("_lowQueue", taskSheduler);

            Assert.IsTrue(!_queue1.Any());
            Assert.IsTrue(!_queue2.Any());
            Assert.IsTrue(!_queue3.Any());
        }