org.apache.hadoop.fs.FileSystem.rename() - java examples

Here are the examples of the java api org.apache.hadoop.fs.FileSystem.rename() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
// Rename on internal mount table should fail
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename1() throws IOException {
    fsView.rename(new Path("/internalDir"), new Path("/newDir"));
}

19 View Complete Implementation : NNBenchWithoutMR.java
Copyright Apache License 2.0
Author : apache
/**
 * Rename a given number of files.  Repeat each remote
 * operation until is succeeds (does not throw an exception).
 *
 * @return the number of exceptions caught
 */
static int rename() {
    int totalExceptions = 0;
    boolean success;
    for (int index = 0; index < numFiles; index++) {
        int singleFileExceptions = 0;
        do {
            // rename file until is succeeds
            try {
                // Possible result of this operation is at no interest to us for it
                // can return false only if the namesystem
                // could rename the path from the name
                // space (e.g. no Exception has been thrown)
                fileSys.rename(new Path(taskDir, "" + index), new Path(taskDir, "A" + index));
                success = true;
            } catch (IOException ioe) {
                success = false;
                totalExceptions++;
                handleException("creating file #" + index, ioe, ++singleFileExceptions);
            }
        } while (!success);
    }
    return totalExceptions;
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
@Test(expected = AccessControlException.clreplaced)
public void testInternalRenameToSlash() throws IOException {
    fsView.rename(new Path("/internalDir/linkToDir2/foo"), new Path("/"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test(expected = AccessControlException.clreplaced)
public void testInternalRenameToSlash() throws IOException {
    fsView.rename(new Path("/internalDir/linkToDir2/foo"), new Path("/"));
}

19 View Complete Implementation : NNBenchWithoutMR.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * Rename a given number of files.  Repeat each remote
 * operation until is suceeds (does not throw an exception).
 *
 * @return the number of exceptions caught
 */
static int rename() {
    int totalExceptions = 0;
    boolean success;
    for (int index = 0; index < numFiles; index++) {
        int singleFileExceptions = 0;
        do {
            // rename file until is succeeds
            try {
                // Possible result of this operation is at no interest to us for it
                // can return false only if the namesystem
                // could rename the path from the name
                // space (e.g. no Exception has been thrown)
                fileSys.rename(new Path(taskDir, "" + index), new Path(taskDir, "A" + index));
                success = true;
            } catch (IOException ioe) {
                success = false;
                totalExceptions++;
                handleException("creating file #" + index, ioe, ++singleFileExceptions);
            }
        } while (!success);
    }
    return totalExceptions;
}

19 View Complete Implementation : NNBenchWithoutMR.java
Copyright Apache License 2.0
Author : yncxcw
/**
 * Rename a given number of files.  Repeat each remote
 * operation until is suceeds (does not throw an exception).
 *
 * @return the number of exceptions caught
 */
static int rename() {
    int totalExceptions = 0;
    boolean success;
    for (int index = 0; index < numFiles; index++) {
        int singleFileExceptions = 0;
        do {
            // rename file until is succeeds
            try {
                // Possible result of this operation is at no interest to us for it
                // can return false only if the namesystem
                // could rename the path from the name
                // space (e.g. no Exception has been thrown)
                fileSys.rename(new Path(taskDir, "" + index), new Path(taskDir, "A" + index));
                success = true;
            } catch (IOException ioe) {
                success = false;
                totalExceptions++;
                handleException("creating file #" + index, ioe, ++singleFileExceptions);
            }
        } while (!success);
    }
    return totalExceptions;
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test(expected = AccessControlException.clreplaced)
public void testInternalRenameFromSlash() throws IOException {
    fsView.rename(new Path("/"), new Path("/bar"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
// rename across mount points fail if the mount link targets are different
// even if the targets are part of the same target FS
@Test(expected = IOException.clreplaced)
public void testRenameAcrossMounts2() throws IOException {
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    fsView.rename(new Path("/user/foo"), new Path("/data/fooBar"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename3() throws IOException {
    fsView.rename(new Path("/user"), new Path("/internalDir/linkToDir2"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
// Rename on internal mount table should fail
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename1() throws IOException {
    fsView.rename(new Path("/internalDir"), new Path("/newDir"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename3() throws IOException {
    fsView.rename(new Path("/user"), new Path("/internalDir/linkToDir2"));
}

19 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
// rename across mount points that point to same target also fail
@Test(expected = IOException.clreplaced)
public void testRenameAcrossMounts1() throws IOException {
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    fsView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar"));
/* - code if we had wanted this to suceed
    replacedert.replacedertFalse(fSys.exists(new Path("/user/foo")));
    replacedert.replacedertFalse(fSysLocal.exists(new Path(targetTestRoot,"user/foo")));
    replacedert.replacedertTrue(fSys.isFile(FileSystemTestHelper.getTestRootPath(fSys,"/user2/fooBarBar")));
    replacedert.replacedertTrue(fSysLocal.isFile(new Path(targetTestRoot,"user/fooBarBar")));
    */
}

18 View Complete Implementation : TestFileSystemOperationsExceptionHandlingMultiThreaded.java
Copyright Apache License 2.0
Author : aliyun-beta
@Override
public void run() {
    try {
        fs.rename(testPath, renamePath);
    } catch (Exception e) {
    // Swallowing the exception as the
    // correctness of the test is controlled
    // by the other thread
    }
}

18 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : apache
/**
 * We would have liked renames across file system to fail but
 * Unfortunately there is not way to distinguish the two file systems
 * @throws IOException
 */
@Test
public void testRenameAcrossFs() throws IOException {
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("file:///tmp/dirFooBar"));
    FileSystemTestHelper.isDir(fSys, new Path("/tmp/dirFooBar"));
}

18 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : yncxcw
/**
 * We would have liked renames across file system to fail but
 * Unfortunately there is not way to distinguish the two file systems
 * @throws IOException
 */
@Test
public void testRenameAcrossFs() throws IOException {
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("file:///tmp/dirFooBar"));
    FileSystemTestHelper.isDir(fSys, new Path("/tmp/dirFooBar"));
}

18 View Complete Implementation : TestSFTPFileSystem.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * Test renaming a file onto an existing file.
 *
 * @throws Exception
 */
@Test(expected = java.io.IOException.clreplaced)
public void testRenamingFileOntoExistingFile() throws Exception {
    Path file1 = touch(localFs, name.getMethodName().toLowerCase() + "1");
    Path file2 = touch(localFs, name.getMethodName().toLowerCase() + "2");
    sftpFs.rename(file1, file2);
}

18 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
// rename across mount points that point to same target also fail
@Test(expected = IOException.clreplaced)
public void testRenameAcrossMounts1() throws IOException {
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    fsView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar"));
/* - code if we had wanted this to suceed
    replacedert.replacedertFalse(fSys.exists(new Path("/user/foo")));
    replacedert.replacedertFalse(fSysLocal.exists(new Path(targetTestRoot,"user/foo")));
    replacedert.replacedertTrue(fSys.isFile(FileSystemTestHelper.getTestRootPath(fSys,"/user2/fooBarBar")));
    replacedert.replacedertTrue(fSysLocal.isFile(new Path(targetTestRoot,"user/fooBarBar")));
    */
}

18 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename2() throws IOException {
    fsView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory();
    fsView.rename(new Path("/internalDir/linkToDir2"), new Path("/internalDir/dir1"));
}

18 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test(expected = AccessControlException.clreplaced)
public void testInternalRename2() throws IOException {
    fsView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory();
    fsView.rename(new Path("/internalDir/linkToDir2"), new Path("/internalDir/dir1"));
}

18 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : apache
/*
   * In order to make this write atomic as a part of write we will first write
   * data to .tmp file and then rename it. Here we are replaceduming that rename is
   * atomic for underlying file system.
   */
protected void writeFile(Path outputPath, byte[] data, boolean makeUnreadableByAdmin) throws Exception {
    Path tempPath = new Path(outputPath.getParent(), outputPath.getName() + ".tmp");
    FSDataOutputStream fsOut = null;
    // This file will be overwritten when app/attempt finishes for saving the
    // final status.
    try {
        fsOut = fs.create(tempPath, true);
        if (makeUnreadableByAdmin) {
            setUnreadableBySuperuserXattrib(tempPath);
        }
        fsOut.write(data);
        fsOut.close();
        fsOut = null;
        fs.rename(tempPath, outputPath);
    } finally {
        IOUtils.cleanupWithLogger(LOG, fsOut);
    }
}

18 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : yncxcw
// rename across mount points fail if the mount link targets are different
// even if the targets are part of the same target FS
@Test(expected = IOException.clreplaced)
public void testRenameAcrossMounts2() throws IOException {
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    fsView.rename(new Path("/user/foo"), new Path("/data/fooBar"));
}

18 View Complete Implementation : TestSFTPFileSystem.java
Copyright Apache License 2.0
Author : apache
/**
 * Test renaming a file that does not exist.
 *
 * @throws Exception
 */
@Test(expected = java.io.IOException.clreplaced)
public void testRenameNonExistFile() throws Exception {
    Path file1 = new Path(localDir, name.getMethodName().toLowerCase() + "1");
    Path file2 = new Path(localDir, name.getMethodName().toLowerCase() + "2");
    sftpFs.rename(file1, file2);
}

18 View Complete Implementation : TestSFTPFileSystem.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * Test renaming a file that does not exist.
 *
 * @throws Exception
 */
@Test(expected = java.io.IOException.clreplaced)
public void testRenameNonExistFile() throws Exception {
    Path file1 = new Path(localDir, name.getMethodName().toLowerCase() + "1");
    Path file2 = new Path(localDir, name.getMethodName().toLowerCase() + "2");
    sftpFs.rename(file1, file2);
}

18 View Complete Implementation : TestSFTPFileSystem.java
Copyright Apache License 2.0
Author : apache
/**
 * Test renaming a file onto an existing file.
 *
 * @throws Exception
 */
@Test(expected = java.io.IOException.clreplaced)
public void testRenamingFileOntoExistingFile() throws Exception {
    Path file1 = touch(localFs, name.getMethodName().toLowerCase() + "1");
    Path file2 = touch(localFs, name.getMethodName().toLowerCase() + "2");
    sftpFs.rename(file1, file2);
}

18 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * We would have liked renames across file system to fail but
 * Unfortunately there is not way to distinguish the two file systems
 * @throws IOException
 */
@Test
public void testRenameAcrossFs() throws IOException {
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("file:///tmp/dirFooBar"));
    FileSystemTestHelper.isDir(fSys, new Path("/tmp/dirFooBar"));
}

17 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : yncxcw
@Test
public void testRename() throws IOException {
    // Rename a file
    fileSystemTestHelper.createFile(fSys, "/newDir/foo");
    fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/foo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
    replacedert.replacedertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/fooBar")));
    replacedert.replacedertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/fooBar")));
    // Rename a dir
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/dirFoo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/dirFoo")));
    replacedert.replacedertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/dirFooBar")));
    replacedert.replacedertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "newDir/dirFooBar")));
}

17 View Complete Implementation : TestProtectedDirectories.java
Copyright Apache License 2.0
Author : apache
/**
 * Return true if the path was successfully renamed. False if it
 * failed with AccessControlException. Any other exceptions are
 * propagated to the caller.
 *
 * @param fs
 * @param srcPath
 * @param dstPath
 * @return
 */
private boolean renamePath(FileSystem fs, Path srcPath, Path dstPath) throws IOException {
    try {
        fs.rename(srcPath, dstPath);
        return true;
    } catch (AccessControlException ace) {
        return false;
    }
}

17 View Complete Implementation : TestAzureFileSystemInstrumentation.java
Copyright Apache License 2.0
Author : yncxcw
@Test
public void testMetricsOnFileRename() throws Exception {
    long base = getBaseWebResponses();
    Path originalPath = new Path("/metricsTest_RenameStart");
    Path destinationPath = new Path("/metricsTest_RenameFinal");
    // Create an empty file
    replacedertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED));
    replacedertTrue(fs.createNewFile(originalPath));
    logOpResponseCount("Creating an empty file", base);
    base = replacedertWebResponsesInRange(base, 2, 20);
    replacedertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED));
    // Rename the file
    replacedertTrue(fs.rename(originalPath, destinationPath));
    // Varies: at the time of writing this code it takes 7 requests/responses.
    logOpResponseCount("Renaming a file", base);
    base = replacedertWebResponsesInRange(base, 2, 15);
    replacedertNoErrors();
}

17 View Complete Implementation : TestMapFile.java
Copyright Apache License 2.0
Author : apache
@Test
public void testRenameWithFalse() {
    final String ERROR_MESSAGE = "Could not rename";
    final String NEW_FILE_NAME = "test-new.mapfile";
    final String OLD_FILE_NAME = "test-old.mapfile";
    MapFile.Writer writer = null;
    try {
        FileSystem fs = FileSystem.getLocal(conf);
        FileSystem spyFs = spy(fs);
        writer = createWriter(OLD_FILE_NAME, IntWritable.clreplaced, IntWritable.clreplaced);
        writer.close();
        Path oldDir = new Path(TEST_DIR, OLD_FILE_NAME);
        Path newDir = new Path(TEST_DIR, NEW_FILE_NAME);
        when(spyFs.rename(oldDir, newDir)).thenReturn(false);
        MapFile.rename(spyFs, oldDir.toString(), newDir.toString());
        fail("testRenameWithException no exception error !!!");
    } catch (IOException ex) {
        replacedertTrue("testRenameWithFalse invalid IOExceptionMessage error !!!", ex.getMessage().startsWith(ERROR_MESSAGE));
    } finally {
        IOUtils.cleanupWithLogger(LOG, writer);
    }
}

17 View Complete Implementation : BaseTestHttpFSWith.java
Copyright Apache License 2.0
Author : yncxcw
private void testRename() throws Exception {
    FileSystem fs = FileSystem.get(getProxiedFSConf());
    Path path = new Path(getProxiedFSTestDir(), "foo");
    fs.mkdirs(path);
    fs.close();
    fs = getHttpFSFileSystem();
    Path oldPath = new Path(path.toUri().getPath());
    Path newPath = new Path(path.getParent(), "bar");
    fs.rename(oldPath, newPath);
    fs.close();
    fs = FileSystem.get(getProxiedFSConf());
    replacedert.replacedertFalse(fs.exists(oldPath));
    replacedert.replacedertTrue(fs.exists(newPath));
    fs.close();
}

17 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test
public void testRename() throws IOException {
    // Rename a file
    fileSystemTestHelper.createFile(fSys, "/newDir/foo");
    fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/foo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
    replacedert.replacedertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/fooBar")));
    replacedert.replacedertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/fooBar")));
    // Rename a dir
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/dirFoo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/dirFoo")));
    replacedert.replacedertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/dirFooBar")));
    replacedert.replacedertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "newDir/dirFooBar")));
}

17 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : yncxcw
/*
   * In order to make this write atomic as a part of write we will first write
   * data to .tmp file and then rename it. Here we are replaceduming that rename is
   * atomic for underlying file system.
   */
protected void writeFile(Path outputPath, byte[] data, boolean makeUnradableByAdmin) throws Exception {
    Path tempPath = new Path(outputPath.getParent(), outputPath.getName() + ".tmp");
    FSDataOutputStream fsOut = null;
    // This file will be overwritten when app/attempt finishes for saving the
    // final status.
    try {
        fsOut = fs.create(tempPath, true);
        if (makeUnradableByAdmin) {
            setUnreadableBySuperuserXattrib(tempPath);
        }
        fsOut.write(data);
        fsOut.close();
        fsOut = null;
        fs.rename(tempPath, outputPath);
    } finally {
        IOUtils.cleanup(LOG, fsOut);
    }
}

17 View Complete Implementation : ViewFileSystemBaseTest.java
Copyright Apache License 2.0
Author : aliyun-beta
/**
 * Test modify operations (create, mkdir, delete, etc)
 * on the mount file system where the pathname references through
 * the mount points.  Hence these operation will modify the target
 * file system.
 *
 * Verify the operation via mountfs (ie fSys) and *also* via the
 *  target file system (ie fSysLocal) that the mount link points-to.
 */
private void testOperationsThroughMountLinksInternal(boolean located) throws IOException {
    // Create file
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    replacedert.replacedertTrue("Created file should be type file", fsView.isFile(new Path("/user/foo")));
    replacedert.replacedertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot, "user/foo")));
    // Delete the created file
    replacedert.replacedertTrue("Delete should suceed", fsView.delete(new Path("/user/foo"), false));
    replacedert.replacedertFalse("File should not exist after delete", fsView.exists(new Path("/user/foo")));
    replacedert.replacedertFalse("Target File should not exist after delete", fsTarget.exists(new Path(targetTestRoot, "user/foo")));
    // Create file with a 2 component dirs
    fileSystemTestHelper.createFile(fsView, "/internalDir/linkToDir2/foo");
    replacedert.replacedertTrue("Created file should be type file", fsView.isFile(new Path("/internalDir/linkToDir2/foo")));
    replacedert.replacedertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot, "dir2/foo")));
    // Delete the created file
    replacedert.replacedertTrue("Delete should suceed", fsView.delete(new Path("/internalDir/linkToDir2/foo"), false));
    replacedert.replacedertFalse("File should not exist after delete", fsView.exists(new Path("/internalDir/linkToDir2/foo")));
    replacedert.replacedertFalse("Target File should not exist after delete", fsTarget.exists(new Path(targetTestRoot, "dir2/foo")));
    // Create file with a 3 component dirs
    fileSystemTestHelper.createFile(fsView, "/internalDir/internalDir2/linkToDir3/foo");
    replacedert.replacedertTrue("Created file should be type file", fsView.isFile(new Path("/internalDir/internalDir2/linkToDir3/foo")));
    replacedert.replacedertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot, "dir3/foo")));
    // Recursive Create file with missing dirs
    fileSystemTestHelper.createFile(fsView, "/internalDir/linkToDir2/missingDir/miss2/foo");
    replacedert.replacedertTrue("Created file should be type file", fsView.isFile(new Path("/internalDir/linkToDir2/missingDir/miss2/foo")));
    replacedert.replacedertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot, "dir2/missingDir/miss2/foo")));
    // Delete the created file
    replacedert.replacedertTrue("Delete should succeed", fsView.delete(new Path("/internalDir/internalDir2/linkToDir3/foo"), false));
    replacedert.replacedertFalse("File should not exist after delete", fsView.exists(new Path("/internalDir/internalDir2/linkToDir3/foo")));
    replacedert.replacedertFalse("Target File should not exist after delete", fsTarget.exists(new Path(targetTestRoot, "dir3/foo")));
    // mkdir
    fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX"));
    replacedert.replacedertTrue("New dir should be type dir", fsView.isDirectory(new Path("/user/dirX")));
    replacedert.replacedertTrue("Target of new dir should be of type dir", fsTarget.isDirectory(new Path(targetTestRoot, "user/dirX")));
    fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX/dirY"));
    replacedert.replacedertTrue("New dir should be type dir", fsView.isDirectory(new Path("/user/dirX/dirY")));
    replacedert.replacedertTrue("Target of new dir should be of type dir", fsTarget.isDirectory(new Path(targetTestRoot, "user/dirX/dirY")));
    // Delete the created dir
    replacedert.replacedertTrue("Delete should succeed", fsView.delete(new Path("/user/dirX/dirY"), false));
    replacedert.replacedertFalse("File should not exist after delete", fsView.exists(new Path("/user/dirX/dirY")));
    replacedert.replacedertFalse("Target File should not exist after delete", fsTarget.exists(new Path(targetTestRoot, "user/dirX/dirY")));
    replacedert.replacedertTrue("Delete should succeed", fsView.delete(new Path("/user/dirX"), false));
    replacedert.replacedertFalse("File should not exist after delete", fsView.exists(new Path("/user/dirX")));
    replacedert.replacedertFalse(fsTarget.exists(new Path(targetTestRoot, "user/dirX")));
    // Rename a file
    fileSystemTestHelper.createFile(fsView, "/user/foo");
    fsView.rename(new Path("/user/foo"), new Path("/user/fooBar"));
    replacedert.replacedertFalse("Renamed src should not exist", fsView.exists(new Path("/user/foo")));
    replacedert.replacedertFalse("Renamed src should not exist in target", fsTarget.exists(new Path(targetTestRoot, "user/foo")));
    replacedert.replacedertTrue("Renamed dest should  exist as file", fsView.isFile(fileSystemTestHelper.getTestRootPath(fsView, "/user/fooBar")));
    replacedert.replacedertTrue("Renamed dest should  exist as file in target", fsTarget.isFile(new Path(targetTestRoot, "user/fooBar")));
    fsView.mkdirs(new Path("/user/dirFoo"));
    fsView.rename(new Path("/user/dirFoo"), new Path("/user/dirFooBar"));
    replacedert.replacedertFalse("Renamed src should not exist", fsView.exists(new Path("/user/dirFoo")));
    replacedert.replacedertFalse("Renamed src should not exist in target", fsTarget.exists(new Path(targetTestRoot, "user/dirFoo")));
    replacedert.replacedertTrue("Renamed dest should  exist as dir", fsView.isDirectory(fileSystemTestHelper.getTestRootPath(fsView, "/user/dirFooBar")));
    replacedert.replacedertTrue("Renamed dest should  exist as dir in target", fsTarget.isDirectory(new Path(targetTestRoot, "user/dirFooBar")));
    // Make a directory under a directory that's mounted from the root of another FS
    fsView.mkdirs(new Path("/targetRoot/dirFoo"));
    replacedert.replacedertTrue(fsView.exists(new Path("/targetRoot/dirFoo")));
    boolean dirFooPresent = false;
    for (FileStatus fileStatus : listStatusInternal(located, new Path("/targetRoot/"))) {
        if (fileStatus.getPath().getName().equals("dirFoo")) {
            dirFooPresent = true;
        }
    }
    replacedert.replacedertTrue(dirFooPresent);
}

17 View Complete Implementation : TestDFSPermission.java
Copyright Apache License 2.0
Author : apache
/* test non-existent file */
private void checkNonExistentFile() {
    try {
        replacedertFalse(fs.exists(NON_EXISTENT_FILE));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.open(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.setReplication(NON_EXISTENT_FILE, (short) 4);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getFileStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getContentSummary(NON_EXISTENT_FILE).getLength();
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.listStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.delete(NON_EXISTENT_FILE, true);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.rename(NON_EXISTENT_FILE, new Path(NON_EXISTENT_FILE + ".txt"));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
}

17 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : yncxcw
@Private
@VisibleForTesting
boolean renameFile(Path src, Path dst) throws Exception {
    return fs.rename(src, dst);
}

17 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : aliyun-beta
@Private
@VisibleForTesting
boolean renameFile(Path src, Path dst) throws Exception {
    return fs.rename(src, dst);
}

17 View Complete Implementation : OnDiskMapOutput.java
Copyright Apache License 2.0
Author : yncxcw
@Override
public void commit() throws IOException {
    fs.rename(tmpOutputPath, outputPath);
    CompressAwarePath compressAwarePath = new CompressAwarePath(outputPath, getSize(), this.compressedSize);
    merger.closeOnDiskFile(compressAwarePath);
}

17 View Complete Implementation : BaseTestHttpFSWith.java
Copyright Apache License 2.0
Author : aliyun-beta
private void testRename() throws Exception {
    FileSystem fs = FileSystem.get(getProxiedFSConf());
    Path path = new Path(getProxiedFSTestDir(), "foo");
    fs.mkdirs(path);
    fs.close();
    fs = getHttpFSFileSystem();
    Path oldPath = new Path(path.toUri().getPath());
    Path newPath = new Path(path.getParent(), "bar");
    fs.rename(oldPath, newPath);
    fs.close();
    fs = FileSystem.get(getProxiedFSConf());
    replacedert.replacedertFalse(fs.exists(oldPath));
    replacedert.replacedertTrue(fs.exists(newPath));
    fs.close();
}

17 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : aliyun-beta
/*
   * In order to make this write atomic as a part of write we will first write
   * data to .tmp file and then rename it. Here we are replaceduming that rename is
   * atomic for underlying file system.
   */
protected void writeFile(Path outputPath, byte[] data, boolean makeUnradableByAdmin) throws Exception {
    Path tempPath = new Path(outputPath.getParent(), outputPath.getName() + ".tmp");
    FSDataOutputStream fsOut = null;
    // This file will be overwritten when app/attempt finishes for saving the
    // final status.
    try {
        fsOut = fs.create(tempPath, true);
        if (makeUnradableByAdmin) {
            setUnreadableBySuperuserXattrib(tempPath);
        }
        fsOut.write(data);
        fsOut.close();
        fsOut = null;
        fs.rename(tempPath, outputPath);
    } finally {
        IOUtils.cleanup(LOG, fsOut);
    }
}

17 View Complete Implementation : TestPermission.java
Copyright Apache License 2.0
Author : yncxcw
static boolean canRename(FileSystem fs, Path src, Path dst) throws IOException {
    try {
        fs.rename(src, dst);
        return true;
    } catch (AccessControlException e) {
        return false;
    }
}

17 View Complete Implementation : TestDFSPermission.java
Copyright Apache License 2.0
Author : yncxcw
/* test non-existent file */
private void checkNonExistentFile() {
    try {
        replacedertFalse(fs.exists(NON_EXISTENT_FILE));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.open(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.setReplication(NON_EXISTENT_FILE, (short) 4);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getFileStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getContentSummary(NON_EXISTENT_FILE).getLength();
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.listStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.delete(NON_EXISTENT_FILE, true);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.rename(NON_EXISTENT_FILE, new Path(NON_EXISTENT_FILE + ".txt"));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
}

17 View Complete Implementation : OnDiskMapOutput.java
Copyright Apache License 2.0
Author : aliyun-beta
@Override
public void commit() throws IOException {
    fs.rename(tmpOutputPath, outputPath);
    CompressAwarePath compressAwarePath = new CompressAwarePath(outputPath, getSize(), this.compressedSize);
    getMerger().closeOnDiskFile(compressAwarePath);
}

17 View Complete Implementation : TestDFSPermission.java
Copyright Apache License 2.0
Author : aliyun-beta
/* test non-existent file */
private void checkNonExistentFile() {
    try {
        replacedertFalse(fs.exists(NON_EXISTENT_FILE));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.open(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.setReplication(NON_EXISTENT_FILE, (short) 4);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getFileStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.getContentSummary(NON_EXISTENT_FILE).getLength();
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.listStatus(NON_EXISTENT_FILE);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.delete(NON_EXISTENT_FILE, true);
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
    try {
        fs.rename(NON_EXISTENT_FILE, new Path(NON_EXISTENT_FILE + ".txt"));
    } catch (IOException e) {
        checkNoPermissionDeny(e);
    }
}

17 View Complete Implementation : TestChRootedFileSystem.java
Copyright Apache License 2.0
Author : apache
@Test
public void testRename() throws IOException {
    // Rename a file
    fileSystemTestHelper.createFile(fSys, "/newDir/foo");
    fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/foo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
    replacedert.replacedertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/fooBar")));
    replacedert.replacedertTrue(fSysTarget.isFile(new Path(chrootedTo, "newDir/fooBar")));
    // Rename a dir
    fSys.mkdirs(new Path("/newDir/dirFoo"));
    fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
    replacedert.replacedertFalse(fSys.exists(new Path("/newDir/dirFoo")));
    replacedert.replacedertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/dirFoo")));
    replacedert.replacedertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys, "/newDir/dirFooBar")));
    replacedert.replacedertTrue(fSysTarget.isDirectory(new Path(chrootedTo, "newDir/dirFooBar")));
}

17 View Complete Implementation : OnDiskMapOutput.java
Copyright Apache License 2.0
Author : apache
@Override
public void commit() throws IOException {
    fs.rename(tmpOutputPath, outputPath);
    CompressAwarePath compressAwarePath = new CompressAwarePath(outputPath, getSize(), this.compressedSize);
    getMerger().closeOnDiskFile(compressAwarePath);
}

17 View Complete Implementation : TestAzureFileSystemInstrumentation.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test
public void testMetricsOnFileRename() throws Exception {
    long base = getBaseWebResponses();
    Path originalPath = new Path("/metricsTest_RenameStart");
    Path destinationPath = new Path("/metricsTest_RenameFinal");
    // Create an empty file
    replacedertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED));
    replacedertTrue(fs.createNewFile(originalPath));
    logOpResponseCount("Creating an empty file", base);
    base = replacedertWebResponsesInRange(base, 2, 20);
    replacedertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED));
    // Rename the file
    replacedertTrue(fs.rename(originalPath, destinationPath));
    // Varies: at the time of writing this code it takes 7 requests/responses.
    logOpResponseCount("Renaming a file", base);
    base = replacedertWebResponsesInRange(base, 2, 15);
    replacedertNoErrors();
}

17 View Complete Implementation : FSSchedulerConfigurationStore.java
Copyright Apache License 2.0
Author : apache
private void finalizeFileSystemFile() throws IOException {
    // call confirmMutation() make sure tempConfigPath is not null
    Path finalConfigPath = getFinalConfigPath(tempConfigPath);
    fileSystem.rename(tempConfigPath, finalConfigPath);
    LOG.info("finalize temp configuration file successfully, finalConfigPath=" + finalConfigPath);
}

17 View Complete Implementation : TestMapFile.java
Copyright Apache License 2.0
Author : apache
/**
 * test {@code MapFile.rename()}
 *  method with throwing {@code IOException}
 */
@Test
public void testRenameWithException() {
    final String ERROR_MESSAGE = "Can't rename file";
    final String NEW_FILE_NAME = "test-new.mapfile";
    final String OLD_FILE_NAME = "test-old.mapfile";
    MapFile.Writer writer = null;
    try {
        FileSystem fs = FileSystem.getLocal(conf);
        FileSystem spyFs = spy(fs);
        writer = createWriter(OLD_FILE_NAME, IntWritable.clreplaced, IntWritable.clreplaced);
        writer.close();
        Path oldDir = new Path(TEST_DIR, OLD_FILE_NAME);
        Path newDir = new Path(TEST_DIR, NEW_FILE_NAME);
        when(spyFs.rename(oldDir, newDir)).thenThrow(new IOException(ERROR_MESSAGE));
        MapFile.rename(spyFs, oldDir.toString(), newDir.toString());
        fail("testRenameWithException no exception error !!!");
    } catch (IOException ex) {
        replacedertEquals("testRenameWithException invalid IOExceptionMessage !!!", ex.getMessage(), ERROR_MESSAGE);
    } finally {
        IOUtils.cleanupWithLogger(LOG, writer);
    }
}

17 View Complete Implementation : FileSystemRMStateStore.java
Copyright Apache License 2.0
Author : apache
@Private
@VisibleForTesting
boolean renameFile(Path src, Path dst) throws Exception {
    return fs.rename(src, dst);
}

16 View Complete Implementation : TestMapFile.java
Copyright Apache License 2.0
Author : aliyun-beta
@Test
public void testRenameWithFalse() {
    final String ERROR_MESSAGE = "Could not rename";
    final String NEW_FILE_NAME = "test-new.mapfile";
    final String OLD_FILE_NAME = "test-old.mapfile";
    MapFile.Writer writer = null;
    try {
        FileSystem fs = FileSystem.getLocal(conf);
        FileSystem spyFs = spy(fs);
        writer = createWriter(OLD_FILE_NAME, IntWritable.clreplaced, IntWritable.clreplaced);
        writer.close();
        Path oldDir = new Path(TEST_DIR, OLD_FILE_NAME);
        Path newDir = new Path(TEST_DIR, NEW_FILE_NAME);
        when(spyFs.rename(oldDir, newDir)).thenReturn(false);
        MapFile.rename(spyFs, oldDir.toString(), newDir.toString());
        fail("testRenameWithException no exception error !!!");
    } catch (IOException ex) {
        replacedertTrue("testRenameWithFalse invalid IOExceptionMessage error !!!", ex.getMessage().startsWith(ERROR_MESSAGE));
    } finally {
        IOUtils.cleanup(null, writer);
    }
}