TestJobName.java
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:4k
源码类别:

网格计算

开发平台:

Java

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