Search in sources :

Example 36 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class ContractTestUtils method getFileStatusEventually.

/**
   * Get the status of a path eventually, even if the FS doesn't have create
   * consistency. If the path is not there by the time the timeout completes,
   * an assertion is raised.
   * @param fs FileSystem
   * @param path path to look for
   * @param timeout timeout in milliseconds
   * @return the status
   * @throws IOException if an I/O error occurs while writing or reading the
   * test file <i>other than file not found</i>
   */
public static FileStatus getFileStatusEventually(FileSystem fs, Path path, int timeout) throws IOException, InterruptedException {
    long endTime = System.currentTimeMillis() + timeout;
    FileStatus stat = null;
    do {
        try {
            stat = fs.getFileStatus(path);
        } catch (FileNotFoundException e) {
            if (System.currentTimeMillis() > endTime) {
                // timeout, raise an assert with more diagnostics
                assertPathExists(fs, "Path not found after " + timeout + " mS", path);
            } else {
                Thread.sleep(50);
            }
        }
    } while (stat == null);
    return stat;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) FileNotFoundException(java.io.FileNotFoundException)

Example 37 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class AbstractContractOpenTest method testOpenReadDir.

@Test
public void testOpenReadDir() throws Throwable {
    describe("create & read a directory");
    Path path = path("zero.dir");
    mkdirs(path);
    try {
        instream = getFileSystem().open(path);
        //at this point we've opened a directory
        fail("A directory has been opened for reading");
    } catch (FileNotFoundException e) {
        handleExpectedException(e);
    } catch (IOException e) {
        handleRelaxedException("opening a directory for reading", "FileNotFoundException", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 38 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class AbstractContractOpenTest method testOpenReadDirWithChild.

@Test
public void testOpenReadDirWithChild() throws Throwable {
    describe("create & read a directory which has a child");
    Path path = path("zero.dir");
    mkdirs(path);
    Path path2 = new Path(path, "child");
    mkdirs(path2);
    try {
        instream = getFileSystem().open(path);
        //at this point we've opened a directory
        fail("A directory has been opened for reading");
    } catch (FileNotFoundException e) {
        handleExpectedException(e);
    } catch (IOException e) {
        handleRelaxedException("opening a directory for reading", "FileNotFoundException", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 39 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class AbstractContractRenameTest method testRenameFileNonexistentDir.

@Test
public void testRenameFileNonexistentDir() throws Throwable {
    describe("rename a file into a new file in the same directory");
    Path renameSrc = path("testRenameSrc");
    Path renameTarget = path("subdir/testRenameTarget");
    byte[] data = dataset(256, 'a', 'z');
    writeDataset(getFileSystem(), renameSrc, data, data.length, 1024 * 1024, false);
    boolean renameCreatesDestDirs = isSupported(RENAME_CREATES_DEST_DIRS);
    try {
        boolean rename = rename(renameSrc, renameTarget);
        if (renameCreatesDestDirs) {
            assertTrue(rename);
            verifyFileContents(getFileSystem(), renameTarget, data);
        } else {
            assertFalse(rename);
            verifyFileContents(getFileSystem(), renameSrc, data);
        }
    } catch (FileNotFoundException e) {
        // allowed unless that rename flag is set
        assertFalse(renameCreatesDestDirs);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 40 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class AbstractContractRenameTest method testRenameNonexistentFile.

@Test
public void testRenameNonexistentFile() throws Throwable {
    describe("rename a file into a new file in the same directory");
    Path missing = path("testRenameNonexistentFileSrc");
    Path target = path("testRenameNonexistentFileDest");
    boolean renameReturnsFalseOnFailure = isSupported(ContractOptions.RENAME_RETURNS_FALSE_IF_SOURCE_MISSING);
    mkdirs(missing.getParent());
    try {
        boolean renamed = rename(missing, target);
        //expected an exception
        if (!renameReturnsFalseOnFailure) {
            String destDirLS = generateAndLogErrorListing(missing, target);
            fail("expected rename(" + missing + ", " + target + " ) to fail," + " got a result of " + renamed + " and a destination directory of " + destDirLS);
        } else {
            // at least one FS only returns false here, if that is the case
            // warn but continue
            getLog().warn("Rename returned {} renaming a nonexistent file", renamed);
            assertFalse("Renaming a missing file returned true", renamed);
        }
    } catch (FileNotFoundException e) {
        if (renameReturnsFalseOnFailure) {
            ContractTestUtils.fail("Renaming a missing file unexpectedly threw an exception", e);
        }
        handleExpectedException(e);
    } catch (IOException e) {
        handleRelaxedException("rename nonexistent file", "FileNotFoundException", e);
    }
    assertPathDoesNotExist("rename nonexistent file created a destination file", target);
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3218 IOException (java.io.IOException)1836 File (java.io.File)1277 FileInputStream (java.io.FileInputStream)814 FileOutputStream (java.io.FileOutputStream)492 InputStream (java.io.InputStream)466 BufferedReader (java.io.BufferedReader)262 FileReader (java.io.FileReader)230 ArrayList (java.util.ArrayList)205 Path (org.apache.hadoop.fs.Path)202 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 InputStreamReader (java.io.InputStreamReader)171 Test (org.junit.Test)171 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)138 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 Properties (java.util.Properties)120 URL (java.net.URL)119 FileStatus (org.apache.hadoop.fs.FileStatus)119 RandomAccessFile (java.io.RandomAccessFile)101