@Test
public void testOpen() throws Exception {
LOG.info("Open a missing file without O_CREAT and it should fail");
try {
FileDescriptor fd = NativeIO.open(
new File(TEST_DIR, "doesntexist").getAbsolutePath(),
NativeIO.O_WRONLY, 0700);
fail("Able to open a new file without O_CREAT");
} catch (IOException ioe) {
// expected
}
LOG.info("Test creating a file with O_CREAT");
FileDescriptor fd = NativeIO.open(
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
NativeIO.O_WRONLY | NativeIO.O_CREAT, 0700);
assertNotNull(true);
assertTrue(fd.valid());
FileOutputStream fos = new FileOutputStream(fd);
fos.write("foo".getBytes());
fos.close();
assertFalse(fd.valid());
LOG.info("Test exclusive create");
try {
fd = NativeIO.open(
new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),