source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestJobHistoryParsing.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: 3.9 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
20
21import java.io.IOException;
22import java.io.PrintWriter;
23import java.util.ArrayList;
24import java.util.Map;
25
26import org.apache.hadoop.fs.FileSystem;
27import org.apache.hadoop.fs.Path;
28import org.apache.hadoop.mapred.JobHistory.*;
29
30import junit.framework.TestCase;
31
32public class TestJobHistoryParsing  extends TestCase {
33  ArrayList<PrintWriter> historyWriter = new ArrayList<PrintWriter>();
34
35  /**
36   * Listener for a test history log file, it populates JobHistory.JobInfo
37   * object with data from log file.
38   */
39  static class TestListener implements Listener {
40    JobInfo job;
41
42    TestListener(JobInfo job) {
43      this.job = job;
44    }
45    // JobHistory.Listener implementation
46    public void handle(RecordTypes recType, 
47                       Map<JobHistory.Keys, String> values)
48    throws IOException {
49      if (recType == JobHistory.RecordTypes.Job) {
50        job.handle(values);
51      }
52    }
53  }
54
55  public void testHistoryParsing() throws IOException {
56    // open a test history file
57    Path historyDir = new Path(System.getProperty("test.build.data", "."), 
58                                "history");
59    FileSystem fs = FileSystem.getLocal(new JobConf());
60    if (!fs.mkdirs(historyDir)) {
61      fail("Failed to create history directory");
62    }
63    Path historyLog = new Path(historyDir, "testlog");
64    PrintWriter out = new PrintWriter(fs.create(historyLog));
65    historyWriter.add(out);
66    // log keys and values into history
67    String value1 = "Value has equal=to, \"quotes\" and spaces in it";
68    String value2 = "Value has \n new line \n and " + 
69                    "dot followed by new line .\n in it ";
70    String value3 = "Value has characters: " +
71                    "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./" +
72                    "~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"'ZXCVBNM<>?" + 
73                    "\t\b\n\f\"\n in it";
74    String value4 = "Value ends with escape\\";
75    String value5 = "Value ends with \\\" \\.\n";
76   
77    // Log the history version
78    JobHistory.MetaInfoManager.logMetaInfo(historyWriter);
79   
80    JobHistory.log(historyWriter, RecordTypes.Job, 
81                   new JobHistory.Keys[] {Keys.JOBTRACKERID, 
82                                          Keys.TRACKER_NAME, 
83                                          Keys.JOBNAME, 
84                                          Keys.JOBCONF,
85                                          Keys.USER},
86                   new String[] {value1, value2, value3, value4, value5});
87    // close history file
88    out.close();
89    historyWriter.remove(out);
90
91    // parse history
92    String jobId = "job_200809171136_0001"; // random jobid for tesing
93    JobHistory.JobInfo job = new JobHistory.JobInfo(jobId);
94    JobHistory.parseHistoryFromFS(historyLog.toString(), 
95                 new TestListener(job), fs);
96    // validate keys and values
97    assertEquals(value1, job.get(Keys.JOBTRACKERID));
98    assertEquals(value2, job.get(Keys.TRACKER_NAME));
99    assertEquals(value3, job.get(Keys.JOBNAME));
100    assertEquals(value4, job.get(Keys.JOBCONF));
101    assertEquals(value5, job.get(Keys.USER));
102  }
103}
Note: See TracBrowser for help on using the repository browser.