Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        private void DoIt(IDictionary <string, string> paramsToCorrupt)
        {
            MiniDFSCluster    cluster = null;
            FileSystem        fs      = null;
            SecondaryNameNode snn     = null;

            try
            {
                Configuration conf = new HdfsConfiguration();
                cluster = new MiniDFSCluster.Builder(conf).Build();
                cluster.WaitActive();
                conf.Set(DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey, "0.0.0.0:0");
                snn = new SecondaryNameNode(conf);
                fs  = cluster.GetFileSystem();
                fs.Mkdirs(new Path("/test/foo"));
                snn.DoCheckpoint();
                IList <FilePath> versionFiles = snn.GetFSImage().GetStorage().GetFiles(null, "VERSION"
                                                                                       );
                snn.Shutdown();
                foreach (FilePath versionFile in versionFiles)
                {
                    foreach (KeyValuePair <string, string> paramToCorrupt in paramsToCorrupt)
                    {
                        string param = paramToCorrupt.Key;
                        string val   = paramToCorrupt.Value;
                        System.Console.Out.WriteLine("Changing '" + param + "' to '" + val + "' in " + versionFile
                                                     );
                        FSImageTestUtil.CorruptVersionFile(versionFile, param, val);
                    }
                }
                snn = new SecondaryNameNode(conf);
                fs.Mkdirs(new Path("/test/bar"));
                snn.DoCheckpoint();
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
                if (snn != null)
                {
                    snn.Shutdown();
                }
            }
        }