/// <summary>Test snapshot after file appending</summary> /// <exception cref="System.Exception"/> public virtual void TestSnapshotAfterAppending() { Path file = new Path(dir, "file"); // 1. create snapshot --> create file --> append SnapshotTestHelper.CreateSnapshot(hdfs, dir, "s0"); DFSTestUtil.CreateFile(hdfs, file, Blocksize, Replication, seed); DFSTestUtil.AppendFile(hdfs, file, Blocksize); INodeFile fileNode = (INodeFile)fsdir.GetINode(file.ToString()); // 2. create snapshot --> modify the file --> append hdfs.CreateSnapshot(dir, "s1"); hdfs.SetReplication(file, (short)(Replication - 1)); DFSTestUtil.AppendFile(hdfs, file, Blocksize); // check corresponding inodes fileNode = (INodeFile)fsdir.GetINode(file.ToString()); NUnit.Framework.Assert.AreEqual(Replication - 1, fileNode.GetFileReplication()); NUnit.Framework.Assert.AreEqual(Blocksize * 3, fileNode.ComputeFileSize()); // 3. create snapshot --> append hdfs.CreateSnapshot(dir, "s2"); DFSTestUtil.AppendFile(hdfs, file, Blocksize); // check corresponding inodes fileNode = (INodeFile)fsdir.GetINode(file.ToString()); NUnit.Framework.Assert.AreEqual(Replication - 1, fileNode.GetFileReplication()); NUnit.Framework.Assert.AreEqual(Blocksize * 4, fileNode.ComputeFileSize()); }
/// <summary> /// Test replication for a file with snapshots, also including the scenario /// where the original file is deleted /// </summary> /// <exception cref="System.Exception"/> public virtual void TestReplicationAfterDeletion() { // Create file1, set its replication to 3 DFSTestUtil.CreateFile(hdfs, file1, Blocksize, Replication, seed); IDictionary <Path, short> snapshotRepMap = new Dictionary <Path, short>(); // Take 3 snapshots of sub1 for (int i = 1; i <= 3; i++) { Path root = SnapshotTestHelper.CreateSnapshot(hdfs, sub1, "s" + i); Path ssFile = new Path(root, file1.GetName()); snapshotRepMap[ssFile] = Replication; } // Check replication CheckFileReplication(file1, Replication, Replication); CheckSnapshotFileReplication(file1, snapshotRepMap, Replication); // Delete file1 hdfs.Delete(file1, true); // Check replication of snapshots foreach (Path ss in snapshotRepMap.Keys) { INodeFile ssInode = GetINodeFile(ss); // The replication number derived from the // INodeFileWithLink#getBlockReplication should always == expectedBlockRep NUnit.Framework.Assert.AreEqual(Replication, ssInode.GetBlockReplication()); // Also check the number derived from INodeFile#getFileReplication NUnit.Framework.Assert.AreEqual(snapshotRepMap[ss], ssInode.GetFileReplication()); } }
/// <summary>Check the replication for both the current file and all its prior snapshots /// </summary> /// <param name="currentFile">the Path of the current file</param> /// <param name="snapshotRepMap"> /// A map maintaining all the snapshots of the current file, as well /// as their expected replication number stored in their corresponding /// INodes /// </param> /// <param name="expectedBlockRep">The expected replication number</param> /// <exception cref="System.Exception"/> private void CheckSnapshotFileReplication(Path currentFile, IDictionary <Path, short > snapshotRepMap, short expectedBlockRep) { // First check the getBlockReplication for the INode of the currentFile INodeFile inodeOfCurrentFile = GetINodeFile(currentFile); NUnit.Framework.Assert.AreEqual(expectedBlockRep, inodeOfCurrentFile.GetBlockReplication ()); // Then check replication for every snapshot foreach (Path ss in snapshotRepMap.Keys) { INodesInPath iip = fsdir.GetINodesInPath(ss.ToString(), true); INodeFile ssInode = iip.GetLastINode().AsFile(); // The replication number derived from the // INodeFileWithLink#getBlockReplication should always == expectedBlockRep NUnit.Framework.Assert.AreEqual(expectedBlockRep, ssInode.GetBlockReplication()); // Also check the number derived from INodeFile#getFileReplication NUnit.Framework.Assert.AreEqual(snapshotRepMap[ss], ssInode.GetFileReplication(iip .GetPathSnapshotId())); } }