Esempio n. 1
0
        // Run a job that will be killed and wait until it completes
        /// <exception cref="System.IO.IOException"/>
        public static RunningJob RunJobKill(JobConf conf, Path inDir, Path outDir)
        {
            conf.SetJobName("test-job-kill");
            conf.SetMapperClass(typeof(UtilsForTests.KillMapper));
            conf.SetReducerClass(typeof(IdentityReducer));
            RunningJob job        = UtilsForTests.RunJob(conf, inDir, outDir);
            long       sleepCount = 0;

            while (job.GetJobState() != JobStatus.Running)
            {
                try
                {
                    if (sleepCount > 300)
                    {
                        // 30 seconds
                        throw new IOException("Job didn't finish in 30 seconds");
                    }
                    Sharpen.Thread.Sleep(100);
                    sleepCount++;
                }
                catch (Exception)
                {
                    break;
                }
            }
            job.KillJob();
            sleepCount = 0;
            while (job.CleanupProgress() == 0.0f)
            {
                try
                {
                    if (sleepCount > 2000)
                    {
                        // 20 seconds
                        throw new IOException("Job cleanup didn't start in 20 seconds");
                    }
                    Sharpen.Thread.Sleep(10);
                    sleepCount++;
                }
                catch (Exception)
                {
                    break;
                }
            }
            return(job);
        }