public virtual void TestUpgradeFromRel2ReservedImage()
        {
            UnpackStorage(Hadoop2ReservedImage, HadoopDfsDirTxt);
            MiniDFSCluster cluster = null;
            // Try it once without setting the upgrade flag to ensure it fails
            Configuration conf = new Configuration();

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).Format(false).StartupOption(HdfsServerConstants.StartupOption
                                                                                       .Upgrade).NumDataNodes(0).Build();
            }
            catch (ArgumentException e)
            {
                GenericTestUtils.AssertExceptionContains("reserved path component in this version"
                                                         , e);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
            // Try it again with a custom rename string
            try
            {
                FSImageFormat.SetRenameReservedPairs(".snapshot=.user-snapshot," + ".reserved=.my-reserved"
                                                     );
                cluster = new MiniDFSCluster.Builder(conf).Format(false).StartupOption(HdfsServerConstants.StartupOption
                                                                                       .Upgrade).NumDataNodes(0).Build();
                DistributedFileSystem dfs = cluster.GetFileSystem();
                // Make sure the paths were renamed as expected
                // Also check that paths are present after a restart, checks that the
                // upgraded fsimage has the same state.
                string[] expected = new string[] { "/edits", "/edits/.reserved", "/edits/.user-snapshot"
                                                   , "/edits/.user-snapshot/editsdir", "/edits/.user-snapshot/editsdir/editscontents"
                                                   , "/edits/.user-snapshot/editsdir/editsdir2", "/image", "/image/.reserved", "/image/.user-snapshot"
                                                   , "/image/.user-snapshot/imagedir", "/image/.user-snapshot/imagedir/imagecontents"
                                                   , "/image/.user-snapshot/imagedir/imagedir2", "/.my-reserved", "/.my-reserved/edits-touch"
                                                   , "/.my-reserved/image-touch" };
                for (int i = 0; i < 2; i++)
                {
                    // Restart the second time through this loop
                    if (i == 1)
                    {
                        cluster.FinalizeCluster(conf);
                        cluster.RestartNameNode(true);
                    }
                    AList <Path> toList = new AList <Path>();
                    toList.AddItem(new Path("/"));
                    AList <string> found = new AList <string>();
                    while (!toList.IsEmpty())
                    {
                        Path         p        = toList.Remove(0);
                        FileStatus[] statuses = dfs.ListStatus(p);
                        foreach (FileStatus status in statuses)
                        {
                            string path = status.GetPath().ToUri().GetPath();
                            System.Console.Out.WriteLine("Found path " + path);
                            found.AddItem(path);
                            if (status.IsDirectory())
                            {
                                toList.AddItem(status.GetPath());
                            }
                        }
                    }
                    foreach (string s in expected)
                    {
                        NUnit.Framework.Assert.IsTrue("Did not find expected path " + s, found.Contains(s
                                                                                                        ));
                    }
                    NUnit.Framework.Assert.AreEqual("Found an unexpected path while listing filesystem"
                                                    , found.Count, expected.Length);
                }
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }