コード例 #1
0
        public virtual void TestAppendToEmptyFile()
        {
            ContractTestUtils.Touch(GetFileSystem(), target);
            byte[]             dataset      = ContractTestUtils.Dataset(256, 'a', 'z');
            FSDataOutputStream outputStream = GetFileSystem().Append(target);

            try
            {
                outputStream.Write(dataset);
            }
            finally
            {
                outputStream.Close();
            }
            byte[] bytes = ContractTestUtils.ReadDataset(GetFileSystem(), target, dataset.Length
                                                         );
            ContractTestUtils.CompareByteArrays(dataset, bytes, dataset.Length);
        }
コード例 #2
0
        public virtual void TestRenameFileBeingAppended()
        {
            ContractTestUtils.Touch(GetFileSystem(), target);
            AssertPathExists("original file does not exist", target);
            byte[]             dataset      = ContractTestUtils.Dataset(256, 'a', 'z');
            FSDataOutputStream outputStream = GetFileSystem().Append(target);

            outputStream.Write(dataset);
            Path renamed = new Path(testPath, "renamed");

            outputStream.Close();
            string listing = Ls(testPath);

            //expected: the stream goes to the file that was being renamed, not
            //the original path
            AssertPathExists("renamed destination file does not exist", renamed);
            AssertPathDoesNotExist("Source file found after rename during append:\n" + listing
                                   , target);
            byte[] bytes = ContractTestUtils.ReadDataset(GetFileSystem(), renamed, dataset.Length
                                                         );
            ContractTestUtils.CompareByteArrays(dataset, bytes, dataset.Length);
        }
コード例 #3
0
        public virtual void TestMkdirOverParentFile()
        {
            Describe("try to mkdir where a parent is a file");
            FileSystem fs   = GetFileSystem();
            Path       path = Path("testMkdirOverParentFile");

            byte[] dataset = ContractTestUtils.Dataset(1024, ' ', 'z');
            ContractTestUtils.CreateFile(GetFileSystem(), path, false, dataset);
            Path child = new Path(path, "child-to-mkdir");

            try
            {
                bool made = fs.Mkdirs(child);
                NUnit.Framework.Assert.Fail("mkdirs did not fail over a file but returned " + made
                                            + "; " + Ls(path));
            }
            catch (ParentNotDirectoryException e)
            {
                //parent is a directory
                HandleExpectedException(e);
            }
            catch (FileAlreadyExistsException e)
            {
                HandleExpectedException(e);
            }
            catch (IOException e)
            {
                HandleRelaxedException("mkdirs", "ParentNotDirectoryException", e);
            }
            AssertIsFile(path);
            byte[] bytes = ContractTestUtils.ReadDataset(GetFileSystem(), path, dataset.Length
                                                         );
            ContractTestUtils.CompareByteArrays(dataset, bytes, dataset.Length);
            AssertPathExists("mkdir failed", path);
            AssertDeleted(path, true);
        }