本文整理汇总了Java中org.apache.hadoop.fs.Options.Rename类的典型用法代码示例。如果您正苦于以下问题:Java Rename类的具体用法?Java Rename怎么用?Java Rename使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rename类属于org.apache.hadoop.fs.Options包,在下文中一共展示了Rename类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRenameDirectoryAsNonExistentDirectory
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
private void testRenameDirectoryAsNonExistentDirectory(Rename... options) throws Exception {
if (!renameSupported()) return;
Path src = getTestRootPath(fc, "test/hadoop/dir");
fc.mkdir(src, FileContext.DEFAULT_PERM, true);
createFile(getTestRootPath(fc, "test/hadoop/dir/file1"));
createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2"));
Path dst = getTestRootPath(fc, "test/new/newdir");
fc.mkdir(dst.getParent(), FileContext.DEFAULT_PERM, true);
rename(src, dst, true, false, true, options);
Assert.assertFalse("Nested file1 exists",
exists(fc, getTestRootPath(fc, "test/hadoop/dir/file1")));
Assert.assertFalse("Nested file2 exists",
exists(fc, getTestRootPath(fc, "test/hadoop/dir/subdir/file2")));
Assert.assertTrue("Renamed nested file1 exists",
exists(fc, getTestRootPath(fc, "test/new/newdir/file1")));
Assert.assertTrue("Renamed nested exists",
exists(fc, getTestRootPath(fc, "test/new/newdir/subdir/file2")));
}
示例2: createCheckpoint
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
private void createCheckpoint(Path trashRoot, Date date) throws IOException {
if (!fs.exists(new Path(trashRoot, CURRENT))) {
return;
}
Path checkpointBase;
synchronized (CHECKPOINT) {
checkpointBase = new Path(trashRoot, CHECKPOINT.format(date));
}
Path checkpoint = checkpointBase;
Path current = new Path(trashRoot, CURRENT);
int attempt = 0;
while (true) {
try {
fs.rename(current, checkpoint, Rename.NONE);
LOG.info("Created trash checkpoint: " + checkpoint.toUri().getPath());
break;
} catch (FileAlreadyExistsException e) {
if (++attempt > 1000) {
throw new IOException("Failed to checkpoint trash: " + checkpoint);
}
checkpoint = checkpointBase.suffix("-" + attempt);
}
}
}
示例3: testRenameFileAsExistingFile
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameFileAsExistingFile() throws Exception {
if (!renameSupported()) return;
Path src = getTestRootPath(fc, "test/hadoop/file");
createFile(src);
Path dst = getTestRootPath(fc, "test/new/existingFile");
createFile(dst);
// Fails without overwrite option
try {
rename(src, dst, false, true, false, Rename.NONE);
Assert.fail("Expected exception was not thrown");
} catch (IOException e) {
Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
}
// Succeeds with overwrite option
rename(src, dst, true, false, true, Rename.OVERWRITE);
}
示例4: testRenameDirectoryAsEmptyDirectory
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsEmptyDirectory() throws Exception {
if (!renameSupported()) return;
Path src = getTestRootPath(fc, "test/hadoop/dir");
fc.mkdir(src, FileContext.DEFAULT_PERM, true);
createFile(getTestRootPath(fc, "test/hadoop/dir/file1"));
createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2"));
Path dst = getTestRootPath(fc, "test/new/newdir");
fc.mkdir(dst, FileContext.DEFAULT_PERM, true);
// Fails without overwrite option
try {
rename(src, dst, false, true, false, Rename.NONE);
Assert.fail("Expected exception was not thrown");
} catch (IOException e) {
// Expected (cannot over-write non-empty destination)
Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
}
// Succeeds with the overwrite option
rename(src, dst, true, false, true, Rename.OVERWRITE);
}
示例5: testRenameDirectoryAsFile
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsFile() throws Exception {
if (!renameSupported()) return;
Path src = getTestRootPath(fc, "test/hadoop/dir");
fc.mkdir(src, FileContext.DEFAULT_PERM, true);
Path dst = getTestRootPath(fc, "test/new/newfile");
createFile(dst);
// Fails without overwrite option
try {
rename(src, dst, false, true, true, Rename.NONE);
Assert.fail("Expected exception was not thrown");
} catch (IOException e) {
}
// Directory cannot be renamed as existing file
try {
rename(src, dst, false, true, true, Rename.OVERWRITE);
Assert.fail("Expected exception was not thrown");
} catch (IOException ex) {
}
}
示例6: testCreateLinkUsingRelPaths
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test creating a symlink using relative paths */
public void testCreateLinkUsingRelPaths() throws IOException {
Path fileAbs = new Path(testBaseDir1(), "file");
Path linkAbs = new Path(testBaseDir1(), "linkToFile");
Path schemeAuth = new Path(testURI().toString());
Path fileQual = new Path(schemeAuth, testBaseDir1()+"/file");
createAndWriteFile(fileAbs);
wrapper.setWorkingDirectory(new Path(testBaseDir1()));
wrapper.createSymlink(new Path("file"), new Path("linkToFile"), false);
checkLink(linkAbs, new Path("file"), fileQual);
// Now rename the link's parent. Because the target was specified
// with a relative path the link should still resolve.
Path dir1 = new Path(testBaseDir1());
Path dir2 = new Path(testBaseDir2());
Path linkViaDir2 = new Path(testBaseDir2(), "linkToFile");
Path fileViaDir2 = new Path(schemeAuth, testBaseDir2()+"/file");
wrapper.rename(dir1, dir2, Rename.OVERWRITE);
FileStatus[] stats = wrapper.listStatus(dir2);
assertEquals(fileViaDir2,
wrapper.getFileLinkStatus(linkViaDir2).getSymlink());
readFile(linkViaDir2);
}
示例7: testCreateLinkUsingAbsPaths
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test creating a symlink using absolute paths */
public void testCreateLinkUsingAbsPaths() throws IOException {
Path fileAbs = new Path(testBaseDir1()+"/file");
Path linkAbs = new Path(testBaseDir1()+"/linkToFile");
Path schemeAuth = new Path(testURI().toString());
Path fileQual = new Path(schemeAuth, testBaseDir1()+"/file");
createAndWriteFile(fileAbs);
wrapper.createSymlink(fileAbs, linkAbs, false);
checkLink(linkAbs, fileAbs, fileQual);
// Now rename the link's parent. The target doesn't change and
// now no longer exists so accessing the link should fail.
Path dir1 = new Path(testBaseDir1());
Path dir2 = new Path(testBaseDir2());
Path linkViaDir2 = new Path(testBaseDir2(), "linkToFile");
wrapper.rename(dir1, dir2, Rename.OVERWRITE);
assertEquals(fileQual, wrapper.getFileLinkStatus(linkViaDir2).getSymlink());
try {
readFile(linkViaDir2);
fail("The target should not exist");
} catch (FileNotFoundException x) {
// Expected
}
}
示例8: testRenameDirToSymlinkToDir
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a symlink to a directory */
public void testRenameDirToSymlinkToDir() throws IOException {
Path dir1 = new Path(testBaseDir1());
Path subDir = new Path(testBaseDir2(), "subDir");
Path linkToDir = new Path(testBaseDir2(), "linkToDir");
wrapper.mkdir(subDir, FileContext.DEFAULT_PERM, false);
wrapper.createSymlink(subDir, linkToDir, false);
try {
wrapper.rename(dir1, linkToDir, Rename.OVERWRITE);
fail("Renamed directory to a symlink");
} catch (IOException e) {
// Expected. Both must be directories.
assertTrue(unwrapException(e) instanceof IOException);
}
assertTrue(wrapper.exists(dir1));
assertTrue(wrapper.exists(linkToDir));
}
示例9: testRenameDirToSymlinkToFile
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a symlink to a file */
public void testRenameDirToSymlinkToFile() throws IOException {
Path dir1 = new Path(testBaseDir1());
Path file = new Path(testBaseDir2(), "file");
Path linkToFile = new Path(testBaseDir2(), "linkToFile");
createAndWriteFile(file);
wrapper.createSymlink(file, linkToFile, false);
try {
wrapper.rename(dir1, linkToFile, Rename.OVERWRITE);
fail("Renamed directory to a symlink");
} catch (IOException e) {
// Expected. Both must be directories.
assertTrue(unwrapException(e) instanceof IOException);
}
assertTrue(wrapper.exists(dir1));
assertTrue(wrapper.exists(linkToFile));
}
示例10: testRenameDirToDanglingSymlink
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a dangling symlink */
public void testRenameDirToDanglingSymlink() throws IOException {
Path dir = new Path(testBaseDir1());
Path link = new Path(testBaseDir2(), "linkToFile");
wrapper.createSymlink(new Path("/doesNotExist"), link, false);
try {
wrapper.rename(dir, link, Rename.OVERWRITE);
fail("Renamed directory to a symlink");
} catch (IOException e) {
// Expected. Both must be directories.
assertTrue(unwrapException(e) instanceof IOException);
}
assertTrue(wrapper.exists(dir));
assertTrue(wrapper.getFileLinkStatus(link) != null);
}
示例11: testRenameFileToSymlinkToDir
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a symlink to a directory */
public void testRenameFileToSymlinkToDir() throws IOException {
Path file = new Path(testBaseDir1(), "file");
Path subDir = new Path(testBaseDir1(), "subDir");
Path link = new Path(testBaseDir1(), "link");
wrapper.mkdir(subDir, FileContext.DEFAULT_PERM, false);
wrapper.createSymlink(subDir, link, false);
createAndWriteFile(file);
try {
wrapper.rename(file, link);
fail("Renamed file to symlink w/o overwrite");
} catch (IOException e) {
// Expected
assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
}
wrapper.rename(file, link, Rename.OVERWRITE);
assertFalse(wrapper.exists(file));
assertTrue(wrapper.exists(link));
assertTrue(wrapper.isFile(link));
assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
示例12: testRenameFileToSymlinkToFile
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a symlink to a file */
public void testRenameFileToSymlinkToFile() throws IOException {
Path file1 = new Path(testBaseDir1(), "file1");
Path file2 = new Path(testBaseDir1(), "file2");
Path link = new Path(testBaseDir1(), "linkToFile");
createAndWriteFile(file1);
createAndWriteFile(file2);
wrapper.createSymlink(file2, link, false);
try {
wrapper.rename(file1, link);
fail("Renamed file to symlink w/o overwrite");
} catch (IOException e) {
// Expected
assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
}
wrapper.rename(file1, link, Rename.OVERWRITE);
assertFalse(wrapper.exists(file1));
assertTrue(wrapper.exists(link));
assertTrue(wrapper.isFile(link));
assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
示例13: testRenameFileToDanglingSymlink
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a dangling symlink */
public void testRenameFileToDanglingSymlink() throws IOException {
/* NB: Local file system doesn't handle dangling links correctly
* since File.exists(danglinLink) returns false. */
if ("file".equals(getScheme())) {
return;
}
Path file1 = new Path(testBaseDir1(), "file1");
Path link = new Path(testBaseDir1(), "linkToFile");
createAndWriteFile(file1);
wrapper.createSymlink(new Path("/doesNotExist"), link, false);
try {
wrapper.rename(file1, link);
} catch (IOException e) {
// Expected
}
wrapper.rename(file1, link, Rename.OVERWRITE);
assertFalse(wrapper.exists(file1));
assertTrue(wrapper.exists(link));
assertTrue(wrapper.isFile(link));
assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
示例14: testRenameSymlinkToExistingFile
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Rename a symlink to a file that exists */
public void testRenameSymlinkToExistingFile() throws IOException {
Path file1 = new Path(testBaseDir1(), "file");
Path file2 = new Path(testBaseDir1(), "someFile");
Path link = new Path(testBaseDir1(), "linkToFile");
createAndWriteFile(file1);
createAndWriteFile(file2);
wrapper.createSymlink(file2, link, false);
try {
wrapper.rename(link, file1);
fail("Renamed w/o passing overwrite");
} catch (IOException e) {
// Expected
assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
}
wrapper.rename(link, file1, Rename.OVERWRITE);
assertFalse(wrapper.exists(link));
assertTrue(wrapper.getFileLinkStatus(file1).isSymlink());
assertEquals(file2, wrapper.getLinkTarget(file1));
}
示例15: testRenameLinkTarget
import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename the symlink's target */
public void testRenameLinkTarget() throws IOException {
Path file = new Path(testBaseDir1(), "file");
Path fileNew = new Path(testBaseDir1(), "fileNew");
Path link = new Path(testBaseDir1(), "linkToFile");
createAndWriteFile(file);
wrapper.createSymlink(file, link, false);
wrapper.rename(file, fileNew, Rename.OVERWRITE);
try {
readFile(link);
fail("Link should be dangling");
} catch (IOException x) {
// Expected
}
wrapper.rename(fileNew, file, Rename.OVERWRITE);
readFile(link);
}