public TaskInfo(Task task) { TaskType ttype = task.GetType(); this.type = ttype.ToString(); TaskReport report = task.GetReport(); this.startTime = report.GetStartTime(); this.finishTime = report.GetFinishTime(); this.state = report.GetTaskState(); this.elapsedTime = Times.Elapsed(this.startTime, this.finishTime, this.state == TaskState .Running); if (this.elapsedTime == -1) { this.elapsedTime = 0; } this.progress = report.GetProgress() * 100; this.status = report.GetStatus(); this.id = MRApps.ToString(task.GetID()); this.taskNum = task.GetID().GetId(); this.successful = GetSuccessfulAttempt(task); if (successful != null) { this.successfulAttempt = MRApps.ToString(successful.GetID()); } else { this.successfulAttempt = string.Empty; } }
public virtual void TestTasksBlock() { ApplicationId appId = ApplicationIdPBImpl.NewInstance(0, 1); JobId jobId = new JobIdPBImpl(); jobId.SetId(0); jobId.SetAppId(appId); TaskId taskId = new TaskIdPBImpl(); taskId.SetId(0); taskId.SetTaskType(TaskType.Map); taskId.SetJobId(jobId); Task task = Org.Mockito.Mockito.Mock <Task>(); Org.Mockito.Mockito.When(task.GetID()).ThenReturn(taskId); TaskReport report = Org.Mockito.Mockito.Mock <TaskReport>(); Org.Mockito.Mockito.When(report.GetProgress()).ThenReturn(0.7f); Org.Mockito.Mockito.When(report.GetTaskState()).ThenReturn(TaskState.Succeeded); Org.Mockito.Mockito.When(report.GetStartTime()).ThenReturn(100001L); Org.Mockito.Mockito.When(report.GetFinishTime()).ThenReturn(100011L); Org.Mockito.Mockito.When(report.GetStatus()).ThenReturn("Dummy Status \n*"); Org.Mockito.Mockito.When(task.GetReport()).ThenReturn(report); Org.Mockito.Mockito.When(task.GetType()).ThenReturn(TaskType.Map); IDictionary <TaskId, Task> tasks = new Dictionary <TaskId, Task>(); tasks[taskId] = task; AppContext ctx = Org.Mockito.Mockito.Mock <AppContext>(); Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job >(); Org.Mockito.Mockito.When(job.GetTasks()).ThenReturn(tasks); Org.Apache.Hadoop.Mapreduce.V2.App.Webapp.App app = new Org.Apache.Hadoop.Mapreduce.V2.App.Webapp.App (ctx); app.SetJob(job); TasksBlockForTest taskBlock = new TasksBlockForTest(app); taskBlock.AddParameter(AMParams.TaskType, "m"); PrintWriter pWriter = new PrintWriter(data); HtmlBlock.Block html = new BlockForTest(new TestBlocks.HtmlBlockForTest(this), pWriter , 0, false); taskBlock.Render(html); pWriter.Flush(); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("task_0_0001_m_000000")); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("70.00")); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("SUCCEEDED")); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("100001")); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("100011")); NUnit.Framework.Assert.IsFalse(data.ToString().Contains("Dummy Status \n*")); NUnit.Framework.Assert.IsTrue(data.ToString().Contains("Dummy Status \\n*")); }
/// <exception cref="System.Exception"/> public virtual void WaitForInternalState(TaskImpl task, TaskStateInternal finalState ) { int timeoutSecs = 0; TaskReport report = task.GetReport(); TaskStateInternal iState = task.GetInternalState(); while (!finalState.Equals(iState) && timeoutSecs++ < 20) { System.Console.Out.WriteLine("Task Internal State is : " + iState + " Waiting for Internal state : " + finalState + " progress : " + report.GetProgress()); Sharpen.Thread.Sleep(500); report = task.GetReport(); iState = task.GetInternalState(); } System.Console.Out.WriteLine("Task Internal State is : " + iState); NUnit.Framework.Assert.AreEqual("Task Internal state is not correct (timedout)", finalState, iState); }
private Task GetTask(long timestamp) { JobId jobId = new JobIdPBImpl(); jobId.SetId(0); jobId.SetAppId(ApplicationIdPBImpl.NewInstance(timestamp, 1)); TaskId taskId = new TaskIdPBImpl(); taskId.SetId(0); taskId.SetTaskType(TaskType.Reduce); taskId.SetJobId(jobId); Task task = Org.Mockito.Mockito.Mock <Task>(); Org.Mockito.Mockito.When(task.GetID()).ThenReturn(taskId); TaskReport report = Org.Mockito.Mockito.Mock <TaskReport>(); Org.Mockito.Mockito.When(report.GetProgress()).ThenReturn(0.7f); Org.Mockito.Mockito.When(report.GetTaskState()).ThenReturn(TaskState.Succeeded); Org.Mockito.Mockito.When(report.GetStartTime()).ThenReturn(100001L); Org.Mockito.Mockito.When(report.GetFinishTime()).ThenReturn(100011L); Org.Mockito.Mockito.When(task.GetReport()).ThenReturn(report); Org.Mockito.Mockito.When(task.GetType()).ThenReturn(TaskType.Reduce); return(task); }
public virtual void VerifyTaskGeneric(Task task, string id, string state, string type, string successfulAttempt, long startTime, long finishTime, long elapsedTime , float progress, string status) { TaskId taskid = task.GetID(); string tid = MRApps.ToString(taskid); TaskReport report = task.GetReport(); WebServicesTestUtils.CheckStringMatch("id", tid, id); WebServicesTestUtils.CheckStringMatch("type", task.GetType().ToString(), type); WebServicesTestUtils.CheckStringMatch("state", report.GetTaskState().ToString(), state); // not easily checked without duplicating logic, just make sure its here NUnit.Framework.Assert.IsNotNull("successfulAttempt null", successfulAttempt); NUnit.Framework.Assert.AreEqual("startTime wrong", report.GetStartTime(), startTime ); NUnit.Framework.Assert.AreEqual("finishTime wrong", report.GetFinishTime(), finishTime ); NUnit.Framework.Assert.AreEqual("elapsedTime wrong", finishTime - startTime, elapsedTime ); NUnit.Framework.Assert.AreEqual("progress wrong", report.GetProgress() * 100, progress , 1e-3f); NUnit.Framework.Assert.AreEqual("status wrong", report.GetStatus(), status); }