Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestControlledJob()
        {
            Log.Info("Starting testControlledJob");
            Configuration conf = CreateJobConf();

            CleanupData(conf);
            Job        job1       = MapReduceTestUtil.CreateCopyJob(conf, outdir_1, indir);
            JobControl theControl = CreateDependencies(conf, job1);

            while (cjob1.GetJobState() != ControlledJob.State.Running)
            {
                try
                {
                    Sharpen.Thread.Sleep(100);
                }
                catch (Exception)
                {
                    break;
                }
            }
            NUnit.Framework.Assert.IsNotNull(cjob1.GetMapredJobId());
            // wait till all the jobs complete
            WaitTillAllFinished(theControl);
            NUnit.Framework.Assert.AreEqual("Some jobs failed", 0, theControl.GetFailedJobList
                                                ().Count);
            theControl.Stop();
        }
Пример #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);
        }
Пример #3
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();
            }
        }
Пример #4
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();
        }
Пример #5
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);
        }
Пример #6
0
 private void WaitTillAllFinished(JobControl theControl)
 {
     while (!theControl.AllFinished())
     {
         try
         {
             Sharpen.Thread.Sleep(100);
         }
         catch (Exception)
         {
         }
     }
 }
Пример #7
0
        /// <exception cref="System.Exception"/>
        public virtual void TestJobControl()
        {
            Log.Info("Starting testJobControl");
            Configuration conf = CreateJobConf();

            CleanupData(conf);
            Job        job1       = MapReduceTestUtil.CreateCopyJob(conf, outdir_1, indir);
            JobControl theControl = CreateDependencies(conf, job1);

            // wait till all the jobs complete
            WaitTillAllFinished(theControl);
            NUnit.Framework.Assert.AreEqual("Some jobs failed", 0, theControl.GetFailedJobList
                                                ().Count);
            theControl.Stop();
        }
Пример #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();
        }
Пример #9
0
        /// <exception cref="System.Exception"/>
        public virtual void TestJobControlWithFailJob()
        {
            Log.Info("Starting testJobControlWithFailJob");
            Configuration conf = CreateJobConf();

            CleanupData(conf);
            // create a Fail job
            Job job1 = MapReduceTestUtil.CreateFailJob(conf, outdir_1, indir);
            // create job dependencies
            JobControl theControl = CreateDependencies(conf, job1);

            // wait till all the jobs complete
            WaitTillAllFinished(theControl);
            NUnit.Framework.Assert.IsTrue(cjob1.GetJobState() == ControlledJob.State.Failed);
            NUnit.Framework.Assert.IsTrue(cjob2.GetJobState() == ControlledJob.State.Success);
            NUnit.Framework.Assert.IsTrue(cjob3.GetJobState() == ControlledJob.State.DependentFailed
                                          );
            NUnit.Framework.Assert.IsTrue(cjob4.GetJobState() == ControlledJob.State.DependentFailed
                                          );
            theControl.Stop();
        }
Пример #10
0
        /// <exception cref="System.Exception"/>
        public virtual void TestJobControlWithKillJob()
        {
            Log.Info("Starting testJobControlWithKillJob");
            Configuration conf = CreateJobConf();

            CleanupData(conf);
            Job        job1       = MapReduceTestUtil.CreateKillJob(conf, outdir_1, indir);
            JobControl theControl = CreateDependencies(conf, job1);

            while (cjob1.GetJobState() != ControlledJob.State.Running)
            {
                try
                {
                    Sharpen.Thread.Sleep(100);
                }
                catch (Exception)
                {
                    break;
                }
            }
            // verify adding dependingJo to RUNNING job fails.
            NUnit.Framework.Assert.IsFalse(cjob1.AddDependingJob(cjob2));
            // suspend jobcontrol and resume it again
            theControl.Suspend();
            NUnit.Framework.Assert.IsTrue(theControl.GetThreadState() == JobControl.ThreadState
                                          .Suspended);
            theControl.Resume();
            // kill the first job.
            cjob1.KillJob();
            // wait till all the jobs complete
            WaitTillAllFinished(theControl);
            NUnit.Framework.Assert.IsTrue(cjob1.GetJobState() == ControlledJob.State.Failed);
            NUnit.Framework.Assert.IsTrue(cjob2.GetJobState() == ControlledJob.State.Success);
            NUnit.Framework.Assert.IsTrue(cjob3.GetJobState() == ControlledJob.State.DependentFailed
                                          );
            NUnit.Framework.Assert.IsTrue(cjob4.GetJobState() == ControlledJob.State.DependentFailed
                                          );
            theControl.Stop();
        }
Пример #11
0
 private void RunJobControl(JobControl jobControl)
 {
     Sharpen.Thread controller = new Sharpen.Thread(jobControl);
     controller.Start();
     WaitTillAllFinished(jobControl);
 }
Пример #12
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.Exception"/>
 private ControlledJob CreateFailedControlledJob(JobControl jobControl, params ControlledJob
                                                 [] dependingJobs)
 {
     return(CreateControlledJob(jobControl, false, dependingJobs));
 }
Пример #13
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.Exception"/>
 private ControlledJob CreateSuccessfulControlledJob(JobControl jobControl, params
                                                     ControlledJob[] dependingJobs)
 {
     return(CreateControlledJob(jobControl, true, dependingJobs));
 }