Esempio n. 1
0
        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.
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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());
        }
        public void TestUpdateStatus()
        {
            BenchmarkSystem BS = new BenchmarkSystem();

            // tatus should have 0 elements in its set to begin with
            Assert.AreEqual(0, BS.Status.Count);

            Job job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("tester"), 3, 35);

            // submit job - Status should have 1 element in its set
            job.State = State.Submitted;
            BS.updateStatus(job);
            Assert.AreEqual(1, BS.Status.Count);

            // cancel job - Status should have 0 elements in its set
            job.State = State.Cancelled;
            BS.updateStatus(job);
            Assert.AreEqual(0, BS.Status.Count);

            // add again
            job.State = State.Submitted;
            BS.updateStatus(job);
            Assert.AreEqual(1, BS.Status.Count);

            // run it - Status shouldn't change
            job.State = State.Running;
            BS.updateStatus(job);
            Assert.AreEqual(1, BS.Status.Count);

            // fail it - Status should have 0 elements
            job.State = State.Failed;
            BS.updateStatus(job);
            Assert.AreEqual(0, BS.Status.Count);

            // add again
            job.State = State.Submitted;
            BS.updateStatus(job);
            Assert.AreEqual(1, BS.Status.Count);

            // terminate it - Status should have 0 elements
            job.State = State.Terminated;
            BS.updateStatus(job);
            Assert.AreEqual(0, BS.Status.Count);
        }
Esempio n. 7
0
        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);
             */

            Simulator sim = new Simulator(system.scheduler);

            Task.Factory.StartNew(() => sim.run());

            system.ExecuteAll();

            Console.ReadKey();
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        public void setup()
        {
            BS  = new BenchmarkSystem();
            sch = BS.scheduler;

            j1 = new Job(
                (string[] arg) =>
            {
                foreach (string s in arg)
                {
                    Console.Out.WriteLine(s);
                }
                ; return("");
            },
                new Owner("one"),
                1,   // Cpus needed
                1000 // Runtime (in milliseconds)
                );

            delayedJob = new Job(
                (string[] arg) =>
            {
                foreach (string s in arg)
                {
                    Console.Out.WriteLine(s);
                }
                ; return("");
            },
                new Owner("delayed"),
                3,   // Cpus needed
                1000 // Runtime (in milliseconds)
                );

            j3 = new Job(
                (string[] arg) =>
            {
                foreach (string s in arg)
                {
                    Console.Out.WriteLine(s);
                }
                ; return("");
            },
                new Owner("three"),
                1,   // Cpus needed
                1000 // Runtime (in milliseconds)
                );

            j4 = new Job(
                (string[] arg) =>
            {
                foreach (string s in arg)
                {
                    Console.Out.WriteLine(s);
                }
                ; return("");
            },
                new Owner("four"),
                1,   // Cpus needed
                1000 // Runtime (in milliseconds)
                );

            j5 = new Job(
                (string[] arg) =>
            {
                foreach (string s in arg)
                {
                    Console.Out.WriteLine(s);
                }
                ; return("");
            },
                new Owner("five"),
                1,   // Cpus needed
                1000 // Runtime (in milliseconds)
                );

            // remove old jobs from the static scheduler
            while (!sch.Empty())
            {
                sch.popJob(10);
            }

            // add them again

            sch.addJob(j1);
            sch.addJob(delayedJob);
            sch.addJob(j3);
            sch.addJob(j4);
            sch.addJob(j5);
        }
Esempio n. 10
0
 public void setup()
 {
     BenchmarkSystem BS  = new BenchmarkSystem();
     Job             job = new Job((string[] arg) => { return(arg.Length.ToString()); }, new Owner("tester"), 3, 35);
 }