public virtual void TestVerifyChecksum() { Path testPath = new Path(TestRootDir, "testPath"); Path testPath11 = new Path(TestRootDir, "testPath11"); FSDataOutputStream fout = localFs.Create(testPath); fout.Write(Runtime.GetBytesForString("testing")); fout.Close(); fout = localFs.Create(testPath11); fout.Write(Runtime.GetBytesForString("testing you")); fout.Close(); // Exercise some boundary cases - a divisor of the chunk size // the chunk size, 2x chunk size, and +/-1 around these. FileSystemTestHelper.ReadFile(localFs, testPath, 128); FileSystemTestHelper.ReadFile(localFs, testPath, 511); FileSystemTestHelper.ReadFile(localFs, testPath, 512); FileSystemTestHelper.ReadFile(localFs, testPath, 513); FileSystemTestHelper.ReadFile(localFs, testPath, 1023); FileSystemTestHelper.ReadFile(localFs, testPath, 1024); FileSystemTestHelper.ReadFile(localFs, testPath, 1025); localFs.Delete(localFs.GetChecksumFile(testPath), true); Assert.True("checksum deleted", !localFs.Exists(localFs.GetChecksumFile (testPath))); //copying the wrong checksum file FileUtil.Copy(localFs, localFs.GetChecksumFile(testPath11), localFs, localFs.GetChecksumFile (testPath), false, true, localFs.GetConf()); Assert.True("checksum exists", localFs.Exists(localFs.GetChecksumFile (testPath))); bool errorRead = false; try { FileSystemTestHelper.ReadFile(localFs, testPath, 1024); } catch (ChecksumException) { errorRead = true; } Assert.True("error reading", errorRead); //now setting verify false, the read should succeed localFs.SetVerifyChecksum(false); string str = FileSystemTestHelper.ReadFile(localFs, testPath, 1024).ToString(); Assert.True("read", "testing".Equals(str)); }
/// <exception cref="System.Exception"/> protected override void SetUp() { LocalFileSystem fs = FileSystem.GetLocal(conf); if (fs.Exists(TestRoot) && !fs.Delete(TestRoot, true)) { NUnit.Framework.Assert.Fail("Can't clean up test root dir"); } fs.Mkdirs(TestRoot); }
public virtual void Setup() { LocalFileSystem fs = FileSystem.GetLocal(conf); if (fs.Exists(TestDir) && !fs.Delete(TestDir, true)) { NUnit.Framework.Assert.Fail("Can't clean up test root dir"); } fs.Mkdirs(TestDir); }
/// <exception cref="System.IO.IOException"/> private static void RmBufferDirs() { Assert.True(!localFs.Exists(BufferPathRoot) || localFs.Delete(BufferPathRoot , true)); }
/// <summary>Test the capability of setting the working directory.</summary> /// <exception cref="System.IO.IOException"/> public virtual void TestWorkingDirectory() { Path origDir = fileSys.GetWorkingDirectory(); Path subdir = new Path(TestRootDir, "new"); try { // make sure it doesn't already exist Assert.True(!fileSys.Exists(subdir)); // make it and check for it Assert.True(fileSys.Mkdirs(subdir)); Assert.True(fileSys.IsDirectory(subdir)); fileSys.SetWorkingDirectory(subdir); // create a directory and check for it Path dir1 = new Path("dir1"); Assert.True(fileSys.Mkdirs(dir1)); Assert.True(fileSys.IsDirectory(dir1)); // delete the directory and make sure it went away fileSys.Delete(dir1, true); Assert.True(!fileSys.Exists(dir1)); // create files and manipulate them. Path file1 = new Path("file1"); Path file2 = new Path("sub/file2"); string contents = FileSystemTestHelper.WriteFile(fileSys, file1, 1); fileSys.CopyFromLocalFile(file1, file2); Assert.True(fileSys.Exists(file1)); Assert.True(fileSys.IsFile(file1)); CleanupFile(fileSys, file2); fileSys.CopyToLocalFile(file1, file2); CleanupFile(fileSys, file2); // try a rename fileSys.Rename(file1, file2); Assert.True(!fileSys.Exists(file1)); Assert.True(fileSys.Exists(file2)); fileSys.Rename(file2, file1); // try reading a file InputStream stm = fileSys.Open(file1); byte[] buffer = new byte[3]; int bytesRead = stm.Read(buffer, 0, 3); Assert.Equal(contents, Runtime.GetStringForBytes(buffer , 0, bytesRead)); stm.Close(); } finally { fileSys.SetWorkingDirectory(origDir); } }
public virtual void PrepFiles() { lfs.SetVerifyChecksum(true); lfs.SetWriteChecksum(true); lfs.Delete(srcPath, true); lfs.Delete(dstPath, true); FSDataOutputStream @out = lfs.Create(srcPath); @out.WriteChars("hi"); @out.Close(); Assert.True(lfs.Exists(lfs.GetChecksumFile(srcPath))); }