HADOOP-9337. org.apache.hadoop.fs.DF.getMount() does not work on Mac OS. Contributed by Ivan A. Veselovsky.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1452624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Aaron Myers 2013-03-05 01:33:29 +00:00
parent 3cfae3cc79
commit e998b63dd9
3 changed files with 27 additions and 31 deletions

View File

@ -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

View File

@ -166,7 +166,7 @@ public String toString() {
@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 @@ protected void parseOutput() throws IOException {
}
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;
}
} catch (NoSuchElementException e) {
throw new IOException("Could not parse line: " + line);
} catch (NumberFormatException e) {

View File

@ -30,6 +30,7 @@
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test;
import static org.junit.Assert.*;
public class TestDFVariations {
@ -45,14 +46,8 @@ public DF.OSType getOSType() {
}
@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 void testDFMalformedOutput() throws Exception {
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));
}
}