Exemplo n.º 1
0
        public virtual void TestHsTasksBlock()
        {
            Task task = GetTask(0);
            IDictionary <TaskId, Task> tasks = new Dictionary <TaskId, Task>();

            tasks[task.GetID()] = task;
            AppContext ctx = Org.Mockito.Mockito.Mock <AppContext>();
            AppForTest app = new AppForTest(ctx);

            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);
            app.SetJob(job);
            TestBlocks.HsTasksBlockForTest block = new TestBlocks.HsTasksBlockForTest(this, app
                                                                                      );
            block.AddParameter(AMParams.TaskType, "r");
            PrintWriter pWriter = new PrintWriter(data);

            HtmlBlock.Block html = new BlockForTest(new TestBlocks.HtmlBlockForTest(this), pWriter
                                                    , 0, false);
            block.Render(html);
            pWriter.Flush();
            // should be printed information about task
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("task_0_0001_r_000000"));
            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.IsTrue(data.ToString().Contains(string.Empty));
        }
Exemplo n.º 2
0
        public virtual void TestAttemptsBlock()
        {
            AppContext ctx  = Org.Mockito.Mockito.Mock <AppContext>();
            AppForTest app  = new AppForTest(ctx);
            Task       task = GetTask(0);
            IDictionary <TaskAttemptId, TaskAttempt> attempts = new Dictionary <TaskAttemptId,
                                                                                TaskAttempt>();
            TaskAttempt   attempt = Org.Mockito.Mockito.Mock <TaskAttempt>();
            TaskAttemptId taId    = new TaskAttemptIdPBImpl();

            taId.SetId(0);
            taId.SetTaskId(task.GetID());
            Org.Mockito.Mockito.When(attempt.GetID()).ThenReturn(taId);
            Org.Mockito.Mockito.When(attempt.GetNodeHttpAddress()).ThenReturn("Node address");
            ApplicationId        appId        = ApplicationIdPBImpl.NewInstance(0, 5);
            ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.NewInstance(appId,
                                                                                       1);
            ContainerId containerId = ContainerIdPBImpl.NewContainerId(appAttemptId, 1);

            Org.Mockito.Mockito.When(attempt.GetAssignedContainerID()).ThenReturn(containerId
                                                                                  );
            Org.Mockito.Mockito.When(attempt.GetAssignedContainerMgrAddress()).ThenReturn("assignedContainerMgrAddress"
                                                                                          );
            Org.Mockito.Mockito.When(attempt.GetNodeRackName()).ThenReturn("nodeRackName");
            long             taStartTime         = 100002L;
            long             taFinishTime        = 100012L;
            long             taShuffleFinishTime = 100010L;
            long             taSortFinishTime    = 100011L;
            TaskAttemptState taState             = TaskAttemptState.Succeeded;

            Org.Mockito.Mockito.When(attempt.GetLaunchTime()).ThenReturn(taStartTime);
            Org.Mockito.Mockito.When(attempt.GetFinishTime()).ThenReturn(taFinishTime);
            Org.Mockito.Mockito.When(attempt.GetShuffleFinishTime()).ThenReturn(taShuffleFinishTime
                                                                                );
            Org.Mockito.Mockito.When(attempt.GetSortFinishTime()).ThenReturn(taSortFinishTime
                                                                             );
            Org.Mockito.Mockito.When(attempt.GetState()).ThenReturn(taState);
            TaskAttemptReport taReport = Org.Mockito.Mockito.Mock <TaskAttemptReport>();

            Org.Mockito.Mockito.When(taReport.GetStartTime()).ThenReturn(taStartTime);
            Org.Mockito.Mockito.When(taReport.GetFinishTime()).ThenReturn(taFinishTime);
            Org.Mockito.Mockito.When(taReport.GetShuffleFinishTime()).ThenReturn(taShuffleFinishTime
                                                                                 );
            Org.Mockito.Mockito.When(taReport.GetSortFinishTime()).ThenReturn(taSortFinishTime
                                                                              );
            Org.Mockito.Mockito.When(taReport.GetContainerId()).ThenReturn(containerId);
            Org.Mockito.Mockito.When(taReport.GetProgress()).ThenReturn(1.0f);
            Org.Mockito.Mockito.When(taReport.GetStateString()).ThenReturn("Processed 128/128 records <p> \n"
                                                                           );
            Org.Mockito.Mockito.When(taReport.GetTaskAttemptState()).ThenReturn(taState);
            Org.Mockito.Mockito.When(taReport.GetDiagnosticInfo()).ThenReturn(string.Empty);
            Org.Mockito.Mockito.When(attempt.GetReport()).ThenReturn(taReport);
            attempts[taId] = attempt;
            Org.Mockito.Mockito.When(task.GetAttempts()).ThenReturn(attempts);
            app.SetTask(task);
            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.GetUserName()).ThenReturn("User");
            app.SetJob(job);
            TestBlocks.AttemptsBlockForTest block = new TestBlocks.AttemptsBlockForTest(this,
                                                                                        app);
            block.AddParameter(AMParams.TaskType, "r");
            PrintWriter pWriter = new PrintWriter(data);

            HtmlBlock.Block html = new BlockForTest(new TestBlocks.HtmlBlockForTest(this), pWriter
                                                    , 0, false);
            block.Render(html);
            pWriter.Flush();
            // should be printed information about attempts
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("0 attempt_0_0001_r_000000_0"
                                                                   ));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("SUCCEEDED"));
            NUnit.Framework.Assert.IsFalse(data.ToString().Contains("Processed 128/128 records <p> \n"
                                                                    ));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("Processed 128\\/128 records &lt;p&gt; \\n"
                                                                   ));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("_0005_01_000001:attempt_0_0001_r_000000_0:User:"******"100002"));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("100010"));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("100011"));
            NUnit.Framework.Assert.IsTrue(data.ToString().Contains("100012"));
        }