示例#1
0
        /// <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);
        }