[120] | 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.mapred; |
---|
| 20 | |
---|
| 21 | import java.io.File; |
---|
| 22 | import java.io.IOException; |
---|
| 23 | |
---|
| 24 | import junit.framework.TestCase; |
---|
| 25 | |
---|
| 26 | import org.apache.hadoop.fs.Path; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * A JUnit test to test Kill Job & Fail Job functionality with local file |
---|
| 30 | * system. |
---|
| 31 | */ |
---|
| 32 | public class TestJobKillAndFail extends TestCase { |
---|
| 33 | |
---|
| 34 | private static String TEST_ROOT_DIR = new File(System.getProperty( |
---|
| 35 | "test.build.data", "/tmp")).toURI().toString().replace(' ', '+'); |
---|
| 36 | |
---|
| 37 | public void testJobFailAndKill() throws IOException { |
---|
| 38 | MiniMRCluster mr = null; |
---|
| 39 | try { |
---|
| 40 | mr = new MiniMRCluster(2, "file:///", 3); |
---|
| 41 | |
---|
| 42 | // run the TCs |
---|
| 43 | JobConf conf = mr.createJobConf(); |
---|
| 44 | |
---|
| 45 | Path inDir = new Path(TEST_ROOT_DIR + "/failkilljob/input"); |
---|
| 46 | Path outDir = new Path(TEST_ROOT_DIR + "/failkilljob/output"); |
---|
| 47 | RunningJob job = UtilsForTests.runJobFail(conf, inDir, outDir); |
---|
| 48 | // Checking that the Job got failed |
---|
| 49 | assertEquals(job.getJobState(), JobStatus.FAILED); |
---|
| 50 | |
---|
| 51 | job = UtilsForTests.runJobKill(conf, inDir, outDir); |
---|
| 52 | // Checking that the Job got killed |
---|
| 53 | assertTrue(job.isComplete()); |
---|
| 54 | assertEquals(job.getJobState(), JobStatus.KILLED); |
---|
| 55 | } finally { |
---|
| 56 | if (mr != null) { |
---|
| 57 | mr.shutdown(); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | } |
---|