diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 43e32c14e40..321576664e9 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -66,6 +66,9 @@ Release 2.0.4-beta - UNRELEASED HADOOP-9349. Confusing output when running hadoop version from one hadoop installation when HADOOP_HOME points to another. (sandyr via tucu) + HADOOP-9337. org.apache.hadoop.fs.DF.getMount() does not work on Mac OS. + (Ivan A. Veselovsky via atm) + Release 2.0.3-alpha - 2013-02-06 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DF.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DF.java index 81a36cb41d1..de1548e5eab 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DF.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DF.java @@ -166,7 +166,7 @@ public class DF extends Shell { @Override protected String[] getExecString() { // ignoring the error since the exit code it enough - return new String[] {"bash","-c","exec 'df' '-k' '" + dirPath + return new String[] {"bash","-c","exec 'df' '-k' '-P' '" + dirPath + "' 2>/dev/null"}; } @@ -210,28 +210,11 @@ public class DF extends Shell { } try { - switch(getOSType()) { - case OS_TYPE_AIX: - Long.parseLong(tokens.nextToken()); // capacity - Long.parseLong(tokens.nextToken()); // available - Integer.parseInt(tokens.nextToken()); // pct used - tokens.nextToken(); - tokens.nextToken(); - this.mount = tokens.nextToken(); - break; - - case OS_TYPE_WIN: - case OS_TYPE_SOLARIS: - case OS_TYPE_MAC: - case OS_TYPE_UNIX: - default: - Long.parseLong(tokens.nextToken()); // capacity - Long.parseLong(tokens.nextToken()); // used - Long.parseLong(tokens.nextToken()); // available - Integer.parseInt(tokens.nextToken()); // pct used - this.mount = tokens.nextToken(); - break; - } + Long.parseLong(tokens.nextToken()); // capacity + Long.parseLong(tokens.nextToken()); // used + Long.parseLong(tokens.nextToken()); // available + Integer.parseInt(tokens.nextToken()); // pct used + this.mount = tokens.nextToken(); } catch (NoSuchElementException e) { throw new IOException("Could not parse line: " + line); } catch (NumberFormatException e) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFVariations.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFVariations.java index 66048f0e2d1..fcd518fbfb3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFVariations.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDFVariations.java @@ -30,6 +30,7 @@ import java.util.Random; import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; +import static org.junit.Assert.*; public class TestDFVariations { @@ -45,14 +46,8 @@ public class TestDFVariations { } @Override protected String[] getExecString() { - switch(getOSType()) { - case OS_TYPE_AIX: - return new String[] { "echo", "IGNORE\n", "/dev/sda3", - "453115160", "400077240", "11%", "18", "skip%", "/foo/bar", "\n" }; - default: - return new String[] { "echo", "IGNORE\n", "/dev/sda3", - "453115160", "53037920", "400077240", "11%", "/foo/bar", "\n" }; - } + return new String[] { "echo", "IGNORE\n", + "/dev/sda3", "453115160", "53037920", "400077240", "11%", "/foo/bar\n"}; } } @@ -132,5 +127,20 @@ public class TestDFVariations { System.out.println(e.toString()); } } + + @Test(timeout=5000) + public void testGetMountCurrentDirectory() throws Exception { + File currentDirectory = new File("."); + String workingDir = currentDirectory.getAbsoluteFile().getCanonicalPath(); + DF df = new DF(new File(workingDir), 0L); + String mountPath = df.getMount(); + File mountDir = new File(mountPath); + assertTrue("Mount dir ["+mountDir.getAbsolutePath()+"] should exist.", + mountDir.exists()); + assertTrue("Mount dir ["+mountDir.getAbsolutePath()+"] should be directory.", + mountDir.isDirectory()); + assertTrue("Working dir ["+workingDir+"] should start with ["+mountPath+"].", + workingDir.startsWith(mountPath)); + } }