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 junit.framework.TestCase; |
---|
21 | |
---|
22 | import org.apache.hadoop.fs.Path; |
---|
23 | import org.apache.hadoop.mapred.FileInputFormat; |
---|
24 | import org.apache.hadoop.mapred.JobConf; |
---|
25 | import org.apache.hadoop.util.StringUtils; |
---|
26 | |
---|
27 | public class TestInputPath extends TestCase { |
---|
28 | public void testInputPath() throws Exception { |
---|
29 | JobConf jobConf = new JobConf(); |
---|
30 | Path workingDir = jobConf.getWorkingDirectory(); |
---|
31 | |
---|
32 | Path path = new Path(workingDir, |
---|
33 | "xx{y"+StringUtils.COMMA_STR+"z}"); |
---|
34 | FileInputFormat.setInputPaths(jobConf, path); |
---|
35 | Path[] paths = FileInputFormat.getInputPaths(jobConf); |
---|
36 | assertEquals(1, paths.length); |
---|
37 | assertEquals(path.toString(), paths[0].toString()); |
---|
38 | |
---|
39 | StringBuilder pathStr = new StringBuilder(); |
---|
40 | pathStr.append(StringUtils.ESCAPE_CHAR); |
---|
41 | pathStr.append(StringUtils.ESCAPE_CHAR); |
---|
42 | pathStr.append(StringUtils.COMMA); |
---|
43 | pathStr.append(StringUtils.COMMA); |
---|
44 | pathStr.append('a'); |
---|
45 | path = new Path(workingDir, pathStr.toString()); |
---|
46 | FileInputFormat.setInputPaths(jobConf, path); |
---|
47 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
48 | assertEquals(1, paths.length); |
---|
49 | assertEquals(path.toString(), paths[0].toString()); |
---|
50 | |
---|
51 | pathStr.setLength(0); |
---|
52 | pathStr.append(StringUtils.ESCAPE_CHAR); |
---|
53 | pathStr.append("xx"); |
---|
54 | pathStr.append(StringUtils.ESCAPE_CHAR); |
---|
55 | path = new Path(workingDir, pathStr.toString()); |
---|
56 | Path path1 = new Path(workingDir, |
---|
57 | "yy"+StringUtils.COMMA_STR+"zz"); |
---|
58 | FileInputFormat.setInputPaths(jobConf, path); |
---|
59 | FileInputFormat.addInputPath(jobConf, path1); |
---|
60 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
61 | assertEquals(2, paths.length); |
---|
62 | assertEquals(path.toString(), paths[0].toString()); |
---|
63 | assertEquals(path1.toString(), paths[1].toString()); |
---|
64 | |
---|
65 | FileInputFormat.setInputPaths(jobConf, path, path1); |
---|
66 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
67 | assertEquals(2, paths.length); |
---|
68 | assertEquals(path.toString(), paths[0].toString()); |
---|
69 | assertEquals(path1.toString(), paths[1].toString()); |
---|
70 | |
---|
71 | Path[] input = new Path[] {path, path1}; |
---|
72 | FileInputFormat.setInputPaths(jobConf, input); |
---|
73 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
74 | assertEquals(2, paths.length); |
---|
75 | assertEquals(path.toString(), paths[0].toString()); |
---|
76 | assertEquals(path1.toString(), paths[1].toString()); |
---|
77 | |
---|
78 | pathStr.setLength(0); |
---|
79 | String str1 = "{a{b,c},de}"; |
---|
80 | String str2 = "xyz"; |
---|
81 | String str3 = "x{y,z}"; |
---|
82 | pathStr.append(str1); |
---|
83 | pathStr.append(StringUtils.COMMA); |
---|
84 | pathStr.append(str2); |
---|
85 | pathStr.append(StringUtils.COMMA); |
---|
86 | pathStr.append(str3); |
---|
87 | FileInputFormat.setInputPaths(jobConf, pathStr.toString()); |
---|
88 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
89 | assertEquals(3, paths.length); |
---|
90 | assertEquals(new Path(workingDir, str1).toString(), paths[0].toString()); |
---|
91 | assertEquals(new Path(workingDir, str2).toString(), paths[1].toString()); |
---|
92 | assertEquals(new Path(workingDir, str3).toString(), paths[2].toString()); |
---|
93 | |
---|
94 | pathStr.setLength(0); |
---|
95 | String str4 = "abc"; |
---|
96 | String str5 = "pq{r,s}"; |
---|
97 | pathStr.append(str4); |
---|
98 | pathStr.append(StringUtils.COMMA); |
---|
99 | pathStr.append(str5); |
---|
100 | FileInputFormat.addInputPaths(jobConf, pathStr.toString()); |
---|
101 | paths = FileInputFormat.getInputPaths(jobConf); |
---|
102 | assertEquals(5, paths.length); |
---|
103 | assertEquals(new Path(workingDir, str1).toString(), paths[0].toString()); |
---|
104 | assertEquals(new Path(workingDir, str2).toString(), paths[1].toString()); |
---|
105 | assertEquals(new Path(workingDir, str3).toString(), paths[2].toString()); |
---|
106 | assertEquals(new Path(workingDir, str4).toString(), paths[3].toString()); |
---|
107 | assertEquals(new Path(workingDir, str5).toString(), paths[4].toString()); |
---|
108 | } |
---|
109 | } |
---|