[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.util.Properties; |
---|
| 22 | |
---|
| 23 | import org.apache.commons.logging.Log; |
---|
| 24 | import org.apache.commons.logging.LogFactory; |
---|
| 25 | import org.apache.hadoop.mapred.ControlledMapReduceJob.ControlledMapReduceJobRunner; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Test to verify the controlled behavior of a ControlledMapReduceJob. |
---|
| 29 | * |
---|
| 30 | */ |
---|
| 31 | public class TestControlledMapReduceJob extends ClusterMapReduceTestCase { |
---|
| 32 | static final Log LOG = LogFactory.getLog(TestControlledMapReduceJob.class); |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Starts a job with 5 maps and 5 reduces. Then controls the finishing of |
---|
| 36 | * tasks. Signals finishing tasks in batches and then verifies their |
---|
| 37 | * completion. |
---|
| 38 | * |
---|
| 39 | * @throws Exception |
---|
| 40 | */ |
---|
| 41 | public void testControlledMapReduceJob() |
---|
| 42 | throws Exception { |
---|
| 43 | |
---|
| 44 | Properties props = new Properties(); |
---|
| 45 | props.setProperty("mapred.tasktracker.map.tasks.maximum", "2"); |
---|
| 46 | props.setProperty("mapred.tasktracker.reduce.tasks.maximum", "2"); |
---|
| 47 | startCluster(true, props); |
---|
| 48 | LOG.info("Started the cluster"); |
---|
| 49 | |
---|
| 50 | ControlledMapReduceJobRunner jobRunner = |
---|
| 51 | ControlledMapReduceJobRunner |
---|
| 52 | .getControlledMapReduceJobRunner(createJobConf(), 7, 6); |
---|
| 53 | jobRunner.start(); |
---|
| 54 | ControlledMapReduceJob controlledJob = jobRunner.getJob(); |
---|
| 55 | JobInProgress jip = |
---|
| 56 | getMRCluster().getJobTrackerRunner().getJobTracker().getJob( |
---|
| 57 | jobRunner.getJobID()); |
---|
| 58 | |
---|
| 59 | ControlledMapReduceJob.waitTillNTasksStartRunning(jip, true, 4); |
---|
| 60 | LOG.info("Finishing 3 maps"); |
---|
| 61 | controlledJob.finishNTasks(true, 3); |
---|
| 62 | ControlledMapReduceJob.waitTillNTotalTasksFinish(jip, true, 3); |
---|
| 63 | |
---|
| 64 | ControlledMapReduceJob.waitTillNTasksStartRunning(jip, true, 4); |
---|
| 65 | LOG.info("Finishing 4 more maps"); |
---|
| 66 | controlledJob.finishNTasks(true, 4); |
---|
| 67 | ControlledMapReduceJob.waitTillNTotalTasksFinish(jip, true, 7); |
---|
| 68 | |
---|
| 69 | ControlledMapReduceJob.waitTillNTasksStartRunning(jip, false, 4); |
---|
| 70 | LOG.info("Finishing 2 reduces"); |
---|
| 71 | controlledJob.finishNTasks(false, 2); |
---|
| 72 | ControlledMapReduceJob.waitTillNTotalTasksFinish(jip, false, 2); |
---|
| 73 | |
---|
| 74 | ControlledMapReduceJob.waitTillNTasksStartRunning(jip, false, 4); |
---|
| 75 | LOG.info("Finishing 4 more reduces"); |
---|
| 76 | controlledJob.finishNTasks(false, 4); |
---|
| 77 | ControlledMapReduceJob.waitTillNTotalTasksFinish(jip, false, 6); |
---|
| 78 | |
---|
| 79 | jobRunner.join(); |
---|
| 80 | } |
---|
| 81 | } |
---|