From e998b63dd9ad42101a16fa1659acb6715c2efcab Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Tue, 5 Mar 2013 01:33:29 +0000 Subject: [PATCH] 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 --- .../hadoop-common/CHANGES.txt | 3 ++ .../main/java/org/apache/hadoop/fs/DF.java | 29 ++++--------------- .../apache/hadoop/fs/TestDFVariations.java | 26 ++++++++++++----- 3 files changed, 27 insertions(+), 31 deletions(-) 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 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; - } + 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 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)); + } }