Search in sources :

Example 71 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestFileSystemCaching method testCloseAllForUGI.

@Test
public void testCloseAllForUGI() throws Exception {
    final Configuration conf = new Configuration();
    conf.set("fs.cachedfile.impl", FileSystem.getFileSystemClass("file", null).getName());
    UserGroupInformation ugiA = UserGroupInformation.createRemoteUser("foo");
    FileSystem fsA = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {

        @Override
        public FileSystem run() throws Exception {
            return FileSystem.get(new URI("cachedfile://a"), conf);
        }
    });
    //Now we should get the cached filesystem
    FileSystem fsA1 = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {

        @Override
        public FileSystem run() throws Exception {
            return FileSystem.get(new URI("cachedfile://a"), conf);
        }
    });
    assertSame(fsA, fsA1);
    FileSystem.closeAllForUGI(ugiA);
    //Now we should get a different (newly created) filesystem
    fsA1 = ugiA.doAs(new PrivilegedExceptionAction<FileSystem>() {

        @Override
        public FileSystem run() throws Exception {
            return FileSystem.get(new URI("cachedfile://a"), conf);
        }
    });
    assertNotSame(fsA, fsA1);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 72 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestFileSystemCanonicalization method testAuthorityFromDefaultFS.

@Test
public void testAuthorityFromDefaultFS() throws Exception {
    Configuration config = new Configuration();
    String defaultFsKey = CommonConfigurationKeys.FS_DEFAULT_NAME_KEY;
    FileSystem fs = getVerifiedFS("myfs://host", "myfs://host.a.b:123", config);
    verifyPaths(fs, new String[] { "myfs://" }, -1, false);
    config.set(defaultFsKey, "myfs://host");
    verifyPaths(fs, new String[] { "myfs://" }, -1, true);
    config.set(defaultFsKey, "myfs2://host");
    verifyPaths(fs, new String[] { "myfs://" }, -1, false);
    config.set(defaultFsKey, "myfs://host:123");
    verifyPaths(fs, new String[] { "myfs://" }, -1, true);
    config.set(defaultFsKey, "myfs://host:456");
    verifyPaths(fs, new String[] { "myfs://" }, -1, false);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 73 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestFileContext method testDefaultURIWithoutScheme.

@Test
public void testDefaultURIWithoutScheme() throws Exception {
    final Configuration conf = new Configuration();
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "/");
    try {
        FileContext.getFileContext(conf);
        fail(UnsupportedFileSystemException.class + " not thrown!");
    } catch (UnsupportedFileSystemException ufse) {
        LOG.info("Expected exception: ", ufse);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 74 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestFileSystemCaching method testDefaultFsUris.

@Test
public void testDefaultFsUris() throws Exception {
    final Configuration conf = new Configuration();
    conf.set("fs.defaultfs.impl", DefaultFs.class.getName());
    final URI defaultUri = URI.create("defaultfs://host");
    FileSystem.setDefaultUri(conf, defaultUri);
    FileSystem fs = null;
    // sanity check default fs
    final FileSystem defaultFs = FileSystem.get(conf);
    assertEquals(defaultUri, defaultFs.getUri());
    // has scheme, no auth
    fs = FileSystem.get(URI.create("defaultfs:/"), conf);
    assertSame(defaultFs, fs);
    fs = FileSystem.get(URI.create("defaultfs:///"), conf);
    assertSame(defaultFs, fs);
    // has scheme, same auth
    fs = FileSystem.get(URI.create("defaultfs://host"), conf);
    assertSame(defaultFs, fs);
    // has scheme, different auth
    fs = FileSystem.get(URI.create("defaultfs://host2"), conf);
    assertNotSame(defaultFs, fs);
    // no scheme, no auth
    fs = FileSystem.get(URI.create("/"), conf);
    assertSame(defaultFs, fs);
    // no scheme, same auth
    try {
        fs = FileSystem.get(URI.create("//host"), conf);
        fail("got fs with auth but no scheme");
    } catch (UnsupportedFileSystemException e) {
    }
    // no scheme, different auth
    try {
        fs = FileSystem.get(URI.create("//host2"), conf);
        fail("got fs with auth but no scheme");
    } catch (UnsupportedFileSystemException e) {
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) URI(java.net.URI) Test(org.junit.Test)

Example 75 with Configuration

use of org.apache.hadoop.conf.Configuration in project hadoop by apache.

the class TestHarFileSystemBasics method testNegativeInitWithoutIndex.

// ========== Negative:
@Test
public void testNegativeInitWithoutIndex() throws Exception {
    // delete the index file:
    final Path indexPath = new Path(harPath, "_index");
    localFileSystem.delete(indexPath, false);
    // now init the HarFs:
    final HarFileSystem hfs = new HarFileSystem(localFileSystem);
    final URI uri = new URI("har://" + harPath.toString());
    try {
        hfs.initialize(uri, new Configuration());
        Assert.fail("Exception expected.");
    } catch (IOException ioe) {
    // ok, expected.
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)5973 Test (org.junit.Test)3243 Path (org.apache.hadoop.fs.Path)1602 FileSystem (org.apache.hadoop.fs.FileSystem)903 IOException (java.io.IOException)850 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)727 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)517 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)502 File (java.io.File)499 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)388 ArrayList (java.util.ArrayList)360 URI (java.net.URI)319 BeforeClass (org.junit.BeforeClass)275 Job (org.apache.hadoop.mapreduce.Job)272 Before (org.junit.Before)264 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)219 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)203 HashMap (java.util.HashMap)192 FileStatus (org.apache.hadoop.fs.FileStatus)190 Properties (java.util.Properties)187