/// <summary> /// Serialize a /// <see cref="INodeDirectory"/> /// </summary> /// <param name="node">The node to write</param> /// <param name="out"> /// The /// <see cref="System.IO.DataOutput"/> /// where the fields are written /// </param> /// <exception cref="System.IO.IOException"/> public static void WriteINodeDirectory(INodeDirectory node, DataOutput @out) { WriteLocalName(node, @out); @out.WriteLong(node.GetId()); @out.WriteShort(0); // replication @out.WriteLong(node.GetModificationTime()); @out.WriteLong(0); // access time @out.WriteLong(0); // preferred block size @out.WriteInt(-1); // # of blocks WriteQuota(node.GetQuotaCounts(), @out); if (node.IsSnapshottable()) { @out.WriteBoolean(true); } else { @out.WriteBoolean(false); @out.WriteBoolean(node.IsWithSnapshot()); } WritePermissionStatus(node, @out); }
/// <exception cref="System.IO.IOException"/> private FSNamesystem MakeNameSystemSpy(Block block, INodeFile file) { Configuration conf = new Configuration(); FSImage image = new FSImage(conf); DatanodeStorageInfo[] targets = new DatanodeStorageInfo[] { }; FSNamesystem namesystem = new FSNamesystem(conf, image); namesystem.SetImageLoaded(true); // set file's parent as root and put the file to inodeMap, so // FSNamesystem's isFileDeleted() method will return false on this file if (file.GetParent() == null) { INodeDirectory mparent = Org.Mockito.Mockito.Mock <INodeDirectory>(); INodeDirectory parent = new INodeDirectory(mparent.GetId(), new byte[0], mparent. GetPermissionStatus(), mparent.GetAccessTime()); parent.SetLocalName(new byte[0]); parent.AddChild(file); file.SetParent(parent); } namesystem.dir.GetINodeMap().Put(file); FSNamesystem namesystemSpy = Org.Mockito.Mockito.Spy(namesystem); BlockInfoContiguousUnderConstruction blockInfo = new BlockInfoContiguousUnderConstruction (block, (short)1, HdfsServerConstants.BlockUCState.UnderConstruction, targets); blockInfo.SetBlockCollection(file); blockInfo.SetGenerationStamp(genStamp); blockInfo.InitializeBlockRecovery(genStamp); Org.Mockito.Mockito.DoReturn(true).When(file).RemoveLastBlock(Matchers.Any <Block> ()); Org.Mockito.Mockito.DoReturn(true).When(file).IsUnderConstruction(); Org.Mockito.Mockito.DoReturn(new BlockInfoContiguous[1]).When(file).GetBlocks(); Org.Mockito.Mockito.DoReturn(blockInfo).When(namesystemSpy).GetStoredBlock(Matchers.Any <Block>()); Org.Mockito.Mockito.DoReturn(blockInfo).When(file).GetLastBlock(); Org.Mockito.Mockito.DoReturn(string.Empty).When(namesystemSpy).CloseFileCommitBlocks (Matchers.Any <INodeFile>(), Matchers.Any <BlockInfoContiguous>()); Org.Mockito.Mockito.DoReturn(Org.Mockito.Mockito.Mock <FSEditLog>()).When(namesystemSpy ).GetEditLog(); return(namesystemSpy); }