You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2023/05/15 06:38:49 UTC

[GitHub] [hadoop] szetszwo commented on a diff in pull request #5656: HDFS-17010. Add a subtree test to TestSnapshotDiffReport.

szetszwo commented on code in PR #5656:
URL: https://github.com/apache/hadoop/pull/5656#discussion_r1193384825


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java:
##########
@@ -1603,4 +1609,51 @@ public void testSnapshotDiffReportRemoteIterator2() throws Exception {
           + "supported for snapshotDiffReport between two snapshots"));
     }
   }
+
+  @Test
+  public void testSubtrees() throws Exception {
+    final Path root = new Path("/");
+    final Path foo = new Path(root, "foo");
+    final Path bar = new Path(foo, "bar");
+    hdfs.mkdirs(bar);
+    modifyAndCreateSnapshot(bar, new Path[]{root});
+
+    final SnapshottableDirectoryStatus[] snapshottables
+        = hdfs.getSnapshottableDirListing();
+    Assert.assertEquals(1, snapshottables.length);
+    Assert.assertEquals(3, snapshottables[0].getSnapshotNumber());
+
+    final SnapshotStatus[] statuses = hdfs.getSnapshotListing(root);
+    Assert.assertEquals(3, statuses.length);
+    for (int i = 0; i < statuses.length; i++) {
+      final SnapshotStatus s = statuses[i];
+      LOG.info("Snapshot #{}: {}", s.getSnapshotID(), s.getFullPath());
+      Assert.assertEquals(i, s.getSnapshotID());
+    }
+
+    for (int i = 0; i <= 2; i++) {
+      for (int j = 0; j <= 2; j++) {
+        assertDiff(root, foo, bar, "s" + i, "s" + j);
+      }
+    }
+  }
+
+  private void assertDiff(Path root, Path foo, Path bar,
+      String from, String to) throws Exception {
+    final String barDiff = diff(bar, from, to);
+    final String fooDiff = diff(foo, from, to);
+    Assert.assertEquals(barDiff, fooDiff.replace("/bar", ""));
+
+    final String rootDiff = diff(root, from, to);
+    Assert.assertEquals(fooDiff, rootDiff.replace("/foo", ""));
+    Assert.assertEquals(barDiff, rootDiff.replace("/foo/bar", ""));
+  }
+
+  private String diff(Path path, String from, String to) throws Exception {
+    final SnapshotDiffReport diff = hdfs.getSnapshotDiffReport(path, from, to);
+    LOG.info("DIFF {} from {} to {}", path, from, to);
+    LOG.info("{}", diff);

Review Comment:
   @ayushtkn , thanks for reviewing this!
   
   > could have put in single line, ...
   
   The report itself is multiple lines.  So, it won't help much.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org