Search in sources :

Example 1 with PathExistsException

use of org.apache.hadoop.fs.PathExistsException in project hadoop by apache.

the class TestMove method testMoveTargetExistsWithoutExplicitRename.

@Test
public void testMoveTargetExistsWithoutExplicitRename() throws Exception {
    Path srcPath = new Path("mockfs:/file");
    Path targetPath = new Path("mockfs:/fold0");
    Path dupPath = new Path("mockfs:/fold0/file");
    Path srcPath2 = new Path("mockfs://user/file");
    Path targetPath2 = new Path("mockfs://user/fold0");
    Path dupPath2 = new Path("mockfs://user/fold0/file");
    InstrumentedRenameCommand cmd;
    String[] cmdargs = new String[] { "mockfs:/file", "mockfs:/fold0" };
    FileStatus src_fileStat, target_fileStat, dup_fileStat;
    URI myuri;
    src_fileStat = mock(FileStatus.class);
    target_fileStat = mock(FileStatus.class);
    dup_fileStat = mock(FileStatus.class);
    myuri = new URI("mockfs://user");
    when(src_fileStat.isDirectory()).thenReturn(false);
    when(target_fileStat.isDirectory()).thenReturn(true);
    when(dup_fileStat.isDirectory()).thenReturn(false);
    when(src_fileStat.getPath()).thenReturn(srcPath2);
    when(target_fileStat.getPath()).thenReturn(targetPath2);
    when(dup_fileStat.getPath()).thenReturn(dupPath2);
    when(mockFs.getFileStatus(eq(srcPath))).thenReturn(src_fileStat);
    when(mockFs.getFileStatus(eq(targetPath))).thenReturn(target_fileStat);
    when(mockFs.getFileStatus(eq(dupPath))).thenReturn(dup_fileStat);
    when(mockFs.getFileStatus(eq(srcPath2))).thenReturn(src_fileStat);
    when(mockFs.getFileStatus(eq(targetPath2))).thenReturn(target_fileStat);
    when(mockFs.getFileStatus(eq(dupPath2))).thenReturn(dup_fileStat);
    when(mockFs.getUri()).thenReturn(myuri);
    cmd = new InstrumentedRenameCommand();
    cmd.setConf(conf);
    cmd.setOverwrite(true);
    cmd.run(cmdargs);
    // make sure command failed with the proper exception
    assertTrue("Rename should have failed with path exists exception", cmd.error instanceof PathExistsException);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) PathExistsException(org.apache.hadoop.fs.PathExistsException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1 PathExistsException (org.apache.hadoop.fs.PathExistsException)1 Test (org.junit.Test)1