1 | /* Licensed to the Apache Software Foundation (ASF) under one |
---|
2 | * or more contributor license agreements. See the NOTICE file |
---|
3 | * distributed with this work for additional information |
---|
4 | * regarding copyright ownership. The ASF licenses this file |
---|
5 | * to you under the Apache License, Version 2.0 (the |
---|
6 | * "License"); you may not use this file except in compliance |
---|
7 | * with the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | package org.apache.hadoop.mapred; |
---|
18 | |
---|
19 | import junit.framework.TestCase; |
---|
20 | |
---|
21 | import org.apache.hadoop.conf.Configuration; |
---|
22 | import org.apache.hadoop.fs.*; |
---|
23 | import org.apache.hadoop.util.ToolRunner; |
---|
24 | import org.apache.hadoop.hdfs.MiniDFSCluster; |
---|
25 | |
---|
26 | public class TestCustomOutputCommitter extends TestCase { |
---|
27 | static final Path input = new Path("/test/input/"); |
---|
28 | static final Path output = new Path("/test/output"); |
---|
29 | |
---|
30 | public void testCommitter() throws Exception { |
---|
31 | MiniDFSCluster dfs = null; |
---|
32 | MiniMRCluster mr = null; |
---|
33 | FileSystem fs = null; |
---|
34 | Path testFile = new Path(input, "testfile"); |
---|
35 | try { |
---|
36 | Configuration conf = new Configuration(); |
---|
37 | |
---|
38 | //start the mini mr and dfs cluster. |
---|
39 | dfs = new MiniDFSCluster(conf, 2 , true, null); |
---|
40 | fs = dfs.getFileSystem(); |
---|
41 | FSDataOutputStream stream = fs.create(testFile); |
---|
42 | stream.write("teststring".getBytes()); |
---|
43 | stream.close(); |
---|
44 | |
---|
45 | mr = new MiniMRCluster(2, fs.getUri().toString(), 1); |
---|
46 | |
---|
47 | String[] args = new String[6]; |
---|
48 | args[0] = "-libjars"; |
---|
49 | // the testjob.jar as a temporary jar file |
---|
50 | // holding custom output committer |
---|
51 | args[1] = "build/test/testjar/testjob.jar"; |
---|
52 | args[2] = "-D"; |
---|
53 | args[3] = "mapred.output.committer.class=testjar.CustomOutputCommitter"; |
---|
54 | args[4] = input.toString(); |
---|
55 | args[5] = output.toString(); |
---|
56 | JobConf jobConf = mr.createJobConf(); |
---|
57 | int ret = ToolRunner.run(jobConf, new WordCount(), args); |
---|
58 | |
---|
59 | assertTrue("not failed ", ret == 0); |
---|
60 | } finally { |
---|
61 | if (dfs != null) {dfs.shutdown();}; |
---|
62 | if (mr != null) {mr.shutdown();}; |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|