/// <summary>test listCorruptFileBlocks in DistributedFileSystem</summary> /// <exception cref="System.Exception"/> public virtual void TestlistCorruptFileBlocksDFS() { Configuration conf = new Configuration(); conf.SetLong(DFSConfigKeys.DfsBlockreportIntervalMsecKey, 1000); conf.SetInt(DFSConfigKeys.DfsDatanodeDirectoryscanIntervalKey, 1); // datanode scans // directories FileSystem fs = null; MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).Build(); cluster.WaitActive(); fs = cluster.GetFileSystem(); DistributedFileSystem dfs = (DistributedFileSystem)fs; DFSTestUtil util = new DFSTestUtil.Builder().SetName("testGetCorruptFiles").SetNumFiles (3).SetMaxLevels(1).SetMaxSize(1024).Build(); util.CreateFiles(fs, "/corruptData"); RemoteIterator <Path> corruptFileBlocks = dfs.ListCorruptFileBlocks(new Path("/corruptData" )); int numCorrupt = CountPaths(corruptFileBlocks); NUnit.Framework.Assert.IsTrue(numCorrupt == 0); // delete the blocks string bpid = cluster.GetNamesystem().GetBlockPoolId(); // For loop through number of datadirectories per datanode (2) for (int i = 0; i < 2; i++) { FilePath storageDir = cluster.GetInstanceStorageDir(0, i); FilePath data_dir = MiniDFSCluster.GetFinalizedDir(storageDir, bpid); IList <FilePath> metadataFiles = MiniDFSCluster.GetAllBlockMetadataFiles(data_dir); if (metadataFiles == null) { continue; } // assertTrue("Blocks do not exist in data-dir", (blocks != null) && // (blocks.length > 0)); foreach (FilePath metadataFile in metadataFiles) { FilePath blockFile = Block.MetaToBlockFile(metadataFile); Log.Info("Deliberately removing file " + blockFile.GetName()); NUnit.Framework.Assert.IsTrue("Cannot remove file.", blockFile.Delete()); Log.Info("Deliberately removing file " + metadataFile.GetName()); NUnit.Framework.Assert.IsTrue("Cannot remove file.", metadataFile.Delete()); } } // break; int count = 0; corruptFileBlocks = dfs.ListCorruptFileBlocks(new Path("/corruptData")); numCorrupt = CountPaths(corruptFileBlocks); while (numCorrupt < 3) { Sharpen.Thread.Sleep(1000); corruptFileBlocks = dfs.ListCorruptFileBlocks(new Path("/corruptData")); numCorrupt = CountPaths(corruptFileBlocks); count++; if (count > 30) { break; } } // Validate we get all the corrupt files Log.Info("Namenode has bad files. " + numCorrupt); NUnit.Framework.Assert.IsTrue(numCorrupt == 3); util.Cleanup(fs, "/corruptData"); util.Cleanup(fs, "/goodData"); } finally { if (cluster != null) { cluster.Shutdown(); } } }