public void FindById_ThreadExecutor_ShouldWorkCorrectly() { //Arrange IScheduler executor = new ThreadExecutor(); Task task1 = new Task(5, 6, Priority.HIGH); Task task2 = new Task(6, 2, Priority.LOW); Task task3 = new Task(7, 4, Priority.LOW); Task task4 = new Task(0, 56, Priority.EXTREME); Task task5 = new Task(0, 56, Priority.EXTREME); //Act executor.Execute(task1); executor.Execute(task2); executor.Execute(task3); executor.Execute(task4); Task result1 = executor.GetById(5); Task result2 = executor.GetById(6); Task result3 = executor.GetById(7); Task result4 = executor.GetById(0); //Assert Assert.AreSame(result1, task1); Assert.AreSame(result2, task2); Assert.AreSame(result3, task3); Assert.AreSame(result4, task4); Assert.AreNotSame(result4, task5); }
public void Cycle_ThreadExecutor_ShouldWorkCorrectly() { //Arange IScheduler executor = new ThreadExecutor(); Task task1 = new Task(5, 5, Priority.HIGH); Task task2 = new Task(6, 5, Priority.LOW); Task task3 = new Task(7, 12, Priority.MEDIUM); Task task4 = new Task(12, 5, Priority.HIGH); Task task5 = new Task(15, 3, Priority.LOW); Task task6 = new Task(19, 2, Priority.LOW); //Act executor.Execute(task1); executor.Execute(task2); executor.Execute(task3); executor.Execute(task4); executor.Execute(task5); executor.Execute(task6); Assert.AreEqual(6, executor.Count); executor.Cycle(3); Assert.AreEqual(4, executor.Count); Assert.Throws <ArgumentException>(() => executor.GetById(19)); Assert.Throws <ArgumentException>(() => executor.GetById(15)); executor.Cycle(5); //Assert Assert.AreEqual(1, executor.Count); Task t = executor.GetByIndex(0); Assert.AreSame(task3, t); Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(1)); }
public void FindById_ThreadExecutor_ShouldWorkFast() { // Arrange IScheduler executor = new ThreadExecutor(); const int count = 100000; LinkedList <Task> tasks = new LinkedList <Task>(); for (int i = 0; i < count; i++) { tasks.AddLast(new Task(i + 1, i, Priority.HIGH)); executor.Execute(tasks.Last.Value); } // Act Stopwatch sw = Stopwatch.StartNew(); LinkedListNode <Task> node = tasks.First; while (node != null) { Assert.AreSame(node.Value, executor.GetById(node.Value.Id)); node = node.Next; } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 250); }
public void FindById_ThreadExecutor_OnNonExistingId_ShouldThrow() { //Arrange IScheduler executor = new ThreadExecutor(); Task task1 = new Task(5, 6, Priority.HIGH); Task task2 = new Task(6, 2, Priority.LOW); Task task3 = new Task(7, 4, Priority.LOW); Task task4 = new Task(0, 56, Priority.EXTREME); Task task5 = new Task(0, 56, Priority.EXTREME); //Act executor.Execute(task1); executor.Execute(task2); executor.Execute(task3); executor.Execute(task4); //Assert Assert.AreEqual(4, executor.Count); Assert.Throws <ArgumentException>(() => executor.GetById(12)); }