Beispiel #1
0
        public virtual void TestSymbolicLinks()
        {
            WriteFile(fc, File1, FileLen);
            WriteFile(fc, File2, FileLen);
            WriteFile(fc, File3, FileLen);
            Path dir4  = new Path(TestDir, "dir4");
            Path dir5  = new Path(dir4, "dir5");
            Path file4 = new Path(dir4, "file4");

            fc.CreateSymlink(Dir1, dir5, true);
            fc.CreateSymlink(File1, file4, true);
            RemoteIterator <LocatedFileStatus> itor = fc.Util().ListFiles(dir4, true);
            LocatedFileStatus stat = itor.Next();

            NUnit.Framework.Assert.IsTrue(stat.IsFile());
            NUnit.Framework.Assert.AreEqual(fc.MakeQualified(File2), stat.GetPath());
            stat = itor.Next();
            NUnit.Framework.Assert.IsTrue(stat.IsFile());
            NUnit.Framework.Assert.AreEqual(fc.MakeQualified(File3), stat.GetPath());
            stat = itor.Next();
            NUnit.Framework.Assert.IsTrue(stat.IsFile());
            NUnit.Framework.Assert.AreEqual(fc.MakeQualified(File1), stat.GetPath());
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            itor = fc.Util().ListFiles(dir4, false);
            stat = itor.Next();
            NUnit.Framework.Assert.IsTrue(stat.IsFile());
            NUnit.Framework.Assert.AreEqual(fc.MakeQualified(File1), stat.GetPath());
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
        }
Beispiel #2
0
        public virtual void TestFcResolveAfs()
        {
            Configuration conf           = new Configuration();
            FileContext   fcLocal        = FileContext.GetLocalFSFileContext();
            FileContext   fcHdfs         = FileContext.GetFileContext(cluster.GetFileSystem().GetUri());
            string        localTestRoot  = helper.GetAbsoluteTestRootDir(fcLocal);
            Path          alphaLocalPath = new Path(fcLocal.GetDefaultFileSystem().GetUri().ToString()
                                                    , new FilePath(localTestRoot, "alpha").GetAbsolutePath());

            DFSTestUtil.CreateFile(FileSystem.GetLocal(conf), alphaLocalPath, 16, (short)1, 2
                                   );
            Path linkTarget = new Path(fcLocal.GetDefaultFileSystem().GetUri().ToString(), localTestRoot
                                       );
            Path hdfsLink = new Path(fcHdfs.GetDefaultFileSystem().GetUri().ToString(), "/tmp/link"
                                     );

            fcHdfs.CreateSymlink(linkTarget, hdfsLink, true);
            Path alphaHdfsPathViaLink = new Path(fcHdfs.GetDefaultFileSystem().GetUri().ToString
                                                     () + "/tmp/link/alpha");
            ICollection <AbstractFileSystem> afsList = fcHdfs.ResolveAbstractFileSystems(alphaHdfsPathViaLink
                                                                                         );

            NUnit.Framework.Assert.AreEqual(2, afsList.Count);
            foreach (AbstractFileSystem afs in afsList)
            {
                if ((!afs.Equals(fcHdfs.GetDefaultFileSystem())) && (!afs.Equals(fcLocal.GetDefaultFileSystem
                                                                                     ())))
                {
                    NUnit.Framework.Assert.Fail("Failed to resolve AFS correctly");
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestFileContextResolveAfs()
        {
            Configuration conf = new Configuration();

            localFs = FileSystem.Get(conf);
            Path localPath = new Path(TestRootDirLocal + "/TestFileContextResolveAfs1");
            Path linkPath  = localFs.MakeQualified(new Path(TestRootDirLocal, "TestFileContextResolveAfs2"
                                                            ));

            localFs.Mkdirs(new Path(TestRootDirLocal));
            localFs.Create(localPath);
            fc.CreateSymlink(localPath, linkPath, true);
            ICollection <AbstractFileSystem> afsList = fc.ResolveAbstractFileSystems(linkPath);

            Assert.Equal(1, afsList.Count);
            localFs.DeleteOnExit(localPath);
            localFs.DeleteOnExit(linkPath);
            localFs.Close();
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestSymlinkHdfsDisable()
        {
            Configuration conf = new HdfsConfiguration();

            // disable symlink resolution
            conf.SetBoolean(CommonConfigurationKeys.FsClientResolveRemoteSymlinksKey, false);
            // spin up minicluster, get dfs and filecontext
            MiniDFSCluster        cluster = new MiniDFSCluster.Builder(conf).Build();
            DistributedFileSystem dfs     = cluster.GetFileSystem();
            FileContext           fc      = FileContext.GetFileContext(cluster.GetURI(0), conf);
            // Create test files/links
            FileContextTestHelper helper = new FileContextTestHelper("/tmp/TestSymlinkHdfsDisable"
                                                                     );
            Path root   = helper.GetTestRootPath(fc);
            Path target = new Path(root, "target");
            Path link   = new Path(root, "link");

            DFSTestUtil.CreateFile(dfs, target, 4096, (short)1, unchecked ((int)(0xDEADDEAD)));
            fc.CreateSymlink(target, link, false);
            // Try to resolve links with FileSystem and FileContext
            try
            {
                fc.Open(link);
                NUnit.Framework.Assert.Fail("Expected error when attempting to resolve link");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("resolution is disabled", e);
            }
            try
            {
                dfs.Open(link);
                NUnit.Framework.Assert.Fail("Expected error when attempting to resolve link");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("resolution is disabled", e);
            }
        }
 /// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/>
 /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
 /// <exception cref="System.IO.FileNotFoundException"/>
 /// <exception cref="Org.Apache.Hadoop.FS.ParentNotDirectoryException"/>
 /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
 /// <exception cref="System.IO.IOException"/>
 public override void CreateSymlink(Path target, Path link, bool createParent)
 {
     fc.CreateSymlink(target, link, createParent);
 }