|
@@ -55,6 +55,9 @@ import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.util.NativeCodeLoader;
|
|
import org.apache.hadoop.util.NativeCodeLoader;
|
|
import org.apache.hadoop.util.Time;
|
|
import org.apache.hadoop.util.Time;
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.io.nativeio.NativeIO.POSIX.*;
|
|
|
|
+import static org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat.*;
|
|
|
|
+
|
|
public class TestNativeIO {
|
|
public class TestNativeIO {
|
|
static final Log LOG = LogFactory.getLog(TestNativeIO.class);
|
|
static final Log LOG = LogFactory.getLog(TestNativeIO.class);
|
|
|
|
|
|
@@ -93,9 +96,8 @@ public class TestNativeIO {
|
|
assertEquals(expectedOwner, owner);
|
|
assertEquals(expectedOwner, owner);
|
|
assertNotNull(stat.getGroup());
|
|
assertNotNull(stat.getGroup());
|
|
assertTrue(!stat.getGroup().isEmpty());
|
|
assertTrue(!stat.getGroup().isEmpty());
|
|
- assertEquals("Stat mode field should indicate a regular file",
|
|
|
|
- NativeIO.POSIX.Stat.S_IFREG,
|
|
|
|
- stat.getMode() & NativeIO.POSIX.Stat.S_IFMT);
|
|
|
|
|
|
+ assertEquals("Stat mode field should indicate a regular file", S_IFREG,
|
|
|
|
+ stat.getMode() & S_IFMT);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -128,8 +130,7 @@ public class TestNativeIO {
|
|
assertNotNull(stat.getGroup());
|
|
assertNotNull(stat.getGroup());
|
|
assertTrue(!stat.getGroup().isEmpty());
|
|
assertTrue(!stat.getGroup().isEmpty());
|
|
assertEquals("Stat mode field should indicate a regular file",
|
|
assertEquals("Stat mode field should indicate a regular file",
|
|
- NativeIO.POSIX.Stat.S_IFREG,
|
|
|
|
- stat.getMode() & NativeIO.POSIX.Stat.S_IFMT);
|
|
|
|
|
|
+ S_IFREG, stat.getMode() & S_IFMT);
|
|
} catch (Throwable t) {
|
|
} catch (Throwable t) {
|
|
thrown.set(t);
|
|
thrown.set(t);
|
|
}
|
|
}
|
|
@@ -338,8 +339,7 @@ public class TestNativeIO {
|
|
LOG.info("Open a missing file without O_CREAT and it should fail");
|
|
LOG.info("Open a missing file without O_CREAT and it should fail");
|
|
try {
|
|
try {
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
- new File(TEST_DIR, "doesntexist").getAbsolutePath(),
|
|
|
|
- NativeIO.POSIX.O_WRONLY, 0700);
|
|
|
|
|
|
+ new File(TEST_DIR, "doesntexist").getAbsolutePath(), O_WRONLY, 0700);
|
|
fail("Able to open a new file without O_CREAT");
|
|
fail("Able to open a new file without O_CREAT");
|
|
} catch (NativeIOException nioe) {
|
|
} catch (NativeIOException nioe) {
|
|
LOG.info("Got expected exception", nioe);
|
|
LOG.info("Got expected exception", nioe);
|
|
@@ -356,7 +356,7 @@ public class TestNativeIO {
|
|
LOG.info("Test creating a file with O_CREAT");
|
|
LOG.info("Test creating a file with O_CREAT");
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
|
|
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
|
|
- NativeIO.POSIX.O_WRONLY | NativeIO.POSIX.O_CREAT, 0700);
|
|
|
|
|
|
+ O_WRONLY | O_CREAT, 0700);
|
|
assertNotNull(true);
|
|
assertNotNull(true);
|
|
assertTrue(fd.valid());
|
|
assertTrue(fd.valid());
|
|
FileOutputStream fos = new FileOutputStream(fd);
|
|
FileOutputStream fos = new FileOutputStream(fd);
|
|
@@ -369,7 +369,7 @@ public class TestNativeIO {
|
|
try {
|
|
try {
|
|
fd = NativeIO.POSIX.open(
|
|
fd = NativeIO.POSIX.open(
|
|
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
|
|
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
|
|
- NativeIO.POSIX.O_WRONLY | NativeIO.POSIX.O_CREAT | NativeIO.POSIX.O_EXCL, 0700);
|
|
|
|
|
|
+ O_WRONLY | O_CREAT | O_EXCL, 0700);
|
|
fail("Was able to create existing file with O_EXCL");
|
|
fail("Was able to create existing file with O_EXCL");
|
|
} catch (NativeIOException nioe) {
|
|
} catch (NativeIOException nioe) {
|
|
LOG.info("Got expected exception for failed exclusive create", nioe);
|
|
LOG.info("Got expected exception for failed exclusive create", nioe);
|
|
@@ -390,7 +390,7 @@ public class TestNativeIO {
|
|
for (int i = 0; i < 10000; i++) {
|
|
for (int i = 0; i < 10000; i++) {
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
FileDescriptor fd = NativeIO.POSIX.open(
|
|
new File(TEST_DIR, "testNoFdLeak").getAbsolutePath(),
|
|
new File(TEST_DIR, "testNoFdLeak").getAbsolutePath(),
|
|
- NativeIO.POSIX.O_WRONLY | NativeIO.POSIX.O_CREAT, 0700);
|
|
|
|
|
|
+ O_WRONLY | O_CREAT, 0700);
|
|
assertNotNull(true);
|
|
assertNotNull(true);
|
|
assertTrue(fd.valid());
|
|
assertTrue(fd.valid());
|
|
FileOutputStream fos = new FileOutputStream(fd);
|
|
FileOutputStream fos = new FileOutputStream(fd);
|
|
@@ -436,8 +436,7 @@ public class TestNativeIO {
|
|
FileInputStream fis = new FileInputStream("/dev/zero");
|
|
FileInputStream fis = new FileInputStream("/dev/zero");
|
|
try {
|
|
try {
|
|
NativeIO.POSIX.posix_fadvise(
|
|
NativeIO.POSIX.posix_fadvise(
|
|
- fis.getFD(), 0, 0,
|
|
|
|
- NativeIO.POSIX.POSIX_FADV_SEQUENTIAL);
|
|
|
|
|
|
+ fis.getFD(), 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
} catch (UnsupportedOperationException uoe) {
|
|
} catch (UnsupportedOperationException uoe) {
|
|
// we should just skip the unit test on machines where we don't
|
|
// we should just skip the unit test on machines where we don't
|
|
// have fadvise support
|
|
// have fadvise support
|
|
@@ -450,20 +449,14 @@ public class TestNativeIO {
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
- NativeIO.POSIX.posix_fadvise(
|
|
|
|
- fis.getFD(), 0, 1024,
|
|
|
|
- NativeIO.POSIX.POSIX_FADV_SEQUENTIAL);
|
|
|
|
-
|
|
|
|
|
|
+ NativeIO.POSIX.posix_fadvise(fis.getFD(), 0, 1024, POSIX_FADV_SEQUENTIAL);
|
|
fail("Did not throw on bad file");
|
|
fail("Did not throw on bad file");
|
|
} catch (NativeIOException nioe) {
|
|
} catch (NativeIOException nioe) {
|
|
assertEquals(Errno.EBADF, nioe.getErrno());
|
|
assertEquals(Errno.EBADF, nioe.getErrno());
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
- NativeIO.POSIX.posix_fadvise(
|
|
|
|
- null, 0, 1024,
|
|
|
|
- NativeIO.POSIX.POSIX_FADV_SEQUENTIAL);
|
|
|
|
-
|
|
|
|
|
|
+ NativeIO.POSIX.posix_fadvise(null, 0, 1024, POSIX_FADV_SEQUENTIAL);
|
|
fail("Did not throw on null file");
|
|
fail("Did not throw on null file");
|
|
} catch (NullPointerException npe) {
|
|
} catch (NullPointerException npe) {
|
|
// expected
|
|
// expected
|
|
@@ -476,9 +469,8 @@ public class TestNativeIO {
|
|
new File(TEST_DIR, "testSyncFileRange"));
|
|
new File(TEST_DIR, "testSyncFileRange"));
|
|
try {
|
|
try {
|
|
fos.write("foo".getBytes());
|
|
fos.write("foo".getBytes());
|
|
- NativeIO.POSIX.sync_file_range(
|
|
|
|
- fos.getFD(), 0, 1024,
|
|
|
|
- NativeIO.POSIX.SYNC_FILE_RANGE_WRITE);
|
|
|
|
|
|
+ NativeIO.POSIX.sync_file_range(fos.getFD(), 0, 1024,
|
|
|
|
+ SYNC_FILE_RANGE_WRITE);
|
|
// no way to verify that this actually has synced,
|
|
// no way to verify that this actually has synced,
|
|
// but if it doesn't throw, we can assume it worked
|
|
// but if it doesn't throw, we can assume it worked
|
|
} catch (UnsupportedOperationException uoe) {
|
|
} catch (UnsupportedOperationException uoe) {
|
|
@@ -489,9 +481,8 @@ public class TestNativeIO {
|
|
fos.close();
|
|
fos.close();
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- NativeIO.POSIX.sync_file_range(
|
|
|
|
- fos.getFD(), 0, 1024,
|
|
|
|
- NativeIO.POSIX.SYNC_FILE_RANGE_WRITE);
|
|
|
|
|
|
+ NativeIO.POSIX.sync_file_range(fos.getFD(), 0, 1024,
|
|
|
|
+ SYNC_FILE_RANGE_WRITE);
|
|
fail("Did not throw on bad file");
|
|
fail("Did not throw on bad file");
|
|
} catch (NativeIOException nioe) {
|
|
} catch (NativeIOException nioe) {
|
|
assertEquals(Errno.EBADF, nioe.getErrno());
|
|
assertEquals(Errno.EBADF, nioe.getErrno());
|
|
@@ -657,4 +648,51 @@ public class TestNativeIO {
|
|
FileUtils.deleteQuietly(TEST_DIR);
|
|
FileUtils.deleteQuietly(TEST_DIR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test (timeout=10000)
|
|
|
|
+ public void testNativePosixConsts() {
|
|
|
|
+ assumeTrue("Native POSIX constants not required for Windows",
|
|
|
|
+ !Path.WINDOWS);
|
|
|
|
+ assertTrue("Native 0_RDONLY const not set", O_RDONLY >= 0);
|
|
|
|
+ assertTrue("Native 0_WRONLY const not set", O_WRONLY >= 0);
|
|
|
|
+ assertTrue("Native 0_RDWR const not set", O_RDWR >= 0);
|
|
|
|
+ assertTrue("Native 0_CREAT const not set", O_CREAT >= 0);
|
|
|
|
+ assertTrue("Native 0_EXCL const not set", O_EXCL >= 0);
|
|
|
|
+ assertTrue("Native 0_NOCTTY const not set", O_NOCTTY >= 0);
|
|
|
|
+ assertTrue("Native 0_TRUNC const not set", O_TRUNC >= 0);
|
|
|
|
+ assertTrue("Native 0_APPEND const not set", O_APPEND >= 0);
|
|
|
|
+ assertTrue("Native 0_NONBLOCK const not set", O_NONBLOCK >= 0);
|
|
|
|
+ assertTrue("Native 0_SYNC const not set", O_SYNC >= 0);
|
|
|
|
+ assertTrue("Native S_IFMT const not set", S_IFMT >= 0);
|
|
|
|
+ assertTrue("Native S_IFIFO const not set", S_IFIFO >= 0);
|
|
|
|
+ assertTrue("Native S_IFCHR const not set", S_IFCHR >= 0);
|
|
|
|
+ assertTrue("Native S_IFDIR const not set", S_IFDIR >= 0);
|
|
|
|
+ assertTrue("Native S_IFBLK const not set", S_IFBLK >= 0);
|
|
|
|
+ assertTrue("Native S_IFREG const not set", S_IFREG >= 0);
|
|
|
|
+ assertTrue("Native S_IFLNK const not set", S_IFLNK >= 0);
|
|
|
|
+ assertTrue("Native S_IFSOCK const not set", S_IFSOCK >= 0);
|
|
|
|
+ assertTrue("Native S_ISUID const not set", S_ISUID >= 0);
|
|
|
|
+ assertTrue("Native S_ISGID const not set", S_ISGID >= 0);
|
|
|
|
+ assertTrue("Native S_ISVTX const not set", S_ISVTX >= 0);
|
|
|
|
+ assertTrue("Native S_IRUSR const not set", S_IRUSR >= 0);
|
|
|
|
+ assertTrue("Native S_IWUSR const not set", S_IWUSR >= 0);
|
|
|
|
+ assertTrue("Native S_IXUSR const not set", S_IXUSR >= 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test (timeout=10000)
|
|
|
|
+ public void testNativeFadviseConsts() {
|
|
|
|
+ assumeTrue("Fadvise constants not supported", fadvisePossible);
|
|
|
|
+ assertTrue("Native POSIX_FADV_NORMAL const not set",
|
|
|
|
+ POSIX_FADV_NORMAL >= 0);
|
|
|
|
+ assertTrue("Native POSIX_FADV_RANDOM const not set",
|
|
|
|
+ POSIX_FADV_RANDOM >= 0);
|
|
|
|
+ assertTrue("Native POSIX_FADV_SEQUENTIAL const not set",
|
|
|
|
+ POSIX_FADV_SEQUENTIAL >= 0);
|
|
|
|
+ assertTrue("Native POSIX_FADV_WILLNEED const not set",
|
|
|
|
+ POSIX_FADV_WILLNEED >= 0);
|
|
|
|
+ assertTrue("Native POSIX_FADV_DONTNEED const not set",
|
|
|
|
+ POSIX_FADV_DONTNEED >= 0);
|
|
|
|
+ assertTrue("Native POSIX_FADV_NOREUSE const not set",
|
|
|
|
+ POSIX_FADV_NOREUSE >= 0);
|
|
|
|
+ }
|
|
}
|
|
}
|