public virtual void TestTaskStartTimes() { TaskId taskId = Org.Mockito.Mockito.Mock <TaskId>(); JobHistoryParser.TaskInfo taskInfo = Org.Mockito.Mockito.Mock <JobHistoryParser.TaskInfo >(); IDictionary <TaskAttemptID, JobHistoryParser.TaskAttemptInfo> taskAttempts = new SortedDictionary <TaskAttemptID, JobHistoryParser.TaskAttemptInfo>(); TaskAttemptID id = new TaskAttemptID("0", 0, TaskType.Map, 0, 0); JobHistoryParser.TaskAttemptInfo info = Org.Mockito.Mockito.Mock <JobHistoryParser.TaskAttemptInfo >(); Org.Mockito.Mockito.When(info.GetAttemptId()).ThenReturn(id); Org.Mockito.Mockito.When(info.GetStartTime()).ThenReturn(10l); taskAttempts[id] = info; id = new TaskAttemptID("1", 0, TaskType.Map, 1, 1); info = Org.Mockito.Mockito.Mock <JobHistoryParser.TaskAttemptInfo>(); Org.Mockito.Mockito.When(info.GetAttemptId()).ThenReturn(id); Org.Mockito.Mockito.When(info.GetStartTime()).ThenReturn(20l); taskAttempts[id] = info; Org.Mockito.Mockito.When(taskInfo.GetAllTaskAttempts()).ThenReturn(taskAttempts); CompletedTask task = new CompletedTask(taskId, taskInfo); TaskReport report = task.GetReport(); // Make sure the startTime returned by report is the lesser of the // attempy launch times NUnit.Framework.Assert.IsTrue(report.GetStartTime() == 10); }
public virtual void VerifyCompleted() { foreach (Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job in GetContext().GetAllJobs ().Values) { JobReport jobReport = job.GetReport(); System.Console.Out.WriteLine("Job start time :" + jobReport.GetStartTime()); System.Console.Out.WriteLine("Job finish time :" + jobReport.GetFinishTime()); NUnit.Framework.Assert.IsTrue("Job start time is not less than finish time", jobReport .GetStartTime() <= jobReport.GetFinishTime()); NUnit.Framework.Assert.IsTrue("Job finish time is in future", jobReport.GetFinishTime () <= Runtime.CurrentTimeMillis()); foreach (Task task in job.GetTasks().Values) { TaskReport taskReport = task.GetReport(); System.Console.Out.WriteLine("Task start time : " + taskReport.GetStartTime()); System.Console.Out.WriteLine("Task finish time : " + taskReport.GetFinishTime()); NUnit.Framework.Assert.IsTrue("Task start time is not less than finish time", taskReport .GetStartTime() <= taskReport.GetFinishTime()); foreach (TaskAttempt attempt in task.GetAttempts().Values) { TaskAttemptReport attemptReport = attempt.GetReport(); NUnit.Framework.Assert.IsTrue("Attempt start time is not less than finish time", attemptReport.GetStartTime() <= attemptReport.GetFinishTime()); } } } }
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*")); }
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); }