Пример #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.
        }
Пример #2
0
        public void RemoveTest()
        {
            BenchmarkSystem target = BenchmarkSystem.instance;
            Job             job    = new Job("Remove test 1", owner, 3, 767);
            Job             job2   = new Job("Remove test 2", owner, 4, 2);

            target.Submit(job);
            target.Submit(job2);
            target.Remove(job);
            Assert.IsTrue(!target.Contains(job));
        }
Пример #3
0
        static void Main(string[] args)
        {
            Random          random = new Random();
            BenchmarkSystem system = BenchmarkSystem.instance;

            int   id        = 0;
            long  timestamp = System.DateTime.Now.Ticks;
            Owner me        = new Owner("Test");
            Timer timer1    = new Timer(((e) => { Console.Clear(); Console.WriteLine(BenchmarkSystem.instance.Status()); }), null, 0, 200);

            while (true)
            {
                while (BenchmarkSystem.instance.TotalNumberOfJobs() < 100)
                {
                    Job job = new Job("ConsoleJob" + id++, me, (byte)(random.Next(9) + 1), (float)(random.NextDouble() * 4.9 + 0.1));
                    job.process = (a) => {
                        //Console.WriteLine("Job "+job.name+" runs and runs");
                        Thread.Sleep((int)job.ExpectedRuntime * 1000);
                        //Console.WriteLine("Job " + job.name + " finished");
                        return("");
                    };
                    system.Submit(job);
                }
                system.ExecuteAll();
            }
        }
Пример #4
0
        public void TotalNumberOfJobsTest()
        {
            BenchmarkSystem target = BenchmarkSystem.instance;

            // Empty queues
            target.ExecuteAll();

            // Add jobs and assert
            uint max = 10;

            Job[] jobs = new Job[max];
            Assert.AreEqual((uint)0, target.TotalNumberOfJobs());
            for (uint i = 1; i <= max; i++)
            {
                Job job = new Job("TotalNumberOfJobs test " + i, null, 1, i);
                jobs[i - 1] = job;
                target.Submit(job);
                Assert.AreEqual(i, target.TotalNumberOfJobs());
            }

            // Remove jobs and assert
            for (uint i = max - 1; i > 0; i--)
            {
                target.Remove(jobs[i]);
                Assert.AreEqual(i, target.TotalNumberOfJobs());
            }
        }
Пример #5
0
        public void SubmitTest()
        {
            BenchmarkSystem target = BenchmarkSystem.instance;
            Job             job    = new Job("Submit test", null, 1, 1);

            target.Submit(job);
            Assert.IsTrue(target.Contains(job));
        }
Пример #6
0
        public void TestInitialize()
        {
            BenchmarkSystem bs = BenchmarkSystem.instance;

            BenchmarkSystem.db = null;
            owner1             = new Owner("DatabaseFunctions Owner1");
            owner2             = new Owner("DatabaseFunctions Owner2");
            j1             = new Job("DatabaseFunctions Job1", owner1, 4, (float)0.39919712943919); //Short
            j2             = new Job("DatabaseFunctions Job2", owner2, 9, (float)2.6312117980473);  //Very long
            j3             = new Job("DatabaseFunctions Job3", owner2, 7, (float)4.7457466516857);  //Very long
            j4             = new Job("DatabaseFunctions Job4", owner1, 8, (float)3.7855014080114);  //Very long
            j5             = new Job("DatabaseFunctions Job5", owner1, 2, (float)1.0786302726616);  //Long
            j6             = new Job("DatabaseFunctions Job6", owner2, 6, (float)4.3559041917584);  //Very long
            j7             = new Job("DatabaseFunctions Job7", owner1, 1, (float)2.0657835664068);  //Very long
            j8             = new Job("DatabaseFunctions Job8", owner1, 3, (float)2.2463377728808);  //Very long
            j9             = new Job("DatabaseFunctions Job9", owner2, 4, (float)2.0612939639768);  //Very long
            j10            = new Job("DatabaseFunctions Job10", owner2, 5, (float)4.1729730872777); //Very long
            timestampStart = System.DateTime.Now.Ticks;
            bs.Submit(j1);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j2);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j3);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j4);
            System.DateTime newTimestamp = System.DateTime.Now;
            newTimestamp = newTimestamp.AddDays(-2);
            j4.timestamp = newTimestamp.Ticks;
            BenchmarkSystem.db.SaveChanges();
            System.Threading.Thread.Sleep(1);
            bs.Submit(j5);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j6);
            j6.State     = Job.JobState.Failed;
            timestampEnd = System.DateTime.Now.Ticks;
            System.Threading.Thread.Sleep(1);
            bs.Submit(j7);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j8);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j9);
            System.Threading.Thread.Sleep(1);
            bs.Submit(j10);
            System.Threading.Thread.Sleep(1);
        }
Пример #7
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);
        }
Пример #8
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);
 }
Пример #9
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);
 }
Пример #10
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());
        }
Пример #11
0
        public void QueuedTest()
        {
            BenchmarkSystem target = BenchmarkSystem.instance;

            target.JobQueued += new EventHandler <JobEventArgs>(EventCalled);
            Job job = new Job("Queued test", null, 1, 1);

            EventCalledBool = false;
            target.Submit(job);
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(EventCalledBool);
            Assert.AreEqual(JobEventArgs.EventType.JobQueued, eventType);
            EventCalledBool   = false;
            target.JobQueued -= new EventHandler <JobEventArgs>(EventCalled);
        }
Пример #12
0
        public void ContainsTest()
        {
            BenchmarkSystem target = BenchmarkSystem.instance;

            // Add jobs and assert
            uint max = 10;

            Job[] jobs = new Job[max];
            for (uint i = 1; i <= max; i++)
            {
                Job job = new Job("Contains test " + i, null, 1, i);
                jobs[i - 1] = job;
                target.Submit(job);
                Assert.IsTrue(target.Contains(job));
            }
            // Remove jobs and assert
            for (uint i = max - 1; i > 0; i--)
            {
                target.Remove(jobs[i]);
                Assert.IsFalse(target.Contains(jobs[i]));
            }
        }
Пример #13
0
        public void TestSubmit()
        {
            system.Submit(Job1);
            system.Submit(Job2);
            system.Submit(Job3);
            system.Submit(Job4);

            Job[] Jobs = scheduler.GetJobs();
            Assert.AreEqual("job2", Jobs[0].ToString(), "Job2 did not match");
            Assert.AreEqual("job3", Jobs[1].ToString(), "Job3 did not match");
            Assert.AreEqual("job4", Jobs[2].ToString(), "Job4 did not match");
            Assert.AreEqual("job1", Jobs[3].ToString(), "Job1 did not match");
        }
Пример #14
0
        public void TestSubmit()
        {
            system.Submit(job1);
            system.Submit(job2);
            system.Submit(job3);
            system.Submit(job4);

            Job[] jobs = scheduler.GetJobs();
            Assert.AreEqual("4,5,Michael", jobs[0].ToString(), "Job2 did not match");
            Assert.AreEqual("1,5,Michael", jobs[1].ToString(), "Job3 did not match");
            Assert.AreEqual("6,10,Michael", jobs[2].ToString(), "Job4 did not match");
            Assert.AreEqual("4,40,Michael", jobs[3].ToString(), "Job1 did not match");
        }