public void Test_AddJob() { BenchmarkSystem.Scheduler s = new BenchmarkSystem.Scheduler(); // Add legal jobs with the three types: SHORT, LONG, VERY_LONG Job shortJob = new Job(new Owner("test"), 25); Job longJob = new Job(new Owner("test"), 115); Job veryLongJob = new Job(new Owner("test"), 500); s.AddJob(shortJob); s.AddJob(longJob); s.AddJob(veryLongJob); Assert.AreEqual(3, s.JobsInSequence.Count); // Add 5000 jobs of varying type for (uint i = 0; i < 5000; i++) { s.AddJob(new Job(new Owner("test"), i)); } Assert.AreEqual(5003, s.JobsInSequence.Count); }
public void Test_IsSlotAvailable() { BenchmarkSystem.Scheduler s = new BenchmarkSystem.Scheduler(); // With no running jobs, should return true Assert.IsTrue(s.IsSlotAvailable()); //// Below is meant for when threads are introduced to the program //// When at maximum simultaneous running jobs, should return false //for (int i = 0; i < 21; i++) //{ // s.AddJob(new Job(new Owner("test" + i), 10)); // s.AddJob(new Job(new Owner("test" + i), 100)); // s.AddJob(new Job(new Owner("test" + i), 500)); //} //for (int i = 0; i < 20; i++) //{ // Job job = s.PopJob(); // job.Process(new String[] { "Test", "stuff" }); //} //Assert.AreEqual(false, s.IsSlotAvailable()); }
public void Test_PopJob() { BenchmarkSystem.Scheduler s = new BenchmarkSystem.Scheduler(); // Check the sequence og jobs returned Job shortJob = new Job(new Owner("test"), 25); Job longJob = new Job(new Owner("test"), 115); Job veryLongJob = new Job(new Owner("test"), 500); // short, long, verylong AssertSequence(s, shortJob, longJob, veryLongJob); // long, short, verylong AssertSequence(s, longJob, shortJob, veryLongJob); // long, verylong, short AssertSequence(s, longJob, veryLongJob, shortJob); // short, verylong, long AssertSequence(s, shortJob, veryLongJob, longJob); // verylong, short, long AssertSequence(s, veryLongJob, shortJob, longJob); // verylong, long, short AssertSequence(s, veryLongJob, longJob, shortJob); // Pop a job when there are none in the scheduler try { s.PopJob(); Assert.Fail("It was possible to pop a job when there were no jobs to pop"); } catch (JobsDepletedException) { // This is good } //// Below is meant for when threads are introduced to the program //// Pop a job when at maximum simultaneous running jobs //for (int i = 0; i < 21; i++) //{ // s.AddJob(new Job(new Owner("test" + i), 10)); // s.AddJob(new Job(new Owner("test" + i), 100)); // s.AddJob(new Job(new Owner("test" + i), 500)); //} //// Start 60 jobs, leaving 3 untouched in scheduler //for (int i = 0; i < 60; i++) //{ // Job job = s.PopJob(); // job.Process(new String[]{"Test", "stuff"}); //} //try //{ // s.PopJob(); // Assert.Fail("It was possible to pop a job from scheduler even though the maximum simultaneously running jobs were reached"); //} //catch (InvalidOperationException) //{ // // This is good //} }
public void Test_RemoveJob() { BenchmarkSystem.Scheduler s = new BenchmarkSystem.Scheduler(); Job job = new Job(new Owner("test"), 20); s.AddJob(job); // Try to remove null try { s.RemoveJob(null); Assert.Fail("It was possible to remove a \"null\" job"); } catch (ArgumentNullException) { // This is good } // Try to remove job not in scheduler Job phonyJob = new Job(new Owner("test"), 50); try { s.RemoveJob(phonyJob); Assert.Fail("It was possible to remove a job not in the scheduler"); } catch (ArgumentException) { // This is good } // Remove a job in the scheduler s.RemoveJob(job); Assert.AreEqual(0, s.JobsInSequence.Count); }