예제 #1
0
        public void FactoryShouldCreateTaskManagersWithTheGivenSize(int size)
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(taskManagerSize: size);

            for (var i = 0; i < size; i++)
            {
                taskManager.Add(new ProcessDto(Priority.Low));
            }
            var isAdded = taskManager.Add(new ProcessDto(Priority.Low));

            Assert.Null(isAdded);
        }
예제 #2
0
        public void FactoryShouldCreateTaskManagersWithDefaultSize()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager();

            for (var i = 0; i < TaskManagerFactory.TaskManagerSize; i++)
            {
                taskManager.Add(new ProcessDto(Priority.Low));
            }

            var isAdded = taskManager.Add(new ProcessDto(Priority.Low));

            Assert.Null(isAdded);
        }
예제 #3
0
        private void KillShouldRemoveTheProcessFromTaskManager()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(taskManagerSize: 2);
            var process     = taskManager.Add(new ProcessDto(Priority.Low));

            var killed = taskManager.Kill(process.PID);

            Assert.True(killed);

            var processlist = taskManager.List();

            Assert.Null(processlist.FirstOrDefault(m => m.PID == process.PID));
        }
예제 #4
0
        public void TaskManagerOverFlow()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(taskManagerSize: 2);

            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Low));
            var isAdded = taskManager.Add(new ProcessDto(Priority.Low));

            Assert.Null(isAdded);

            var itemCount = taskManager.List().ToList().Count;

            Assert.True(itemCount == 2);
        }
예제 #5
0
        public void FifoTaskManagerOverFlow()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(CustomerName, 2);

            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Low));

            var isAdded = taskManager.Add(new ProcessDto(Priority.Low));

            Assert.NotNull(isAdded);

            var itemCount = taskManager.List().ToList().Count;

            Assert.True(2 == itemCount);
        }
예제 #6
0
        public void TaskListShouldBeOrderedByPriority()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager();
            var pLow        = taskManager.Add(new ProcessDto(Priority.Low));

            var pHigh = taskManager.Add(new ProcessDto(Priority.High));

            var pMedium = taskManager.Add(new ProcessDto(Priority.Medium));

            var items = taskManager.List(m => m.Priority).ToList();

            Assert.Equal(items[0].PID, pLow.PID);
            Assert.Equal(items[1].PID, pMedium.PID);
            Assert.Equal(items[2].PID, pHigh.PID);
        }
예제 #7
0
        public void TaskListShouldBeOrderedByCreationDate()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager();
            var p1          = taskManager.Add(new ProcessDto(Priority.Low));

            var p2 = taskManager.Add(new ProcessDto(Priority.High));

            var p3 = taskManager.Add(new ProcessDto(Priority.Medium));

            var items = taskManager.List().ToList();

            Assert.Equal(items[0].PID, p1.PID);
            Assert.Equal(items[1].PID, p2.PID);
            Assert.Equal(items[2].PID, p3.PID);
        }
예제 #8
0
        public void PriorityQueueWithLowPriority()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(CustomerName, 2);
            var p1          = new ProcessDto(Priority.Low);

            taskManager.Add(p1);
            taskManager.Add(new ProcessDto(Priority.Low));

            var isAdded = taskManager.Add(new ProcessDto(Priority.Medium));

            Assert.NotNull(isAdded);

            var processList = taskManager.List();

            Assert.Null(processList.FirstOrDefault(m => m.PID == p1.PID));
        }
예제 #9
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hi, this is the task manager!");

            try
            {
                Console.WriteLine("Please select Customer Type: F for Fifo / P for Priority / D for Default");
                var customerType = Console.ReadLine();
                var taskManager  = TaskManagerFactory.CreateTaskManager(customerType);


                PrintMenu();
                var command = Console.ReadLine()?.ToUpper();

                while (command != "E")
                {
                    switch (command)
                    {
                    case "A":
                        NewProcess(taskManager);
                        break;

                    case "L":
                        ListProcesses(taskManager);
                        break;

                    case "K":
                        KillProcess(taskManager);
                        break;

                    default:
                        Console.WriteLine("Wrong command.");
                        break;
                    }

                    PrintMenu();
                    command = Console.ReadLine();
                }

                Console.WriteLine("Bye!");
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #10
0
        private void KillByPriorityShouldRemoveTheProcessFromTaskManager(Priority priority)
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(taskManagerSize: 6);

            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Medium));
            taskManager.Add(new ProcessDto(Priority.Medium));
            taskManager.Add(new ProcessDto(Priority.High));
            taskManager.Add(new ProcessDto(Priority.High));

            var killed = taskManager.KillByPriority(priority);

            Assert.True(killed);

            var processlist = taskManager.List();

            Assert.Null(processlist.FirstOrDefault(m => m.Priority == priority));
        }
예제 #11
0
        private void KillAllShouldRemoveAllTheTaskFromTaskManager()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(taskManagerSize: 6);

            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Low));
            taskManager.Add(new ProcessDto(Priority.Medium));
            taskManager.Add(new ProcessDto(Priority.Medium));
            taskManager.Add(new ProcessDto(Priority.High));
            taskManager.Add(new ProcessDto(Priority.High));

            var killed = taskManager.KillAll();

            Assert.True(killed);

            var processlist = taskManager.List();

            Assert.False(processlist.Any());
        }
예제 #12
0
        public void PriorityQueueWithHighPriority()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(CustomerName, 2);
            var pLowOld     = new ProcessDto(Priority.Low);
            var pHigh       = new ProcessDto(Priority.High);
            var pMedium     = new ProcessDto(Priority.Medium);
            var pLowNew     = new ProcessDto(Priority.Low);

            taskManager.Add(pLowOld);
            taskManager.Add(pHigh);
            taskManager.Add(pLowNew);

            var isAdded = taskManager.Add(pMedium);

            Assert.NotNull(isAdded);

            var processList = taskManager.List();

            Assert.Null(processList.FirstOrDefault(m => m.PID == pLowOld.PID));
        }
예제 #13
0
        public void FifoTaskManagerOverFlowOldestWillBeKilled()
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(CustomerName, 2);
            var p1          = new ProcessDto(Priority.Low);
            var p2          = new ProcessDto(Priority.Low);
            var p3          = new ProcessDto(Priority.Low);

            taskManager.Add(p1);
            taskManager.Add(p2);
            taskManager.Add(p3);

            var processList = taskManager.List(m => m.CreateDate);

            Assert.Null(processList.FirstOrDefault(m => m.PID == p1.PID));

            var p4 = new ProcessDto(Priority.Low);

            taskManager.Add(p4);
            processList = taskManager.List(m => m.CreateDate);
            Assert.Null(processList.FirstOrDefault(m => m.PID == p2.PID));
        }
예제 #14
0
        public void FactoryShouldCreateTaskManagersBasedOnCustomer(string customer, Type typeOfTaskManager)
        {
            var taskManager = TaskManagerFactory.CreateTaskManager(customer);

            Assert.Equal(typeOfTaskManager, taskManager.GetType());
        }