public void TestDontRunAtFirstIfCoresNotAvailable() { BenchmarkSystem Bs = new BenchmarkSystem(); //jobs that needs in all 27 cpus, should execute with no problems. Job job1 = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten12"), 9, 10000); Job job2 = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten22"), 9, 10000); Job job3 = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten32"), 9, 10000); Bs.Submit(job1); Bs.Submit(job2); Bs.Submit(job3); //this job requires too many cores and should therefore not run immediately Job job4 = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten4"), 9, 10000); Bs.Submit(job4); Task task = Task.Factory.StartNew(() => Bs.ExecuteAll()); Thread.Sleep(1000); Assert.AreEqual(State.Running, job1.State); Assert.AreEqual(State.Running, job2.State); Assert.AreEqual(State.Running, job3.State); // this job should not be running as there aren't enough cores for it to run. Assert.AreEqual(State.Submitted, job4.State); //it should run after the cores become available Thread.Sleep(12000); Assert.AreEqual(State.Running, job4.State); // NOTE: this test fails because the first three submitted jobs dont run simultaneusly. The factory method of Task should run them in separate threads, but somehow choses to // run them chronological instead. Maybe you can explain why? Thank you in advance. }
public void changeState() { BenchmarkSystem BS = new BenchmarkSystem(); Job job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("tester"), 3, 35); BS.Submit(job); BS.changeState(job, State.Running); Assert.IsTrue(job.State == State.Running); }
public void TestDontRunWithTooManyCores() { BenchmarkSystem Bs = new BenchmarkSystem(); //job that requires 50 cores, should not get the state terminated. And should throw exception before that. Job job2 = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten"), 50, 1); Assert.AreEqual(State.Created, job2.State); Bs.Submit(job2); Task task2 = Task.Factory.StartNew(() => Bs.ExecuteAll()); Thread.Sleep(50); Assert.AreNotEqual(State.Terminated, job2.State); }
public void TestDontRunIfCoresNotAvailable() { BenchmarkSystem Bs = new BenchmarkSystem(); //job that needs 3 cpus, should execute with no problems. Job job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("morten"), 3, 1); Assert.AreEqual(State.Created, job.State); Bs.Submit(job); Task task = Task.Factory.StartNew(() => Bs.ExecuteAll()); Thread.Sleep(50); Assert.AreEqual(State.Terminated, job.State); }
public void TestSubmit() { BenchmarkSystem BS = new BenchmarkSystem(); Job job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("tester"), 3, 35); Assert.AreEqual(0, BS.Status.Count); Assert.IsTrue(BS.scheduler.Empty()); BS.Submit(job); Assert.AreEqual(1, BS.Status.Count); Assert.IsTrue(BS.Status.Contains(job)); Assert.IsFalse(BS.scheduler.Empty()); }
static void Main(String[] args) { BenchmarkSystem system = new BenchmarkSystem(); // get the logger to subscribe to BenchmarkSystem system.StateChanged += Logger.OnStateChanged; Job job1 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner1"), 2, 45); Job job2 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner2"), 2, 3); Job job3 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner3"), 2, 200); Job job4 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner4"), 2, 3); Job job5 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner5"), 2, 45); Job job6 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner6"), 2, 200); Job job7 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner7"), 2, 45); Job job8 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner8"), 2, 45); Job job9 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner9"), 2, 200); Job job10 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner10"), 2, 3); Job job11 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner11"), 2, 45); Job job12 = new Job((string[] arg) => { foreach (string s in arg) { Console.Out.WriteLine(s); } return(""); }, new Owner("owner12"), 2, 200); system.Submit(job1); system.Submit(job2); system.Submit(job3); system.Submit(job4); system.Submit(job5); system.Submit(job6); system.Submit(job7); system.Submit(job8); system.Submit(job9); system.Submit(job10); system.Submit(job11); system.Submit(job12); system.ExecuteAll(); Job job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("tester"), 3, 35); //Console.WriteLine(job); }