HADOOP-9915. o.a.h.fs.Stat support on Mac OS X (Contributed by Binglin Chang)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1520190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Colin McCabe 2013-09-05 01:46:14 +00:00
parent 1e513bfc68
commit 4f46801111
3 changed files with 26 additions and 3 deletions

View File

@ -105,6 +105,9 @@ Trunk (Unreleased)
HADOOP-9833 move slf4j to version 1.7.5 (Kousuke Saruta via stevel) HADOOP-9833 move slf4j to version 1.7.5 (Kousuke Saruta via stevel)
HADOOP-9915. o.a.h.fs.Stat support on Mac OS X (Binglin Chang via Colin
Patrick McCabe)
BUG FIXES BUG FIXES
HADOOP-9451. Fault single-layer config if node group topology is enabled. HADOOP-9451. Fault single-layer config if node group topology is enabled.

View File

@ -80,7 +80,7 @@ public FileStatus getFileStatus() throws IOException {
* @return * @return
*/ */
public static boolean isAvailable() { public static boolean isAvailable() {
if (Shell.LINUX || Shell.FREEBSD) { if (Shell.LINUX || Shell.FREEBSD || Shell.MAC) {
return true; return true;
} }
return false; return false;
@ -100,7 +100,7 @@ protected String[] getExecString() {
if (Shell.LINUX) { if (Shell.LINUX) {
return new String[] { return new String[] {
"stat", derefFlag + "c", "%s,%F,%Y,%X,%a,%U,%G,%N", path.toString() }; "stat", derefFlag + "c", "%s,%F,%Y,%X,%a,%U,%G,%N", path.toString() };
} else if (Shell.FREEBSD) { } else if (Shell.FREEBSD || Shell.MAC) {
return new String[] { return new String[] {
"stat", derefFlag + "f", "%z,%HT,%m,%a,%Op,%Su,%Sg,`link' -> `%Y'", "stat", derefFlag + "f", "%z,%HT,%m,%a,%Op,%Su,%Sg,`link' -> `%Y'",
path.toString() }; path.toString() };

View File

@ -19,6 +19,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -26,10 +27,11 @@
import java.io.StringReader; import java.io.StringReader;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.junit.Assume;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
public class TestStat { public class TestStat extends FileSystemTestHelper {
private static Stat stat; private static Stat stat;
@ -113,6 +115,7 @@ public void testStatFreeBSD() throws Exception {
@Test(timeout=10000) @Test(timeout=10000)
public void testStatFileNotFound() throws Exception { public void testStatFileNotFound() throws Exception {
Assume.assumeTrue(Stat.isAvailable());
try { try {
stat.getFileStatus(); stat.getFileStatus();
fail("Expected FileNotFoundException"); fail("Expected FileNotFoundException");
@ -125,4 +128,21 @@ public void testStatFileNotFound() throws Exception {
public void testStatEnvironment() throws Exception { public void testStatEnvironment() throws Exception {
assertEquals(stat.getEnvironment("LANG"), "C"); assertEquals(stat.getEnvironment("LANG"), "C");
} }
@Test(timeout=10000)
public void testStat() throws Exception {
Assume.assumeTrue(Stat.isAvailable());
FileSystem fs = FileSystem.getLocal(new Configuration());
Path testDir = new Path(getTestRootPath(fs), "teststat");
fs.mkdirs(testDir);
Path sub1 = new Path(testDir, "sub1");
Path sub2 = new Path(testDir, "sub2");
fs.mkdirs(sub1);
fs.createSymlink(sub1, sub2, false);
FileStatus stat1 = new Stat(sub1, 4096l, false, fs).getFileStatus();
FileStatus stat2 = new Stat(sub2, 0, false, fs).getFileStatus();
assertTrue(stat1.isDirectory());
assertFalse(stat2.isDirectory());
fs.delete(testDir, true);
}
} }