Search in sources :

Example 1 with RawLocalFileSystem

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

the class TestFileSystemApplicationHistoryStore method testInitNonExistingWorkingDirectoryInSafeMode.

@Test
public void testInitNonExistingWorkingDirectoryInSafeMode() throws Exception {
    LOG.info("Starting testInitNonExistingWorkingDirectoryInSafeMode");
    tearDown();
    // Setup file system to inject startup conditions
    FileSystem fs = spy(new RawLocalFileSystem());
    FileStatus fileStatus = Mockito.mock(FileStatus.class);
    doReturn(false).when(fileStatus).isDirectory();
    doReturn(fileStatus).when(fs).getFileStatus(any(Path.class));
    doThrow(new IOException()).when(fs).mkdirs(any(Path.class));
    try {
        initAndStartStore(fs);
        Assert.fail("Exception should have been thrown");
    } catch (Exception e) {
    // Expected failure
    }
    // Make sure that directory creation was attempted
    verify(fileStatus, never()).isDirectory();
    verify(fs, times(1)).mkdirs(any(Path.class));
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with RawLocalFileSystem

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

the class TestRawlocalContractRename method testRenameWithNonEmptySubDirPOSIX.

/**
   * Test fallback rename code <code>handleEmptyDstDirectoryOnWindows()</code>
   * even on not Windows platform where the normal <code>File.renameTo()</code>
   * is supposed to work well. This test has been added for HADOOP-9805.
   * 
   * @see AbstractContractRenameTest#testRenameWithNonEmptySubDirPOSIX()
   */
@Test
public void testRenameWithNonEmptySubDirPOSIX() throws Throwable {
    final Path renameTestDir = path("testRenameWithNonEmptySubDir");
    final Path srcDir = new Path(renameTestDir, "src1");
    final Path srcSubDir = new Path(srcDir, "sub");
    final Path finalDir = new Path(renameTestDir, "dest");
    FileSystem fs = getFileSystem();
    ContractTestUtils.rm(fs, renameTestDir, true, false);
    fs.mkdirs(srcDir);
    fs.mkdirs(finalDir);
    ContractTestUtils.writeTextFile(fs, new Path(srcDir, "source.txt"), "this is the file in src dir", false);
    ContractTestUtils.writeTextFile(fs, new Path(srcSubDir, "subfile.txt"), "this is the file in src/sub dir", false);
    ContractTestUtils.assertPathExists(fs, "not created in src dir", new Path(srcDir, "source.txt"));
    ContractTestUtils.assertPathExists(fs, "not created in src/sub dir", new Path(srcSubDir, "subfile.txt"));
    RawLocalFileSystem rlfs = (RawLocalFileSystem) fs;
    rlfs.handleEmptyDstDirectoryOnWindows(srcDir, rlfs.pathToFile(srcDir), finalDir, rlfs.pathToFile(finalDir));
    // Accept only POSIX rename behavior in this test
    ContractTestUtils.assertPathExists(fs, "not renamed into dest dir", new Path(finalDir, "source.txt"));
    ContractTestUtils.assertPathExists(fs, "not renamed into dest/sub dir", new Path(finalDir, "sub/subfile.txt"));
    ContractTestUtils.assertPathDoesNotExist(fs, "not deleted", new Path(srcDir, "source.txt"));
}
Also used : Path(org.apache.hadoop.fs.Path) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) AbstractContractRenameTest(org.apache.hadoop.fs.contract.AbstractContractRenameTest) Test(org.junit.Test)

Example 3 with RawLocalFileSystem

use of org.apache.hadoop.fs.RawLocalFileSystem in project tez by apache.

the class ExternalSorter method sameVolRename.

/**
 * Rename srcPath to dstPath on the same volume. This is the same as
 * RawLocalFileSystem's rename method, except that it will not fall back to a
 * copy, and it will create the target directory if it doesn't exist.
 */
protected void sameVolRename(Path srcPath, Path dstPath) throws IOException {
    RawLocalFileSystem rfs = (RawLocalFileSystem) this.rfs;
    File src = rfs.pathToFile(srcPath);
    File dst = rfs.pathToFile(dstPath);
    if (!dst.getParentFile().exists()) {
        if (!dst.getParentFile().mkdirs()) {
            throw new IOException("Unable to rename " + src + " to " + dst + ": couldn't create parent directory");
        }
    }
    if (!src.renameTo(dst)) {
        throw new IOException("Unable to rename " + src + " to " + dst);
    }
}
Also used : RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) IOException(java.io.IOException) File(java.io.File)

Example 4 with RawLocalFileSystem

use of org.apache.hadoop.fs.RawLocalFileSystem in project flink by apache.

the class HadoopLocalFileSystemBehaviorTest method getFileSystem.

@Override
public FileSystem getFileSystem() throws Exception {
    org.apache.hadoop.fs.FileSystem fs = new RawLocalFileSystem();
    fs.initialize(LocalFileSystem.getLocalFsURI(), new Configuration());
    return new HadoopFileSystem(fs);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem)

Example 5 with RawLocalFileSystem

use of org.apache.hadoop.fs.RawLocalFileSystem in project kylo by Teradata.

the class FileSystemUtilTest method registerFileSystems.

/**
 * Verify adding file systems to Hadoop configuration.
 */
@Test
public void registerFileSystems() {
    final Configuration conf = new Configuration(false);
    FileSystemUtil.registerFileSystems(Arrays.asList(new LocalFileSystem(), new MockFileSystem(), new RawLocalFileSystem()), conf);
    Assert.assertEquals(LocalFileSystem.class.getName(), conf.get("fs.file.impl"));
    Assert.assertEquals(MockFileSystem.class.getName(), conf.get("fs.mock.impl"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) Test(org.junit.Test)

Aggregations

RawLocalFileSystem (org.apache.hadoop.fs.RawLocalFileSystem)16 Path (org.apache.hadoop.fs.Path)9 IOException (java.io.IOException)7 FileSystem (org.apache.hadoop.fs.FileSystem)7 Test (org.junit.Test)6 File (java.io.File)5 Configuration (org.apache.hadoop.conf.Configuration)5 FileStatus (org.apache.hadoop.fs.FileStatus)3 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)3 FileNotFoundException (java.io.FileNotFoundException)2 URISyntaxException (java.net.URISyntaxException)2 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2 IntWritable (org.apache.hadoop.io.IntWritable)2 NullWritable (org.apache.hadoop.io.NullWritable)2 Text (org.apache.hadoop.io.Text)2 Counters (org.apache.hadoop.mapred.Counters)2 Counter (org.apache.hadoop.mapred.Counters.Counter)2 Writer (org.apache.hadoop.mapred.IFile.Writer)2 JobConf (org.apache.hadoop.mapred.JobConf)2