Exemple #1
0
        public virtual void TestErrorWhileSubmitting()
        {
            JobControl    jobControl = new JobControl("Test");
            Job           mockJob    = Org.Mockito.Mockito.Mock <Job>();
            ControlledJob job1       = new ControlledJob(mockJob, null);

            Org.Mockito.Mockito.When(mockJob.GetConfiguration()).ThenReturn(new Configuration
                                                                                ());
            Org.Mockito.Mockito.DoThrow(new IncompatibleClassChangeError("This is a test")).When
                (mockJob).Submit();
            jobControl.AddJob(job1);
            RunJobControl(jobControl);
            try
            {
                NUnit.Framework.Assert.AreEqual("Success list", 0, jobControl.GetSuccessfulJobList
                                                    ().Count);
                NUnit.Framework.Assert.AreEqual("Failed list", 1, jobControl.GetFailedJobList().Count
                                                );
                NUnit.Framework.Assert.IsTrue(job1.GetJobState() == ControlledJob.State.Failed);
            }
            finally
            {
                jobControl.Stop();
            }
        }
Exemple #2
0
        /// <summary>This is a main function for testing JobControl class.</summary>
        /// <remarks>
        /// This is a main function for testing JobControl class.
        /// It requires 4 jobs:
        /// Job 1: passed as parameter. input:indir  output:outdir_1
        /// Job 2: copy data from indir to outdir_2
        /// Job 3: copy data from outdir_1 and outdir_2 to outdir_3
        /// Job 4: copy data from outdir to outdir_4
        /// The jobs 1 and 2 have no dependency. The job 3 depends on jobs 1 and 2.
        /// The job 4 depends on job 3.
        /// Then it creates a JobControl object and add the 4 jobs to
        /// the JobControl object.
        /// Finally, it creates a thread to run the JobControl object
        /// </remarks>
        /// <exception cref="System.Exception"/>
        private JobControl CreateDependencies(Configuration conf, Job job1)
        {
            IList <ControlledJob> dependingJobs = null;

            cjob1 = new ControlledJob(job1, dependingJobs);
            Job job2 = MapReduceTestUtil.CreateCopyJob(conf, outdir_2, indir);

            cjob2 = new ControlledJob(job2, dependingJobs);
            Job job3 = MapReduceTestUtil.CreateCopyJob(conf, outdir_3, outdir_1, outdir_2);

            dependingJobs = new AList <ControlledJob>();
            dependingJobs.AddItem(cjob1);
            dependingJobs.AddItem(cjob2);
            cjob3 = new ControlledJob(job3, dependingJobs);
            Job job4 = MapReduceTestUtil.CreateCopyJob(conf, outdir_4, outdir_3);

            dependingJobs = new AList <ControlledJob>();
            dependingJobs.AddItem(cjob3);
            cjob4 = new ControlledJob(job4, dependingJobs);
            JobControl theControl = new JobControl("Test");

            theControl.AddJob(cjob1);
            theControl.AddJob(cjob2);
            theControl.AddJob(cjob3);
            theControl.AddJob(cjob4);
            Sharpen.Thread theController = new Sharpen.Thread(theControl);
            theController.Start();
            return(theControl);
        }
Exemple #3
0
 private void FailAllJobs(Exception t)
 {
     lock (this)
     {
         string message = "Unexpected System Error Occured: " + StringUtils.StringifyException
                              (t);
         IEnumerator <ControlledJob> it = jobsInProgress.GetEnumerator();
         while (it.HasNext())
         {
             ControlledJob j = it.Next();
             try
             {
                 j.FailJob(message);
             }
             catch (IOException e)
             {
                 Log.Error("Error while tyring to clean up " + j.GetJobName(), e);
             }
             catch (Exception e)
             {
                 Log.Error("Error while tyring to clean up " + j.GetJobName(), e);
             }
             finally
             {
                 failedJobs.AddItem(j);
                 it.Remove();
             }
         }
     }
 }
        public virtual void TestAddingDependingJobToRunningJobFails()
        {
            Configuration conf = new Configuration();
            ControlledJob job1 = new ControlledJob(conf);

            job1.SetJobState(ControlledJob.State.Running);
            NUnit.Framework.Assert.IsFalse(job1.AddDependingJob(new ControlledJob(conf)));
        }
Exemple #5
0
        public virtual void TestKillJob()
        {
            JobControl    jobControl = new JobControl("Test");
            ControlledJob job        = CreateFailedControlledJob(jobControl);

            job.KillJob();
            // Verify that killJob() was called on the mock Job
            Org.Mockito.Mockito.Verify(job.GetJob()).KillJob();
        }
Exemple #6
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        private ControlledJob CreateControlledJob(JobControl jobControl, bool successful,
                                                  params ControlledJob[] dependingJobs)
        {
            IList <ControlledJob> dependingJobsList = dependingJobs == null ? null : Arrays.AsList
                                                          (dependingJobs);
            ControlledJob job = new ControlledJob(CreateJob(true, successful), dependingJobsList
                                                  );

            jobControl.AddJob(job);
            return(job);
        }
Exemple #7
0
 /// <summary>Add a new controlled job.</summary>
 /// <param name="aJob">the new controlled job</param>
 public virtual string AddJob(ControlledJob aJob)
 {
     lock (this)
     {
         string id = this.GetNextJobID();
         aJob.SetJobID(id);
         aJob.SetJobState(ControlledJob.State.Waiting);
         jobsInProgress.AddItem(aJob);
         return(id);
     }
 }
Exemple #8
0
        public virtual void TestSuccessfulJobs()
        {
            JobControl    jobControl = new JobControl("Test");
            ControlledJob job1       = CreateSuccessfulControlledJob(jobControl);
            ControlledJob job2       = CreateSuccessfulControlledJob(jobControl);
            ControlledJob job3       = CreateSuccessfulControlledJob(jobControl, job1, job2);
            ControlledJob job4       = CreateSuccessfulControlledJob(jobControl, job3);

            RunJobControl(jobControl);
            NUnit.Framework.Assert.AreEqual("Success list", 4, jobControl.GetSuccessfulJobList
                                                ().Count);
            NUnit.Framework.Assert.AreEqual("Failed list", 0, jobControl.GetFailedJobList().Count
                                            );
            NUnit.Framework.Assert.IsTrue(job1.GetJobState() == ControlledJob.State.Success);
            NUnit.Framework.Assert.IsTrue(job2.GetJobState() == ControlledJob.State.Success);
            NUnit.Framework.Assert.IsTrue(job3.GetJobState() == ControlledJob.State.Success);
            NUnit.Framework.Assert.IsTrue(job4.GetJobState() == ControlledJob.State.Success);
            jobControl.Stop();
        }
Exemple #9
0
        /// <summary>The main loop for the thread.</summary>
        /// <remarks>
        /// The main loop for the thread.
        /// The loop does the following:
        /// Check the states of the running jobs
        /// Update the states of waiting jobs
        /// Submit the jobs in ready state
        /// </remarks>
        public virtual void Run()
        {
            try
            {
                this.runnerState = JobControl.ThreadState.Running;
                while (true)
                {
                    while (this.runnerState == JobControl.ThreadState.Suspended)
                    {
                        try
                        {
                            Sharpen.Thread.Sleep(5000);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    //TODO the thread was interrupted, do something!!!
                    lock (this)
                    {
                        IEnumerator <ControlledJob> it = jobsInProgress.GetEnumerator();
                        while (it.HasNext())
                        {
                            ControlledJob j = it.Next();
                            Log.Debug("Checking state of job " + j);
                            switch (j.CheckState())
                            {
                            case ControlledJob.State.Success:
                            {
                                successfulJobs.AddItem(j);
                                it.Remove();
                                break;
                            }

                            case ControlledJob.State.Failed:
                            case ControlledJob.State.DependentFailed:
                            {
                                failedJobs.AddItem(j);
                                it.Remove();
                                break;
                            }

                            case ControlledJob.State.Ready:
                            {
                                j.Submit();
                                break;
                            }

                            case ControlledJob.State.Running:
                            case ControlledJob.State.Waiting:
                            {
                                //Do Nothing
                                break;
                            }
                            }
                        }
                    }
                    if (this.runnerState != JobControl.ThreadState.Running && this.runnerState != JobControl.ThreadState
                        .Suspended)
                    {
                        break;
                    }
                    try
                    {
                        Sharpen.Thread.Sleep(5000);
                    }
                    catch (Exception)
                    {
                    }
                    //TODO the thread was interrupted, do something!!!
                    if (this.runnerState != JobControl.ThreadState.Running && this.runnerState != JobControl.ThreadState
                        .Suspended)
                    {
                        break;
                    }
                }
            }
            catch (Exception t)
            {
                Log.Error("Error while trying to run jobs.", t);
                //Mark all jobs as failed because we got something bad.
                FailAllJobs(t);
            }
            this.runnerState = JobControl.ThreadState.Stopped;
        }