public virtual void TestSeekBigFile() { Describe("Seek round a large file and verify the bytes are what is expected"); Path testSeekFile = Path("bigseekfile.txt"); byte[] block = ContractTestUtils.Dataset(65536, 0, 255); ContractTestUtils.CreateFile(GetFileSystem(), testSeekFile, false, block); instream = GetFileSystem().Open(testSeekFile); Assert.Equal(0, instream.GetPos()); //expect that seek to 0 works instream.Seek(0); int result = instream.Read(); Assert.Equal(0, result); Assert.Equal(1, instream.Read()); Assert.Equal(2, instream.Read()); //do seek 32KB ahead instream.Seek(32768); Assert.Equal("@32768", block[32768], unchecked ((byte)instream. Read())); instream.Seek(40000); Assert.Equal("@40000", block[40000], unchecked ((byte)instream. Read())); instream.Seek(8191); Assert.Equal("@8191", block[8191], unchecked ((byte)instream.Read ())); instream.Seek(0); Assert.Equal("@0", 0, unchecked ((byte)instream.Read())); }
public virtual void TestOpenFileTwice() { Describe("verify that two opened file streams are independent"); Path path = Path("testopenfiletwice.txt"); byte[] block = ContractTestUtils.Dataset(TestFileLen, 0, 255); //this file now has a simple rule: offset => value ContractTestUtils.CreateFile(GetFileSystem(), path, false, block); //open first FSDataInputStream instream1 = GetFileSystem().Open(path); int c = instream1.Read(); Assert.Equal(0, c); FSDataInputStream instream2 = null; try { instream2 = GetFileSystem().Open(path); Assert.Equal("first read of instream 2", 0, instream2.Read()); Assert.Equal("second read of instream 1", 1, instream1.Read()); instream1.Close(); Assert.Equal("second read of instream 2", 1, instream2.Read()); //close instream1 again instream1.Close(); } finally { IOUtils.CloseStream(instream1); IOUtils.CloseStream(instream2); } }
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 TestFsIsEncrypted() { Describe("create an empty file and call FileStatus.isEncrypted()"); Path path = Path("file"); ContractTestUtils.CreateFile(GetFileSystem(), path, false, new byte[0]); FileStatus stat = GetFileSystem().GetFileStatus(path); NUnit.Framework.Assert.IsFalse("Expecting false for stat.isEncrypted()", stat.IsEncrypted ()); }
/// <exception cref="System.Exception"/> public override void Setup() { base.Setup(); SkipIfUnsupported(SupportsConcat); //delete the test directory testPath = Path("test"); srcFile = new Path(testPath, "small.txt"); zeroByteFile = new Path(testPath, "zero.txt"); target = new Path(testPath, "target"); byte[] block = ContractTestUtils.Dataset(TestFileLen, 0, 255); ContractTestUtils.CreateFile(GetFileSystem(), srcFile, false, block); ContractTestUtils.Touch(GetFileSystem(), zeroByteFile); }
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 }); }
/// <exception cref="System.Exception"/> public override void Setup() { base.Setup(); SkipIfUnsupported(SupportsSeek); //delete the test directory testPath = GetContract().GetTestPath(); smallSeekFile = Path("seekfile.txt"); zeroByteFile = Path("zero.txt"); byte[] block = ContractTestUtils.Dataset(TestFileLen, 0, 255); //this file now has a simple rule: offset => value ContractTestUtils.CreateFile(GetFileSystem(), smallSeekFile, false, block); ContractTestUtils.Touch(GetFileSystem(), zeroByteFile); }
public virtual void TestConcatOnSelf() { byte[] block = ContractTestUtils.Dataset(TestFileLen, 0, 255); ContractTestUtils.CreateFile(GetFileSystem(), target, false, block); try { GetFileSystem().Concat(target, new Path[] { target }); } catch (Exception e) { //expected HandleExpectedException(e); } }
public virtual void TestRandomSeeks() { int limit = GetContract().GetLimit(TestRandomSeekCount, DefaultRandomSeekCount); Describe("Testing " + limit + " random seeks"); int filesize = 10 * 1024; byte[] buf = ContractTestUtils.Dataset(filesize, 0, 255); Path randomSeekFile = Path("testrandomseeks.bin"); ContractTestUtils.CreateFile(GetFileSystem(), randomSeekFile, false, buf); Random r = new Random(); FSDataInputStream stm = GetFileSystem().Open(randomSeekFile); // Record the sequence of seeks and reads which trigger a failure. int[] seeks = new int[10]; int[] reads = new int[10]; try { for (int i = 0; i < limit; i++) { int seekOff = r.Next(buf.Length); int toRead = r.Next(Math.Min(buf.Length - seekOff, 32000)); seeks[i % seeks.Length] = seekOff; reads[i % reads.Length] = toRead; ContractTestUtils.VerifyRead(stm, buf, seekOff, toRead); } } catch (Exception afe) { StringBuilder sb = new StringBuilder(); sb.Append("Sequence of actions:\n"); for (int j = 0; j < seeks.Length; j++) { sb.Append("seek @ ").Append(seeks[j]).Append(" ").Append("read ").Append(reads[j ]).Append("\n"); } Log.Error(sb.ToString()); throw; } finally { stm.Close(); } }
public virtual void TestCreateFileOverRoot() { Path root = new Path("/"); byte[] dataset = ContractTestUtils.Dataset(1024, ' ', 'z'); try { ContractTestUtils.CreateFile(GetFileSystem(), root, false, dataset); NUnit.Framework.Assert.Fail("expected an exception, got a file created over root: " + Ls(root)); } catch (IOException e) { //expected HandleExpectedException(e); } AssertIsDirectory(root); }
public virtual void TestSequentialRead() { Describe("verify that sequential read() operations return values"); Path path = Path("testsequentialread.txt"); int len = 4; int @base = unchecked ((int)(0x40)); // 64 byte[] block = ContractTestUtils.Dataset(len, @base, @base + len); //this file now has a simple rule: offset => (value | 0x40) ContractTestUtils.CreateFile(GetFileSystem(), path, false, block); //open first instream = GetFileSystem().Open(path); Assert.Equal(@base, instream.Read()); Assert.Equal(@base + 1, instream.Read()); Assert.Equal(@base + 2, instream.Read()); Assert.Equal(@base + 3, instream.Read()); // and now, failures Assert.Equal(-1, instream.Read()); Assert.Equal(-1, instream.Read()); instream.Close(); }
public virtual void TestPositionedBulkReadDoesntChangePosition() { Describe("verify that a positioned read does not change the getPos() value"); Path testSeekFile = Path("bigseekfile.txt"); byte[] block = ContractTestUtils.Dataset(65536, 0, 255); ContractTestUtils.CreateFile(GetFileSystem(), testSeekFile, false, block); instream = GetFileSystem().Open(testSeekFile); instream.Seek(39999); Assert.True(-1 != instream.Read()); Assert.Equal(40000, instream.GetPos()); byte[] readBuffer = new byte[256]; instream.Read(128, readBuffer, 0, readBuffer.Length); //have gone back Assert.Equal(40000, instream.GetPos()); //content is the same too Assert.Equal("@40000", block[40000], unchecked ((byte)instream. Read())); //now verify the picked up data for (int i = 0; i < 256; i++) { Assert.Equal("@" + i, block[i + 128], readBuffer[i]); } }
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); }