GeorgeJahad commented on code in PR #4134:
URL: https://github.com/apache/ozone/pull/4134#discussion_r1071549142


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java:
##########
@@ -61,59 +78,78 @@ public static void initClass() throws Exception {
         .build();
     cluster.waitForClusterToBeReady();
     ozoneManager = cluster.getOzoneManager();
-  }
 
-  @Before
-  public void init() {
     String hostPrefix = OZONE_OFS_URI_SCHEME + "://" + OM_SERVICE_ID;
     clientConf = new OzoneConfiguration(cluster.getConf());
     clientConf.set(FS_DEFAULT_NAME_KEY, hostPrefix);
+    shell = new OzoneFsShell(clientConf);
+
+    // Create vol1 and bucket1
+    int res = ToolRunner.run(shell,
+        new String[]{"-mkdir", "-p", BUCKET_ONE_PATH});
+    Assertions.assertEquals(0, res);
+    // List the bucket to make sure that bucket exists.
+    res = ToolRunner.run(shell, new String[]{"-ls", BUCKET_ONE_PATH});
+    Assertions.assertEquals(0, res);
   }
 
-  @AfterClass
-  public static void shutdown() {
+  @AfterAll
+  public static void shutdown() throws Exception {
+    shell.close();
     if (cluster != null) {
       cluster.shutdown();
     }
   }
 
   @Test
   public void testCreateSnapshot() throws Exception {
-    String volume = "vol1";
-    String bucket = "bucket1";
-    String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
-    String snapshotName = "snap1";
-    String testKey = testVolBucket + "/key1";
-
-    OzoneFsShell shell = new OzoneFsShell(clientConf);
-    try {
-      // Create volume and bucket
-      int res = ToolRunner.run(shell,
-          new String[]{"-mkdir", "-p", testVolBucket});
-      assertEquals(0, res);
-      // Create key
-      ToolRunner.run(shell, new String[]{"-touch", testKey});
-      assertEquals(0, res);
-      // List the bucket to make sure that bucket exists.
-      ToolRunner.run(shell, new String[]{"-ls", testVolBucket});
-      assertEquals(0, res);
+    // Create key1
+    int res = ToolRunner.run(shell, new String[]{"-touch", KEY_ONE_PATH});
+    Assertions.assertEquals(0, res);
+
+    res = ToolRunner.run(shell,
+        new String[]{"-createSnapshot", BUCKET_ONE_PATH, SNAPSHOT_ONE});
+    // Asserts that create request succeeded
+    Assertions.assertEquals(0, res);
+
+    SnapshotInfo snapshotInfo = ozoneManager
+        .getMetadataManager()
+        .getSnapshotInfoTable()
+        .get(SnapshotInfo.getTableKey(VOLUME_ONE, BUCKET_ONE, SNAPSHOT_ONE));
+
+    // Assert that snapshot exists in RocksDB.
+    // We can't use list or valid if snapshot directory exists because DB
+    // transaction might not be flushed by the time.
+    Assertions.assertNotNull(snapshotInfo);
+  }
+
+  /**
+   * Test list snapshots with "ozone fs -ls".
+   */
+  @Test
+  public void testFsLsSnapshot() throws Exception {
+    // Create key2
+    int res = ToolRunner.run(shell, new String[]{"-touch", KEY_TWO_PATH});
+    Assertions.assertEquals(0, res);
+
+    // Create snap2
+    res = ToolRunner.run(shell,
+        new String[]{"-createSnapshot", BUCKET_ONE_PATH, SNAPSHOT_TWO});
+    // Asserts that create request succeeded
+    Assertions.assertEquals(0, res);
+
+    try (GenericTestUtils.SystemOutCapturer capture =
+             new GenericTestUtils.SystemOutCapturer()) {
 
       res = ToolRunner.run(shell,
-          new String[]{"-createSnapshot", testVolBucket, snapshotName});
-      // Asserts that create request succeeded
-      assertEquals(0, res);
-
-      SnapshotInfo snapshotInfo = ozoneManager
-          .getMetadataManager()
-          .getSnapshotInfoTable()
-          .get(SnapshotInfo.getTableKey(volume, bucket, snapshotName));
-
-      // Assert that snapshot exists in RocksDB.
-      // We can't use list or valid if snapshot directory exists because DB
-      // transaction might not be flushed by the time.
-      Assert.assertNotNull(snapshotInfo);
-    } finally {
-      shell.close();
+          new String[]{"-ls", BUCKET_ONE_WITH_SNAPSHOT_INDICATOR_PATH});
+      // Asserts that -ls request succeeded
+      Assertions.assertEquals(0, res);
+
+      // Assert that output contains snap2
+      Assertions.assertTrue(capture.getOutput()
+          .contains(BUCKET_ONE_WITH_SNAPSHOT_INDICATOR_PATH
+              + OM_KEY_PREFIX + SNAPSHOT_TWO));

Review Comment:
   Check for KEY_TWO as well, please.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to