/// <summary>check the correctness of the diff reports</summary>
        /// <exception cref="System.IO.IOException"/>
        private void VerifyDiffReport(Path dir, string from, string to, params SnapshotDiffReport.DiffReportEntry
                                      [] entries)
        {
            SnapshotDiffReport report = hdfs.GetSnapshotDiffReport(dir, from, to);
            // reverse the order of from and to
            SnapshotDiffReport inverseReport = hdfs.GetSnapshotDiffReport(dir, to, from);

            System.Console.Out.WriteLine(report.ToString());
            System.Console.Out.WriteLine(inverseReport.ToString() + "\n");
            NUnit.Framework.Assert.AreEqual(entries.Length, report.GetDiffList().Count);
            NUnit.Framework.Assert.AreEqual(entries.Length, inverseReport.GetDiffList().Count
                                            );
            foreach (SnapshotDiffReport.DiffReportEntry entry in entries)
            {
                if (entry.GetType() == SnapshotDiffReport.DiffType.Modify)
                {
                    NUnit.Framework.Assert.IsTrue(report.GetDiffList().Contains(entry));
                    NUnit.Framework.Assert.IsTrue(inverseReport.GetDiffList().Contains(entry));
                }
                else
                {
                    if (entry.GetType() == SnapshotDiffReport.DiffType.Delete)
                    {
                        NUnit.Framework.Assert.IsTrue(report.GetDiffList().Contains(entry));
                        NUnit.Framework.Assert.IsTrue(inverseReport.GetDiffList().Contains(new SnapshotDiffReport.DiffReportEntry
                                                                                               (SnapshotDiffReport.DiffType.Create, entry.GetSourcePath())));
                    }
                    else
                    {
                        if (entry.GetType() == SnapshotDiffReport.DiffType.Create)
                        {
                            NUnit.Framework.Assert.IsTrue(report.GetDiffList().Contains(entry));
                            NUnit.Framework.Assert.IsTrue(inverseReport.GetDiffList().Contains(new SnapshotDiffReport.DiffReportEntry
                                                                                                   (SnapshotDiffReport.DiffType.Delete, entry.GetSourcePath())));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <exception cref="System.Exception"/>
        public virtual int Run(string[] argv)
        {
            string description = "hdfs snapshotDiff <snapshotDir> <from> <to>:\n" + "\tGet the difference between two snapshots, \n"
                                 + "\tor between a snapshot and the current tree of a directory.\n" + "\tFor <from>/<to>, users can use \".\" to present the current status,\n"
                                 + "\tand use \".snapshot/snapshot_name\" to present a snapshot,\n" + "\twhere \".snapshot/\" can be omitted\n";

            if (argv.Length != 3)
            {
                System.Console.Error.WriteLine("Usage: \n" + description);
                return(1);
            }
            FileSystem fs = FileSystem.Get(GetConf());

            if (!(fs is DistributedFileSystem))
            {
                System.Console.Error.WriteLine("SnapshotDiff can only be used in DistributedFileSystem"
                                               );
                return(1);
            }
            DistributedFileSystem dfs = (DistributedFileSystem)fs;
            Path   snapshotRoot       = new Path(argv[0]);
            string fromSnapshot       = GetSnapshotName(argv[1]);
            string toSnapshot         = GetSnapshotName(argv[2]);

            try
            {
                SnapshotDiffReport diffReport = dfs.GetSnapshotDiffReport(snapshotRoot, fromSnapshot
                                                                          , toSnapshot);
                System.Console.Out.WriteLine(diffReport.ToString());
            }
            catch (IOException e)
            {
                string[] content = e.GetLocalizedMessage().Split("\n");
                System.Console.Error.WriteLine("snapshotDiff: " + content[0]);
                return(1);
            }
            return(0);
        }