use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.
the class TestLeaseRecovery2 method recoverLeaseUsingCreate.
private void recoverLeaseUsingCreate(Path filepath) throws IOException, InterruptedException {
FileSystem dfs2 = getFSAsAnotherUser(conf);
for (int i = 0; i < 10; i++) {
AppendTestUtil.LOG.info("i=" + i);
try {
dfs2.create(filepath, false, BUF_SIZE, (short) 1, BLOCK_SIZE);
fail("Creation of an existing file should never succeed.");
} catch (FileAlreadyExistsException e) {
// expected
return;
} catch (AlreadyBeingCreatedException e) {
// expected
return;
} catch (IOException ioe) {
AppendTestUtil.LOG.warn("UNEXPECTED ", ioe);
AppendTestUtil.LOG.info("sleep " + 5000 + "ms");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
}
fail("recoverLeaseUsingCreate failed");
}
use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.
the class JobHistoryEventHandler method mkdir.
private void mkdir(FileSystem fs, Path path, FsPermission fsp) throws IOException {
if (!fs.exists(path)) {
try {
fs.mkdirs(path, fsp);
FileStatus fsStatus = fs.getFileStatus(path);
LOG.info("Perms after creating " + fsStatus.getPermission().toShort() + ", Expected: " + fsp.toShort());
if (fsStatus.getPermission().toShort() != fsp.toShort()) {
LOG.info("Explicitly setting permissions to : " + fsp.toShort() + ", " + fsp);
fs.setPermission(path, fsp);
}
} catch (FileAlreadyExistsException e) {
LOG.info("Directory: [" + path + "] already exists.");
}
}
}
use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.
the class AbstractContractMkdirTest method testNoMkdirOverFile.
@Test
public void testNoMkdirOverFile() throws Throwable {
describe("try to mkdir over a file");
FileSystem fs = getFileSystem();
Path path = path("testNoMkdirOverFile");
byte[] dataset = dataset(1024, ' ', 'z');
createFile(getFileSystem(), path, false, dataset);
try {
boolean made = fs.mkdirs(path);
fail("mkdirs did not fail over a file but returned " + made + "; " + ls(path));
} catch (ParentNotDirectoryException | FileAlreadyExistsException e) {
//parent is a directory
handleExpectedException(e);
} catch (IOException e) {
//here the FS says "no create"
handleRelaxedException("mkdirs", "FileAlreadyExistsException", e);
}
assertIsFile(path);
byte[] bytes = ContractTestUtils.readDataset(getFileSystem(), path, dataset.length);
ContractTestUtils.compareByteArrays(dataset, bytes, dataset.length);
assertPathExists("mkdir failed", path);
assertDeleted(path, true);
}
use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.
the class AbstractContractMkdirTest method testMkdirOverParentFile.
@Test
public void testMkdirOverParentFile() throws Throwable {
describe("try to mkdir where a parent is a file");
FileSystem fs = getFileSystem();
Path path = path("testMkdirOverParentFile");
byte[] dataset = dataset(1024, ' ', 'z');
createFile(getFileSystem(), path, false, dataset);
Path child = new Path(path, "child-to-mkdir");
try {
boolean made = fs.mkdirs(child);
fail("mkdirs did not fail over a file but returned " + made + "; " + ls(path));
} catch (ParentNotDirectoryException | FileAlreadyExistsException e) {
//parent is a directory
handleExpectedException(e);
} catch (IOException e) {
handleRelaxedException("mkdirs", "ParentNotDirectoryException", e);
}
assertIsFile(path);
byte[] bytes = ContractTestUtils.readDataset(getFileSystem(), path, dataset.length);
ContractTestUtils.compareByteArrays(dataset, bytes, dataset.length);
assertPathExists("mkdir failed", path);
assertDeleted(path, true);
}
use of org.apache.hadoop.fs.FileAlreadyExistsException in project hadoop by apache.
the class TestAliyunOSSFileSystemContract method testRenameFileAsExistingFile.
@Override
public void testRenameFileAsExistingFile() throws Exception {
if (this.renameSupported()) {
Path src = this.path("/test/hadoop/file");
this.createFile(src);
Path dst = this.path("/test/new/newfile");
this.createFile(dst);
try {
super.rename(src, dst, false, true, true);
fail("Should throw FileAlreadyExistsException");
} catch (FileAlreadyExistsException e) {
// expected
}
}
}
Aggregations