/// <exception cref="System.Exception"/> public virtual void TestCompletedTask() { HistoryFileManager.HistoryFileInfo info = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo >(); Org.Mockito.Mockito.When(info.GetConfFile()).ThenReturn(fullConfPath); completedJob = new CompletedJob(conf, jobId, fullHistoryPath, loadTasks, "user", info, jobAclsManager); TaskId mt1Id = MRBuilderUtils.NewTaskId(jobId, 0, TaskType.Map); TaskId rt1Id = MRBuilderUtils.NewTaskId(jobId, 0, TaskType.Reduce); IDictionary <TaskId, Task> mapTasks = completedJob.GetTasks(TaskType.Map); IDictionary <TaskId, Task> reduceTasks = completedJob.GetTasks(TaskType.Reduce); NUnit.Framework.Assert.AreEqual(10, mapTasks.Count); NUnit.Framework.Assert.AreEqual(2, reduceTasks.Count); Task mt1 = mapTasks[mt1Id]; NUnit.Framework.Assert.AreEqual(1, mt1.GetAttempts().Count); NUnit.Framework.Assert.AreEqual(TaskState.Succeeded, mt1.GetState()); TaskReport mt1Report = mt1.GetReport(); NUnit.Framework.Assert.AreEqual(TaskState.Succeeded, mt1Report.GetTaskState()); NUnit.Framework.Assert.AreEqual(mt1Id, mt1Report.GetTaskId()); Task rt1 = reduceTasks[rt1Id]; NUnit.Framework.Assert.AreEqual(1, rt1.GetAttempts().Count); NUnit.Framework.Assert.AreEqual(TaskState.Succeeded, rt1.GetState()); TaskReport rt1Report = rt1.GetReport(); NUnit.Framework.Assert.AreEqual(TaskState.Succeeded, rt1Report.GetTaskState()); NUnit.Framework.Assert.AreEqual(rt1Id, rt1Report.GetTaskId()); }
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; } }
/// <exception cref="System.Exception"/> public virtual void WaitForState(Task task, TaskState finalState) { int timeoutSecs = 0; TaskReport report = task.GetReport(); while (!finalState.Equals(report.GetTaskState()) && timeoutSecs++ < 20) { System.Console.Out.WriteLine("Task State for " + task.GetID() + " is : " + report .GetTaskState() + " Waiting for state : " + finalState + " progress : " + report .GetProgress()); report = task.GetReport(); Sharpen.Thread.Sleep(500); } System.Console.Out.WriteLine("Task State is : " + report.GetTaskState()); NUnit.Framework.Assert.AreEqual("Task state is not correct (timedout)", finalState , report.GetTaskState()); }
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*")); }
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); }