Author: sradia Date: Thu Jun 21 00:43:16 2012 New Revision: 1352377 URL: http://svn.apache.org/viewvc?rev=1352377&view=rev Log: HADOOP-8409 Fix TestCommandLineJobSubmission and TestGenericOptionsParser to work for windows (Ivan Mitic via Sanjay Radia)
Modified: hadoop/common/branches/branch-1-win/CHANGES.txt hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestCommandLineJobSubmission.java hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestGenericOptionsParser.java Modified: hadoop/common/branches/branch-1-win/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.txt?rev=1352377&r1=1352376&r2=1352377&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/CHANGES.txt (original) +++ hadoop/common/branches/branch-1-win/CHANGES.txt Thu Jun 21 00:43:16 2012 @@ -35,6 +35,8 @@ branch-hadoop-1-win - unreleased HADOOP-8440 HarFileSystem.decodeHarURI 2nd patch (HADOOP-8440-branch-1-win.2.patch) (Ivan Mitic via Sanjay Radia) + HADOOP-8409 Fix TestCommandLineJobSubmission and TestGenericOptionsParser to work for windows (Ivan Mitic via Sanjay Radia) + Release 1.1.0 - unreleased Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestCommandLineJobSubmission.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestCommandLineJobSubmission.java?rev=1352377&r1=1352376&r2=1352377&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestCommandLineJobSubmission.java (original) +++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestCommandLineJobSubmission.java Thu Jun 21 00:43:16 2012 @@ -57,7 +57,11 @@ public class TestCommandLineJobSubmissio stream.close(); mr = new MiniMRCluster(2, fs.getUri().toString(), 1); File thisbuildDir = new File(buildDir, "jobCommand"); - assertTrue("create build dir", thisbuildDir.mkdirs()); + // Create the build dir only if it does not exist as mkdirs + // fails on Windows otherwise + if (!thisbuildDir.exists()) { + assertTrue("create build dir", thisbuildDir.mkdirs()); + } File f = new File(thisbuildDir, "files_tmp"); FileOutputStream fstream = new FileOutputStream(f); fstream.write("somestrings".getBytes()); @@ -85,20 +89,21 @@ public class TestCommandLineJobSubmissio // construct options for -files String[] files = new String[3]; - files[0] = f.toString(); - files[1] = f1.toString() + "#localfilelink"; + files[0] = f.toURI().toString(); + files[1] = f1.toURI().toString() + "#localfilelink"; files[2] = fs.getUri().resolve(cachePath + "/test.txt#dfsfilelink").toString(); // construct options for -libjars String[] libjars = new String[2]; - libjars[0] = "build/test/testjar/testjob.jar"; + libjars[0] = new File(System.getProperty("test.build.dir", "build/test"), + "testjar/testjob.jar").toURI().toString(); libjars[1] = fs.getUri().resolve(cachePath + "/test.jar").toString(); // construct options for -archives String[] archives = new String[4]; - archives[0] = tgzPath.toString(); - archives[1] = tarPath + "#tarlink"; + archives[0] = tgzPath.toUri().toString(); + archives[1] = tarPath.toUri().toString() + "#tarlink"; archives[2] = fs.getUri().resolve(cachePath + "/test.zip#ziplink").toString(); archives[3] = @@ -142,7 +147,10 @@ public class TestCommandLineJobSubmissio Configuration jobConf = mr.createJobConf(); FileSystem fs = dfs.getFileSystem(); Path dfsPath = new Path("/test/testjob.jar"); - fs.copyFromLocalFile(new Path("build/test/testjar/testjob.jar"), dfsPath); + fs.copyFromLocalFile( + new Path(System.getProperty("test.build.dir", "build/test"), + "testjar/testjob.jar"), + dfsPath); String url = fs.getDefaultUri(jobConf).toString() + dfsPath.toString(); String[] args = new String[6]; args[0] = "-files"; Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestGenericOptionsParser.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestGenericOptionsParser.java?rev=1352377&r1=1352376&r2=1352377&view=diff ============================================================================== --- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestGenericOptionsParser.java (original) +++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestGenericOptionsParser.java Thu Jun 21 00:43:16 2012 @@ -95,7 +95,9 @@ public class TestGenericOptionsParser ex String[] args = new String[2]; // pass a files option args[0] = "-files"; - args[1] = tmpFile.toString(); + // Convert a file to a URI as File.toString() is not a valid URI on + // all platforms and GenericOptionsParser accepts only valid URIs + args[1] = tmpFile.toURI().toString(); new GenericOptionsParser(conf, args); String files = conf.get("tmpfiles"); assertNotNull("files is null", files); @@ -104,7 +106,7 @@ public class TestGenericOptionsParser ex // pass file as uri Configuration conf1 = new Configuration(); - URI tmpURI = new URI(tmpFile.toString() + "#link"); + URI tmpURI = new URI(tmpFile.toURI().toString() + "#link"); args[0] = "-files"; args[1] = tmpURI.toString(); new GenericOptionsParser(conf1, args);