Ejemplo n.º 1
0
 /// <summary>
 /// The constructor
 /// </summary>
 public BenchmarkSystem()
 {
     _threads = new List<Job>();
     _jobs = new Dictionary<User, List<Job>>();
     _isFinishing = true;
     _tmDAO = new TM2SQL_DAO();
     _logger = new Logger(this, _tmDAO);
     _scheduler = new Scheduler();
     _scheduler.JobDone += OnJobDone;
     _scheduler.JobFailed += OnJobFailed;
     _scheduler.JobTerminated += OnJobTerminated;
     SetStatus();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// With maximum simultaneous running jobs
        /// </summary>
        //[TestMethod]
        public void Test_IsSlotAvailableWhileMaxed()
        {
            Scheduler s = new Scheduler();
            Func<string[], int> funk = st => { Thread.Sleep(500); return 0; };
            Mutex mutex = new Mutex(false, "Test_PopJobWhileMaxed");

            // Insert 63 jobs into the scheduler
            for (int i = 0; i < 21; i++)
            {
                s.AddJob(new Job(new User("test" + i, ""), 10, 5, funk));
                s.AddJob(new Job(new User("test" + i, ""), 100, 5, funk));
                s.AddJob(new Job(new User("test" + i, ""), 500, 5, funk));
            }

            bool ready = false;
            bool mutexReleased = false;
            Thread blocker = new Thread(new ThreadStart(() =>
            {
                mutex.WaitOne();
                while (!ready) { Thread.Sleep(500); }
                mutex.ReleaseMutex();
                mutexReleased = true;
            }));

            try
            {
                blocker.Start();
                Job job = null;
                for (int i = 0; i < 3; i++)
                {
                    job = s.PopJob();
                    Thread t = new Thread(new ThreadStart(() => job.Process(new String[] { "Test", "stuff" })));
                    t.Start();
                    while (t.ThreadState != ThreadState.WaitSleepJoin) { Thread.Sleep(500); }
                }
            }
            catch
            {
                // To the finally block!
            }
            finally
            {
                ready = true;
                while (!mutexReleased) { Thread.Sleep(500); }
                Assert.IsFalse(s.IsSlotAvailable());
            }
        }
Ejemplo n.º 3
0
        public void Test_AddJobNull()
        {
            Scheduler s = new Scheduler();

            try
            {
                s.AddJob(null);
                Assert.Fail("It was possible to add a null job");
            }
            catch (Exception e)
            {
                // If it is not a contract exception the test fails
                if (!e.ToString().ToLower().Contains("precondition failed"))
                {
                    Assert.Fail("Unexpected exception thrown: " + e);
                }
            }
        }
Ejemplo n.º 4
0
        public void Test_AddJob()
        {
            Scheduler s = new Scheduler();

            // Add legal jobs with the three types: SHORT, LONG, VERY_LONG
            Func<string[], int> funk = st => 10;
            Job shortJob = new Job(new User("test", ""), 25, 5, funk);
            Job longJob = new Job(new User("test", ""), 115, 5, funk);
            Job veryLongJob = new Job(new User("test", ""), 500, 5, funk);

            s.AddJob(shortJob);
            s.AddJob(longJob);
            s.AddJob(veryLongJob);

            Assert.AreEqual(3, s.JobsInSequence.Count);

            // Add 5000 jobs of varying type
            for (uint i = 0; i < 5000; i++)
            {
                s.AddJob(new Job(new User("test", ""), i, 5, funk));
            }

            Assert.AreEqual(5003, s.JobsInSequence.Count);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Helper method. Checks that the sequence of jobs returned is in the same order as they were added
 /// </summary>
 /// <param name="s">The scheduler</param>
 /// <param name="first">Job to add first</param>
 /// <param name="second">Job to add second</param>
 /// <param name="third">Job to add last</param>
 private void AssertSequence(Scheduler s, Job first, Job second, Job third)
 {
     s.AddJob(first);
     s.AddJob(second);
     s.AddJob(third);
     Assert.AreEqual(first, s.PopJob());
     Assert.AreEqual(second, s.PopJob());
     Assert.AreEqual(third, s.PopJob());
 }
Ejemplo n.º 6
0
 public void Test_RemoveJobNull()
 {
     Scheduler s = new Scheduler();
     try
     {
         s.RemoveJob(null);
         Assert.Fail("It was possible to remove a \"null\" job");
     }
     catch (ArgumentNullException)
     {
         // This is good
     }
 }
Ejemplo n.º 7
0
 public void Test_RemoveJobNoTInScheduler()
 {
     Scheduler s = new Scheduler();
     Func<string[], int> funk = st => 10;
     Job phonyJob = new Job(new User("test", ""), 50, 5, funk);
     try
     {
         s.RemoveJob(phonyJob);
         Assert.Fail("It was possible to remove a job not in the scheduler");
     }
     catch (ArgumentException)
     {
         // This is good
     }
 }
Ejemplo n.º 8
0
        public void Test_RemoveJobInScheduler()
        {
            Scheduler s = new Scheduler();
            Func<string[], int> funk = st => 10;
            Job job = new Job(new User("test", ""), 20, 5, funk);
            s.AddJob(job);

            // Remove a job in the scheduler
            s.RemoveJob(job);
            Assert.AreEqual(0, s.JobsInSequence.Count);
        }
Ejemplo n.º 9
0
 public void Test_PopJobWithNoJobs()
 {
     Scheduler s = new Scheduler();
     try
     {
         s.PopJob();
         Assert.Fail("It was possible to pop a job when there were no jobs to pop");
     }
     catch (JobsDepletedException)
     {
         // This is good
     }
 }
Ejemplo n.º 10
0
        public void Test_PopJobWhileMaxed()
        {
            Scheduler s = new Scheduler();
            Func<string[], int> funk = st => 0;
            Mutex mutex = new Mutex(false, "Test_PopJobWhileMaxed");

            // Insert 63 jobs into the scheduler
            for (int i = 0; i < 21; i++)
            {
                s.AddJob(new Job(new User("test" + i, ""), 10, 5, funk));
                s.AddJob(new Job(new User("test" + i, ""), 100, 5, funk));
                s.AddJob(new Job(new User("test" + i, ""), 500, 5, funk));
            }

            bool ready = false;
            bool mutexReleased = false;
            Thread blocker = new Thread(new ThreadStart(() =>
            {
                mutex.WaitOne();
                while (!ready) { Thread.Sleep(500); }
                mutex.ReleaseMutex();
                mutexReleased = true;
            }));

            try
            {
                blocker.Start();
                Job job = null;
                for (int i = 0; i < 3; i++)
                {
                    job = s.PopJob();
                    Thread t = new Thread(new ThreadStart(() => job.Process(new String[] { "Test", "stuff" })));
                    t.Start();
                    while (t.ThreadState != ThreadState.WaitSleepJoin) { Thread.Sleep(500); }
                }
                try
                {
                    s.PopJob();
                    Assert.Fail("It was possible to pop a job from scheduler while at maximum capacity.");
                }
                catch (InvalidOperationException)
                {
                    // This is good
                }
            }
            catch
            {
                // To the finally block!
            }
            finally
            {
                ready = true;
                while (!mutexReleased) { Thread.Sleep(500); }
            }
        }
Ejemplo n.º 11
0
        public void Test_PopJobSequence()
        {
            Scheduler s = new Scheduler();
            Func<string[], int> funk = st => 10;

            // Check the sequence og jobs returned
            Job shortJob = new Job(new User("test", ""), 25, 5, funk);
            Job longJob = new Job(new User("test", ""), 115, 5, funk);
            Job veryLongJob = new Job(new User("test", ""), 500, 5, funk);

            // short, long, verylong
            AssertSequence(s, shortJob, longJob, veryLongJob);
            // long, short, verylong
            AssertSequence(s, longJob, shortJob, veryLongJob);
            // long, verylong, short
            AssertSequence(s, longJob, veryLongJob, shortJob);
            // short, verylong, long
            AssertSequence(s, shortJob, veryLongJob, longJob);
            // verylong, short, long
            AssertSequence(s, veryLongJob, shortJob, longJob);
            // verylong, long, short
            AssertSequence(s, veryLongJob, longJob, shortJob);
        }
Ejemplo n.º 12
0
        public void Test_IsSlotAvailableWithoutRunningJobs()
        {
            Scheduler s = new Scheduler();

            // With no running jobs, should return true
            Assert.IsTrue(s.IsSlotAvailable());
        }