source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestTrackerBlacklistAcrossJobs.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.2 KB
Line 
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 */
18package org.apache.hadoop.mapred;
19
20import java.io.IOException;
21
22import org.apache.hadoop.conf.Configuration;
23import org.apache.hadoop.examples.SleepJob.SleepInputFormat;
24import org.apache.hadoop.fs.FileSystem;
25import org.apache.hadoop.fs.Path;
26import org.apache.hadoop.hdfs.MiniDFSCluster;
27import org.apache.hadoop.io.IntWritable;
28import org.apache.hadoop.io.NullWritable;
29import org.apache.hadoop.mapred.lib.NullOutputFormat;
30
31import junit.framework.TestCase;
32
33public class TestTrackerBlacklistAcrossJobs extends TestCase {
34  private static final String hosts[] = new String[] {
35    "host1.rack.com", "host2.rack.com", "host3.rack.com"
36  };
37  final Path inDir = new Path("/testing");
38  final Path outDir = new Path("/output");
39
40  public static class SleepJobFailOnHost extends MapReduceBase
41    implements Mapper<IntWritable, IntWritable, IntWritable, NullWritable> {
42    String hostname = "";
43   
44    public void configure(JobConf job) {
45      this.hostname = job.get("slave.host.name");
46    }
47   
48    public void map(IntWritable key, IntWritable value,
49                    OutputCollector<IntWritable, NullWritable> output,
50                    Reporter reporter)
51    throws IOException {
52      if (this.hostname.equals(hosts[0])) {
53        // fail here
54        throw new IOException("failing on host: " + hosts[0]);
55      }
56    }
57  }
58 
59  public void testBlacklistAcrossJobs() throws IOException {
60    MiniDFSCluster dfs = null;
61    MiniMRCluster mr = null;
62    FileSystem fileSys = null;
63    Configuration conf = new Configuration();
64    // setup dfs and input
65    dfs = new MiniDFSCluster(conf, 1, true, null, hosts);
66    fileSys = dfs.getFileSystem();
67    if (!fileSys.mkdirs(inDir)) {
68      throw new IOException("Mkdirs failed to create " + inDir.toString());
69    }
70    UtilsForTests.writeFile(dfs.getNameNode(), conf, 
71                                 new Path(inDir + "/file"), (short) 1);
72    // start mr cluster
73    JobConf jtConf = new JobConf();
74    jtConf.setInt("mapred.max.tracker.blacklists", 1);
75    mr = new MiniMRCluster(3, fileSys.getUri().toString(),
76                           1, null, hosts, jtConf);
77
78    // setup job configuration
79    JobConf mrConf = mr.createJobConf();
80    JobConf job = new JobConf(mrConf);
81    job.setInt("mapred.max.tracker.failures", 1);
82    job.setNumMapTasks(30);
83    job.setNumReduceTasks(0);
84    job.setMapperClass(SleepJobFailOnHost.class);
85    job.setMapOutputKeyClass(IntWritable.class);
86    job.setMapOutputValueClass(NullWritable.class);
87    job.setOutputFormat(NullOutputFormat.class);
88    job.setInputFormat(SleepInputFormat.class);
89    FileInputFormat.setInputPaths(job, inDir);
90    FileOutputFormat.setOutputPath(job, outDir);
91   
92    // run the job
93    JobClient jc = new JobClient(mrConf);
94    RunningJob running = JobClient.runJob(job);
95    assertEquals("Job failed", JobStatus.SUCCEEDED, running.getJobState());
96    assertEquals("Didn't blacklist the host", 1, 
97      jc.getClusterStatus().getBlacklistedTrackers());
98    assertEquals("Fault count should be 1", 1, mr.getFaultCount(hosts[0]));
99
100    // run the same job once again
101    // there should be no change in blacklist count
102    running = JobClient.runJob(job);
103    assertEquals("Job failed", JobStatus.SUCCEEDED, running.getJobState());
104    assertEquals("Didn't blacklist the host", 1,
105      jc.getClusterStatus().getBlacklistedTrackers());
106    assertEquals("Fault count should be 1", 1, mr.getFaultCount(hosts[0]));
107  }
108}
Note: See TracBrowser for help on using the repository browser.