Пример #1
0
 public void AddJobTest()
 {
     Owner owner = new Owner("Testuser"+userId++);
       Scheduler target = new Scheduler();
       Job job = new Job("AddJob Test", owner, 6, 4);
       target.AddJob(job);
      Job job2 = target.PopJob();
       Assert.AreSame(job, job2);
 }
Пример #2
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();
              }
        }
Пример #3
0
 public void ToStringTest()
 {
     Owner owner = new Owner("Test owner");
       byte CPU = 3;
       uint ExpectedRuntime = 42;
       Job target = new Job("ToString Test", owner, CPU, ExpectedRuntime);
       string actual = target.ToString();
       Assert.IsTrue(target.ToString().Contains(owner.Name));
       Assert.IsTrue(target.ToString().Contains("42"));
       Assert.IsTrue(target.ToString().Contains("3"));
       Assert.IsTrue(target.ToString().Contains("Created"));
 }
Пример #4
0
 public void ownerTest3()
 {
     Owner owner = new Owner("Some owner");
       byte CPU = 1;
       uint ExpectedRuntime = 0;
       Job target = new Job("Owner Test 3", owner, CPU, ExpectedRuntime);
       Owner shouldfail = new Owner("Test owner");
       Owner actual;
       actual = target.owner;
       Assert.AreNotEqual(shouldfail, actual);
 }
Пример #5
0
 public void ownerTest2()
 {
     Owner owner = new Owner("Some owner");
       byte CPU = 1;
       uint ExpectedRuntime = 0;
       Job target = new Job("Owner test 2", owner, CPU, ExpectedRuntime);
       Owner expected = new Owner("Some owner");
       Owner actual;
       target.owner = expected;
       actual = target.owner;
       Assert.AreEqual(expected, actual);
 }
Пример #6
0
 public void JobConstructorTest()
 {
     Owner owner = new Owner("Test owner");
       byte CPU = 3;
       uint ExpectedRuntime = 42;
       Job target = new Job("Constructor test", owner, CPU, ExpectedRuntime);
       Assert.AreEqual(owner, target.owner);
       Assert.AreEqual(CPU, target.CPU);
       Assert.AreEqual(ExpectedRuntime, target.ExpectedRuntime);
 }
Пример #7
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);
 }