public virtual void TestOverwriteNonEmptyDirectory()
        {
            Describe("verify trying to create a file over a non-empty dir fails");
            Path path = Path("testOverwriteNonEmptyDirectory");

            Mkdirs(path);
            try
            {
                AssertIsDirectory(path);
            }
            catch (Exception failure)
            {
                if (IsSupported(IsBlobstore))
                {
                    // file/directory hack surfaces here
                    throw Extensions.InitCause(new AssumptionViolatedException(failure.ToString
                                                                                   ()), failure);
                }
                // else: rethrow
                throw;
            }
            Path child = new Path(path, "child");

            ContractTestUtils.WriteTextFile(GetFileSystem(), child, "child file", true);
            byte[] data = ContractTestUtils.Dataset(256, 'a', 'z');
            try
            {
                ContractTestUtils.WriteDataset(GetFileSystem(), path, data, data.Length, 1024, true
                                               );
                FileStatus status = GetFileSystem().GetFileStatus(path);
                bool       isDir  = status.IsDirectory();
                if (!isDir && IsSupported(IsBlobstore))
                {
                    // object store: downgrade to a skip so that the failure is visible
                    // in test results
                    ContractTestUtils.Skip("Object store allows a file to overwrite a directory");
                }
                NUnit.Framework.Assert.Fail("write of file over dir succeeded");
            }
            catch (FileAlreadyExistsException expected)
            {
                //expected
                HandleExpectedException(expected);
            }
            catch (FileNotFoundException e)
            {
                HandleRelaxedException("overwriting a dir with a file ", "FileAlreadyExistsException"
                                       , e);
            }
            catch (IOException e)
            {
                HandleRelaxedException("overwriting a dir with a file ", "FileAlreadyExistsException"
                                       , e);
            }
            AssertIsDirectory(path);
            AssertIsFile(child);
        }
        public virtual void TestDeleteNonEmptyDirRecursive()
        {
            Path path = Path("testDeleteNonEmptyDirNonRecursive");

            Mkdirs(path);
            Path file = new Path(path, "childfile");

            ContractTestUtils.WriteTextFile(GetFileSystem(), file, "goodbye, world", true);
            AssertDeleted(path, true);
            ContractTestUtils.AssertPathDoesNotExist(GetFileSystem(), "not deleted", file);
        }
        public virtual void TestDeleteSingleFile()
        {
            // Test delete of just a file
            Path path = Path("testDeleteSingleFile/d1/d2");

            Mkdirs(path);
            Path file = new Path(path, "childfile");

            ContractTestUtils.WriteTextFile(GetFileSystem(), file, "single file to be deleted."
                                            , true);
            ContractTestUtils.AssertPathExists(GetFileSystem(), "single file not created", file
                                               );
            AssertDeleted(file, false);
        }
Пример #4
0
        public virtual void TestRenameWithNonEmptySubDir()
        {
            Path       renameTestDir         = Path("testRenameWithNonEmptySubDir");
            Path       srcDir                = new Path(renameTestDir, "src1");
            Path       srcSubDir             = new Path(srcDir, "sub");
            Path       finalDir              = new Path(renameTestDir, "dest");
            FileSystem fs                    = GetFileSystem();
            bool       renameRemoveEmptyDest = IsSupported(RenameRemoveDestIfEmptyDir);

            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"));
            fs.Rename(srcDir, finalDir);
            // Accept both POSIX rename behavior and CLI rename behavior
            if (renameRemoveEmptyDest)
            {
                // POSIX rename behavior
                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"));
            }
            else
            {
                // CLI rename behavior
                ContractTestUtils.AssertPathExists(fs, "not renamed into dest dir", new Path(finalDir
                                                                                             , "src1/source.txt"));
                ContractTestUtils.AssertPathExists(fs, "not renamed into dest/sub dir", new Path(
                                                       finalDir, "src1/sub/subfile.txt"));
            }
            ContractTestUtils.AssertPathDoesNotExist(fs, "not deleted", new Path(srcDir, "source.txt"
                                                                                 ));
        }
        public virtual void TestDeleteNonEmptyDirNonRecursive()
        {
            Path path = Path("testDeleteNonEmptyDirNonRecursive");

            Mkdirs(path);
            Path file = new Path(path, "childfile");

            ContractTestUtils.WriteTextFile(GetFileSystem(), file, "goodbye, world", true);
            try
            {
                ContractTestUtils.RejectRootOperation(path);
                bool deleted = GetFileSystem().Delete(path, false);
                NUnit.Framework.Assert.Fail("non recursive delete should have raised an exception,"
                                            + " but completed with exit code " + deleted);
            }
            catch (IOException expected)
            {
                //expected
                HandleExpectedException(expected);
            }
            ContractTestUtils.AssertIsDirectory(GetFileSystem(), path);
        }