Exemplo n.º 1
0
        public virtual void TestKillJob()
        {
            CountDownLatch latch = new CountDownLatch(1);
            MRApp          app   = new TestKill.BlockingMRApp(1, 0, latch);

            //this will start the job but job won't complete as task is
            //blocked
            Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = app.Submit(new Configuration());
            //wait and vailidate for Job to become RUNNING
            app.WaitForState(job, JobState.Running);
            //send the kill signal to Job
            app.GetContext().GetEventHandler().Handle(new JobEvent(job.GetID(), JobEventType.
                                                                   JobKill));
            //unblock Task
            latch.CountDown();
            //wait and validate for Job to be KILLED
            app.WaitForState(job, JobState.Killed);
            IDictionary <TaskId, Task> tasks = job.GetTasks();

            NUnit.Framework.Assert.AreEqual("No of tasks is not correct", 1, tasks.Count);
            Task task = tasks.Values.GetEnumerator().Next();

            NUnit.Framework.Assert.AreEqual("Task state not correct", TaskState.Killed, task.
                                            GetReport().GetTaskState());
            IDictionary <TaskAttemptId, TaskAttempt> attempts = tasks.Values.GetEnumerator().Next
                                                                    ().GetAttempts();

            NUnit.Framework.Assert.AreEqual("No of attempts is not correct", 1, attempts.Count
                                            );
            IEnumerator <TaskAttempt> it = attempts.Values.GetEnumerator();

            NUnit.Framework.Assert.AreEqual("Attempt state not correct", TaskAttemptState.Killed
                                            , it.Next().GetReport().GetTaskAttemptState());
        }
Exemplo n.º 2
0
        public virtual void TestKillTaskAttempt()
        {
            CountDownLatch latch = new CountDownLatch(1);
            MRApp          app   = new TestKill.BlockingMRApp(2, 0, latch);

            //this will start the job but job won't complete as Task is blocked
            Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = app.Submit(new Configuration());
            //wait and vailidate for Job to become RUNNING
            app.WaitForState(job, JobState.Running);
            IDictionary <TaskId, Task> tasks = job.GetTasks();

            NUnit.Framework.Assert.AreEqual("No of tasks is not correct", 2, tasks.Count);
            IEnumerator <Task> it = tasks.Values.GetEnumerator();
            Task task1            = it.Next();
            Task task2            = it.Next();

            //wait for tasks to become running
            app.WaitForState(task1, TaskState.Scheduled);
            app.WaitForState(task2, TaskState.Scheduled);
            //send the kill signal to the first Task's attempt
            TaskAttempt attempt = task1.GetAttempts().Values.GetEnumerator().Next();

            app.GetContext().GetEventHandler().Handle(new TaskAttemptEvent(attempt.GetID(), TaskAttemptEventType
                                                                           .TaKill));
            //unblock
            latch.CountDown();
            //wait and validate for Job to become SUCCEEDED
            //job will still succeed
            app.WaitForState(job, JobState.Succeeded);
            //first Task will have two attempts 1st is killed, 2nd Succeeds
            //both Tasks and Job succeeds
            NUnit.Framework.Assert.AreEqual("Task state not correct", TaskState.Succeeded, task1
                                            .GetReport().GetTaskState());
            NUnit.Framework.Assert.AreEqual("Task state not correct", TaskState.Succeeded, task2
                                            .GetReport().GetTaskState());
            IDictionary <TaskAttemptId, TaskAttempt> attempts = task1.GetAttempts();

            NUnit.Framework.Assert.AreEqual("No of attempts is not correct", 2, attempts.Count
                                            );
            IEnumerator <TaskAttempt> iter = attempts.Values.GetEnumerator();

            NUnit.Framework.Assert.AreEqual("Attempt state not correct", TaskAttemptState.Killed
                                            , iter.Next().GetReport().GetTaskAttemptState());
            NUnit.Framework.Assert.AreEqual("Attempt state not correct", TaskAttemptState.Succeeded
                                            , iter.Next().GetReport().GetTaskAttemptState());
            attempts = task2.GetAttempts();
            NUnit.Framework.Assert.AreEqual("No of attempts is not correct", 1, attempts.Count
                                            );
            iter = attempts.Values.GetEnumerator();
            NUnit.Framework.Assert.AreEqual("Attempt state not correct", TaskAttemptState.Succeeded
                                            , iter.Next().GetReport().GetTaskAttemptState());
        }