|
@@ -25,6 +25,7 @@ import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
|
|
|
import org.apache.hadoop.hdfs.tools.snapshot.SnapshotDiff;
|
|
|
+import org.apache.hadoop.util.ChunkedArrayList;
|
|
|
import org.junit.After;
|
|
|
import org.junit.AfterClass;
|
|
|
import org.junit.Before;
|
|
@@ -195,4 +196,53 @@ public class TestSnapshotCommands {
|
|
|
"Disallowing snaphot on " + path + " succeeded", config);
|
|
|
fs.delete(new Path("/Fully/QPath"), true);
|
|
|
}
|
|
|
+
|
|
|
+ @Test (timeout=60000)
|
|
|
+ public void testSnapshotDiff()throws Exception {
|
|
|
+ Configuration config = new HdfsConfiguration();
|
|
|
+ Path snapDirPath = new Path(fs.getUri().toString() + "/snap_dir");
|
|
|
+ String snapDir = snapDirPath.toString();
|
|
|
+ fs.mkdirs(snapDirPath);
|
|
|
+
|
|
|
+ DFSTestUtil.DFSAdminRun("-allowSnapshot " + snapDirPath, 0,
|
|
|
+ "Allowing snaphot on " + snapDirPath + " succeeded", config);
|
|
|
+ DFSTestUtil.createFile(fs, new Path(snapDirPath, "file1"),
|
|
|
+ 1024, (short) 1, 100);
|
|
|
+ DFSTestUtil.FsShellRun("-createSnapshot " + snapDirPath + " sn1", config);
|
|
|
+ DFSTestUtil.createFile(fs, new Path(snapDirPath, "file2"),
|
|
|
+ 1024, (short) 1, 100);
|
|
|
+ DFSTestUtil.createFile(fs, new Path(snapDirPath, "file3"),
|
|
|
+ 1024, (short) 1, 100);
|
|
|
+ DFSTestUtil.FsShellRun("-createSnapshot " + snapDirPath + " sn2", config);
|
|
|
+
|
|
|
+ // verify the snapshot diff using api and command line
|
|
|
+ SnapshotDiffReport report_s1_s2 =
|
|
|
+ fs.getSnapshotDiffReport(snapDirPath, "sn1", "sn2");
|
|
|
+ DFSTestUtil.toolRun(new SnapshotDiff(config), snapDir +
|
|
|
+ " sn1 sn2", 0, report_s1_s2.toString());
|
|
|
+ DFSTestUtil.FsShellRun("-renameSnapshot " + snapDirPath + " sn2 sn3",
|
|
|
+ config);
|
|
|
+
|
|
|
+ SnapshotDiffReport report_s1_s3 =
|
|
|
+ fs.getSnapshotDiffReport(snapDirPath, "sn1", "sn3");
|
|
|
+ DFSTestUtil.toolRun(new SnapshotDiff(config), snapDir +
|
|
|
+ " sn1 sn3", 0, report_s1_s3.toString());
|
|
|
+
|
|
|
+ // Creating 100 more files so as to force DiffReport generation
|
|
|
+ // backend ChunkedArrayList to create multiple chunks.
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
+ DFSTestUtil.createFile(fs, new Path(snapDirPath, "file_" + i),
|
|
|
+ 1, (short) 1, 100);
|
|
|
+ }
|
|
|
+ DFSTestUtil.FsShellRun("-createSnapshot " + snapDirPath + " sn4", config);
|
|
|
+ DFSTestUtil.toolRun(new SnapshotDiff(config), snapDir +
|
|
|
+ " sn1 sn4", 0, null);
|
|
|
+
|
|
|
+ DFSTestUtil.FsShellRun("-deleteSnapshot " + snapDir + " sn1", config);
|
|
|
+ DFSTestUtil.FsShellRun("-deleteSnapshot " + snapDir + " sn3", config);
|
|
|
+ DFSTestUtil.FsShellRun("-deleteSnapshot " + snapDir + " sn4", config);
|
|
|
+ DFSTestUtil.DFSAdminRun("-disallowSnapshot " + snapDir, 0,
|
|
|
+ "Disallowing snaphot on " + snapDirPath + " succeeded", config);
|
|
|
+ fs.delete(new Path("/Fully/QPath"), true);
|
|
|
+ }
|
|
|
}
|