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 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());
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Starts listens to events
 /// </summary>
 /// <param name="system">The system to "listen" to</param>
 public void subscribe(BenchmarkSystem.BenchmarkSystem system)
 {
     system.JobSubmitted		+= onJobSubmit;
     system.JobCancelled		+= onJobCancel;
     system.JobRunning		+= onJobRun;
     system.JobTerminated	+= onJobTerminate;
     system.JobFailed		+= onJobFail;
 }
Esempio n. 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));
        }
Esempio n. 6
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. 7
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. 8
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));
        }
Esempio n. 9
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. 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());
        }
Esempio n. 11
0
        public void OnJobTerminatedTest()
        {
            EventCalledBool = false;
            BenchmarkSystem target = BenchmarkSystem.instance;

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

            target.OnJobTerminated(job);
            Assert.IsTrue(EventCalledBool);
            Assert.AreEqual(JobEventArgs.EventType.JobTerminated, eventType);
            EventCalledBool       = false;
            target.JobTerminated -= new EventHandler <JobEventArgs>(EventCalled);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        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. 15
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]));
            }
        }
Esempio n. 16
0
 public void setup()
 {
     BenchmarkSystem BS = new BenchmarkSystem();
     Job job = new Job((string[] arg) => { return arg.Length.ToString(); }, new Owner("tester"), 3, 35);
 }
Esempio n. 17
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. 18
0
 public ClientSimulation(BenchmarkSystem bs)
 {
     this.bs = bs;
 }
Esempio n. 19
0
        public void TestInitialize()
        {
            BenchmarkSystem bs = BenchmarkSystem.instance;

            BenchmarkSystem.db = null;
        }
Esempio n. 20
0
 public Logger(BenchmarkSystem.BenchmarkSystem system)
 {
     subscribe(system);
 }