/** * Copyright (c) 2010 Yahoo! Inc. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. See accompanying LICENSE file. */ package org.apache.oozie.action.hadoop; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.oozie.util.XConfiguration; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Properties; public class TestMapReduceMain extends MainTestCase { public Void call() throws Exception { FileSystem fs = getFileSystem(); Path inputDir = new Path(getFsTestCaseDir(), "input"); fs.mkdirs(inputDir); Writer writer = new OutputStreamWriter(fs.create(new Path(inputDir, "data.txt"))); writer.write("hello"); writer.close(); Path outputDir = new Path(getFsTestCaseDir(), "output"); XConfiguration jobConf = new XConfiguration(); jobConf.setInt("mapred.map.tasks", 1); jobConf.setInt("mapred.map.max.attempts", 1); jobConf.setInt("mapred.reduce.max.attempts", 1); jobConf.set("mapred.job.tracker", getJobTrackerUri()); jobConf.set("fs.default.name", getNameNodeUri()); jobConf.set("mapred.input.dir", inputDir.toString()); jobConf.set("mapred.output.dir", outputDir.toString()); jobConf.set("user.name", getTestUser()); jobConf.set("hadoop.job.ugi", getTestUser() + "," + getTestGroup()); injectKerberosInfo(jobConf); File actionXml = new File(getTestCaseDir(), "action.xml"); OutputStream os = new FileOutputStream(actionXml); jobConf.writeXml(os); os.close(); File newIdProperties = new File(getTestCaseDir(), "newId.properties"); System.setProperty("oozie.action.conf.xml", actionXml.getAbsolutePath()); System.setProperty("oozie.action.newId.properties", newIdProperties.getAbsolutePath()); MapReduceMain.main(new String[0]); assertTrue(newIdProperties.exists()); InputStream is = new FileInputStream(newIdProperties); Properties props = new Properties(); props.load(is); is.close(); assertTrue(props.containsKey("id")); return null; } }