[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 | package org.apache.hadoop.mapred; |
---|
| 19 | |
---|
| 20 | import java.io.BufferedReader; |
---|
| 21 | import java.io.IOException; |
---|
| 22 | import java.io.InputStream; |
---|
| 23 | import java.io.InputStreamReader; |
---|
| 24 | import java.io.OutputStream; |
---|
| 25 | import java.io.OutputStreamWriter; |
---|
| 26 | import java.io.Writer; |
---|
| 27 | import java.util.Iterator; |
---|
| 28 | import java.util.StringTokenizer; |
---|
| 29 | |
---|
| 30 | import org.apache.hadoop.fs.FileUtil; |
---|
| 31 | import org.apache.hadoop.fs.Path; |
---|
| 32 | import org.apache.hadoop.io.LongWritable; |
---|
| 33 | import org.apache.hadoop.io.Text; |
---|
| 34 | import org.apache.hadoop.io.serializer.JavaSerializationComparator; |
---|
| 35 | import org.apache.hadoop.mapred.lib.IdentityMapper; |
---|
| 36 | |
---|
| 37 | public class TestJobName extends ClusterMapReduceTestCase { |
---|
| 38 | |
---|
| 39 | public void testComplexName() throws Exception { |
---|
| 40 | OutputStream os = getFileSystem().create(new Path(getInputDir(), |
---|
| 41 | "text.txt")); |
---|
| 42 | Writer wr = new OutputStreamWriter(os); |
---|
| 43 | wr.write("b a\n"); |
---|
| 44 | wr.close(); |
---|
| 45 | |
---|
| 46 | JobConf conf = createJobConf(); |
---|
| 47 | conf.setJobName("[name][some other value that gets truncated internally that this test attempts to aggravate]"); |
---|
| 48 | |
---|
| 49 | conf.setInputFormat(TextInputFormat.class); |
---|
| 50 | |
---|
| 51 | conf.setOutputKeyClass(LongWritable.class); |
---|
| 52 | conf.setOutputValueClass(Text.class); |
---|
| 53 | |
---|
| 54 | conf.setMapperClass(IdentityMapper.class); |
---|
| 55 | |
---|
| 56 | FileInputFormat.setInputPaths(conf, getInputDir()); |
---|
| 57 | |
---|
| 58 | FileOutputFormat.setOutputPath(conf, getOutputDir()); |
---|
| 59 | |
---|
| 60 | JobClient.runJob(conf); |
---|
| 61 | |
---|
| 62 | Path[] outputFiles = FileUtil.stat2Paths( |
---|
| 63 | getFileSystem().listStatus(getOutputDir(), |
---|
| 64 | new OutputLogFilter())); |
---|
| 65 | assertEquals(1, outputFiles.length); |
---|
| 66 | InputStream is = getFileSystem().open(outputFiles[0]); |
---|
| 67 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
---|
| 68 | assertEquals("0\tb a", reader.readLine()); |
---|
| 69 | assertNull(reader.readLine()); |
---|
| 70 | reader.close(); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | public void testComplexNameWithRegex() throws Exception { |
---|
| 74 | OutputStream os = getFileSystem().create(new Path(getInputDir(), |
---|
| 75 | "text.txt")); |
---|
| 76 | Writer wr = new OutputStreamWriter(os); |
---|
| 77 | wr.write("b a\n"); |
---|
| 78 | wr.close(); |
---|
| 79 | |
---|
| 80 | JobConf conf = createJobConf(); |
---|
| 81 | conf.setJobName("name \\Evalue]"); |
---|
| 82 | |
---|
| 83 | conf.setInputFormat(TextInputFormat.class); |
---|
| 84 | |
---|
| 85 | conf.setOutputKeyClass(LongWritable.class); |
---|
| 86 | conf.setOutputValueClass(Text.class); |
---|
| 87 | |
---|
| 88 | conf.setMapperClass(IdentityMapper.class); |
---|
| 89 | |
---|
| 90 | FileInputFormat.setInputPaths(conf, getInputDir()); |
---|
| 91 | |
---|
| 92 | FileOutputFormat.setOutputPath(conf, getOutputDir()); |
---|
| 93 | |
---|
| 94 | JobClient.runJob(conf); |
---|
| 95 | |
---|
| 96 | Path[] outputFiles = FileUtil.stat2Paths( |
---|
| 97 | getFileSystem().listStatus(getOutputDir(), |
---|
| 98 | new OutputLogFilter())); |
---|
| 99 | assertEquals(1, outputFiles.length); |
---|
| 100 | InputStream is = getFileSystem().open(outputFiles[0]); |
---|
| 101 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
---|
| 102 | assertEquals("0\tb a", reader.readLine()); |
---|
| 103 | assertNull(reader.readLine()); |
---|
| 104 | reader.close(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | } |
---|