예제 #1
0
        /// <summary>Test the computation and representation of diff between snapshots</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestDiffReport()
        {
            cluster.GetNamesystem().GetSnapshotManager().SetAllowNestedSnapshots(true);
            Path subsub1    = new Path(sub1, "subsub1");
            Path subsubsub1 = new Path(subsub1, "subsubsub1");

            hdfs.Mkdirs(subsubsub1);
            ModifyAndCreateSnapshot(sub1, new Path[] { sub1, subsubsub1 });
            ModifyAndCreateSnapshot(subsubsub1, new Path[] { sub1, subsubsub1 });
            try
            {
                hdfs.GetSnapshotDiffReport(subsub1, "s1", "s2");
                NUnit.Framework.Assert.Fail("Expect exception when getting snapshot diff report: "
                                            + subsub1 + " is not a snapshottable directory.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("Directory is not a snapshottable directory: "
                                                         + subsub1, e);
            }
            string invalidName = "invalid";

            try
            {
                hdfs.GetSnapshotDiffReport(sub1, invalidName, invalidName);
                NUnit.Framework.Assert.Fail("Expect exception when providing invalid snapshot name for diff report"
                                            );
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("Cannot find the snapshot of directory "
                                                         + sub1 + " with name " + invalidName, e);
            }
            // diff between the same snapshot
            SnapshotDiffReport report = hdfs.GetSnapshotDiffReport(sub1, "s0", "s0");

            System.Console.Out.WriteLine(report);
            NUnit.Framework.Assert.AreEqual(0, report.GetDiffList().Count);
            report = hdfs.GetSnapshotDiffReport(sub1, string.Empty, string.Empty);
            System.Console.Out.WriteLine(report);
            NUnit.Framework.Assert.AreEqual(0, report.GetDiffList().Count);
            report = hdfs.GetSnapshotDiffReport(subsubsub1, "s0", "s2");
            System.Console.Out.WriteLine(report);
            NUnit.Framework.Assert.AreEqual(0, report.GetDiffList().Count);
            // test path with scheme also works
            report = hdfs.GetSnapshotDiffReport(hdfs.MakeQualified(subsubsub1), "s0", "s2");
            System.Console.Out.WriteLine(report);
            NUnit.Framework.Assert.AreEqual(0, report.GetDiffList().Count);
            VerifyDiffReport(sub1, "s0", "s2", new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType
                                                                                      .Modify, DFSUtil.String2Bytes(string.Empty)), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("file15")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("file12")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("file11")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("file11")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("file13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("link13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("link13")));
            VerifyDiffReport(sub1, "s0", "s5", new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType
                                                                                      .Modify, DFSUtil.String2Bytes(string.Empty)), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("file15")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("file12")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("file10")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("file11")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("file11")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("file13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("link13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("link13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("subsub1/subsubsub1"))
                             , new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                      .String2Bytes("subsub1/subsubsub1/file10")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("subsub1/subsubsub1/file11"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("subsub1/subsubsub1/link13"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file15")));
            VerifyDiffReport(sub1, "s2", "s5", new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType
                                                                                      .Modify, DFSUtil.String2Bytes("file10")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("subsub1/subsubsub1"))
                             , new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                      .String2Bytes("subsub1/subsubsub1/file10")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("subsub1/subsubsub1/file11"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Create, DFSUtil.String2Bytes("subsub1/subsubsub1/link13"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file15")));
            VerifyDiffReport(sub1, "s3", string.Empty, new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("subsub1/subsubsub1"))
                             , new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                      .String2Bytes("subsub1/subsubsub1/file15")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("subsub1/subsubsub1/file12"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Modify, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file10")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("subsub1/subsubsub1/file11"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/file11")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Modify, DFSUtil.String2Bytes("subsub1/subsubsub1/file13"
                                                                                           )), new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Create, DFSUtil
                                                                                                                                      .String2Bytes("subsub1/subsubsub1/link13")), new SnapshotDiffReport.DiffReportEntry
                                 (SnapshotDiffReport.DiffType.Delete, DFSUtil.String2Bytes("subsub1/subsubsub1/link13"
                                                                                           )));
        }