Example #1
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestRenameAcrossFileSystemsViaLink()
        {
            Path          localDir           = new Path("file://" + wrapper.GetAbsoluteTestRootDir() + "/test");
            Path          hdfsFile           = new Path(TestBaseDir1(), "file");
            Path          link               = new Path(TestBaseDir1(), "link");
            Path          hdfsFileNew        = new Path(TestBaseDir1(), "fileNew");
            Path          hdfsFileNewViaLink = new Path(link, "fileNew");
            FSTestWrapper localWrapper       = wrapper.GetLocalFSWrapper();

            localWrapper.Delete(localDir, true);
            localWrapper.Mkdir(localDir, FileContext.DefaultPerm, true);
            localWrapper.SetWorkingDirectory(localDir);
            CreateAndWriteFile(hdfsFile);
            wrapper.CreateSymlink(localDir, link, false);
            // Rename hdfs://test1/file to hdfs://test1/link/fileNew
            // which renames to file://TEST_ROOT/test/fileNew which
            // spans AbstractFileSystems and therefore fails.
            try
            {
                wrapper.Rename(hdfsFile, hdfsFileNewViaLink);
                NUnit.Framework.Assert.Fail("Renamed across file systems");
            }
            catch (InvalidPathException)
            {
            }
            catch (ArgumentException e)
            {
                // Expected from FileContext
                // Expected from Filesystem
                GenericTestUtils.AssertExceptionContains("Wrong FS: ", e);
            }
            // Now rename hdfs://test1/link/fileNew to hdfs://test1/fileNew
            // which renames file://TEST_ROOT/test/fileNew to hdfs://test1/fileNew
            // which spans AbstractFileSystems and therefore fails.
            CreateAndWriteFile(hdfsFileNewViaLink);
            try
            {
                wrapper.Rename(hdfsFileNewViaLink, hdfsFileNew);
                NUnit.Framework.Assert.Fail("Renamed across file systems");
            }
            catch (InvalidPathException)
            {
            }
            catch (ArgumentException e)
            {
                // Expected from FileContext
                // Expected from Filesystem
                GenericTestUtils.AssertExceptionContains("Wrong FS: ", e);
            }
        }
Example #2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestLinkAcrossFileSystems()
        {
            Path localDir  = new Path("file://" + wrapper.GetAbsoluteTestRootDir() + "/test");
            Path localFile = new Path("file://" + wrapper.GetAbsoluteTestRootDir() + "/test/file"
                                      );
            Path          link         = new Path(TestBaseDir1(), "linkToFile");
            FSTestWrapper localWrapper = wrapper.GetLocalFSWrapper();

            localWrapper.Delete(localDir, true);
            localWrapper.Mkdir(localDir, FileContext.DefaultPerm, true);
            localWrapper.SetWorkingDirectory(localDir);
            NUnit.Framework.Assert.AreEqual(localDir, localWrapper.GetWorkingDirectory());
            CreateAndWriteFile(localWrapper, localFile);
            wrapper.CreateSymlink(localFile, link, false);
            ReadFile(link);
            NUnit.Framework.Assert.AreEqual(fileSize, wrapper.GetFileStatus(link).GetLen());
        }
Example #3
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestCreateLinkToSlash()
        {
            Path dir         = new Path(TestBaseDir1());
            Path file        = new Path(TestBaseDir1(), "file");
            Path link        = new Path(TestBaseDir1(), "linkToSlash");
            Path fileViaLink = new Path(TestBaseDir1() + "/linkToSlash" + TestBaseDir1() + "/file"
                                        );

            CreateAndWriteFile(file);
            wrapper.SetWorkingDirectory(dir);
            wrapper.CreateSymlink(new Path("/"), link, false);
            ReadFile(fileViaLink);
            NUnit.Framework.Assert.AreEqual(fileSize, wrapper.GetFileStatus(fileViaLink).GetLen
                                                ());
            // Ditto when using another file context since the file system
            // for the slash is resolved according to the link's parent.
            if (wrapper is FileContextTestWrapper)
            {
                FSTestWrapper localWrapper = wrapper.GetLocalFSWrapper();
                Path          linkQual     = new Path(cluster.GetURI(0).ToString(), fileViaLink);
                NUnit.Framework.Assert.AreEqual(fileSize, localWrapper.GetFileStatus(linkQual).GetLen
                                                    ());
            }
        }