public virtual void TestConcatFileOnFile() { byte[] block = ContractTestUtils.Dataset(TestFileLen, 0, 255); ContractTestUtils.CreateFile(GetFileSystem(), target, false, block); GetFileSystem().Concat(target, new Path[] { srcFile }); ContractTestUtils.AssertFileHasLength(GetFileSystem(), target, TestFileLen * 2); ContractTestUtils.ValidateFileContent(ContractTestUtils.ReadDataset(GetFileSystem (), target, TestFileLen * 2), new byte[][] { block, block }); }
public virtual void TestAppendToExistingFile() { byte[] original = ContractTestUtils.Dataset(8192, 'A', 'Z'); byte[] appended = ContractTestUtils.Dataset(8192, '0', '9'); ContractTestUtils.CreateFile(GetFileSystem(), target, false, original); FSDataOutputStream outputStream = GetFileSystem().Append(target); outputStream.Write(appended); outputStream.Close(); byte[] bytes = ContractTestUtils.ReadDataset(GetFileSystem(), target, original.Length + appended.Length); ContractTestUtils.ValidateFileContent(bytes, new byte[][] { original, appended }); }
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); }
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); }
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); }