1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.mapreduce.v2.app; 20 21 import java.util.Iterator; 22 import java.util.List; 23 24 import org.junit.Assert; 25 26 import org.apache.hadoop.conf.Configuration; 27 import org.apache.hadoop.mapreduce.MRJobConfig; 28 import org.apache.hadoop.mapreduce.v2.api.records.AMInfo; 29 import org.apache.hadoop.mapreduce.v2.api.records.JobState; 30 import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptState; 31 import org.apache.hadoop.mapreduce.v2.api.records.TaskState; 32 import org.apache.hadoop.mapreduce.v2.app.TestRecovery.MRAppWithHistory; 33 import org.apache.hadoop.mapreduce.v2.app.job.Job; 34 import org.apache.hadoop.mapreduce.v2.app.job.Task; 35 import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt; 36 import org.junit.Test; 37 38 public class TestAMInfos { 39 40 @Test testAMInfosWithoutRecoveryEnabled()41 public void testAMInfosWithoutRecoveryEnabled() throws Exception { 42 int runCount = 0; 43 MRApp app = 44 new MRAppWithHistory(1, 0, false, this.getClass().getName(), true, 45 ++runCount); 46 Configuration conf = new Configuration(); 47 conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); 48 Job job = app.submit(conf); 49 app.waitForState(job, JobState.RUNNING); 50 51 long am1StartTime = app.getAllAMInfos().get(0).getStartTime(); 52 53 Assert.assertEquals("No of tasks not correct", 1, job.getTasks().size()); 54 Iterator<Task> it = job.getTasks().values().iterator(); 55 Task mapTask = it.next(); 56 app.waitForState(mapTask, TaskState.RUNNING); 57 TaskAttempt taskAttempt = mapTask.getAttempts().values().iterator().next(); 58 app.waitForState(taskAttempt, TaskAttemptState.RUNNING); 59 60 // stop the app 61 app.stop(); 62 63 // rerun 64 app = 65 new MRAppWithHistory(1, 0, false, this.getClass().getName(), false, 66 ++runCount); 67 conf = new Configuration(); 68 // in rerun the AMInfo will be recovered from previous run even if recovery 69 // is not enabled. 70 conf.setBoolean(MRJobConfig.MR_AM_JOB_RECOVERY_ENABLE, false); 71 conf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, false); 72 job = app.submit(conf); 73 app.waitForState(job, JobState.RUNNING); 74 Assert.assertEquals("No of tasks not correct", 1, job.getTasks().size()); 75 it = job.getTasks().values().iterator(); 76 mapTask = it.next(); 77 // There should be two AMInfos 78 List<AMInfo> amInfos = app.getAllAMInfos(); 79 Assert.assertEquals(2, amInfos.size()); 80 AMInfo amInfoOne = amInfos.get(0); 81 Assert.assertEquals(am1StartTime, amInfoOne.getStartTime()); 82 app.stop(); 83 } 84 } 85