This is an automated email from the ASF dual-hosted git repository.

sshenoy pushed a commit to branch HDDS-6517-Snapshot
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/HDDS-6517-Snapshot by this 
push:
     new 0c25be8cdf HDDS-7702. [snapshot] Add unit-testcases for Ozone fs 
createSnapshot (#4122)
0c25be8cdf is described below

commit 0c25be8cdff777d0fa67a6fa65543de33febe0d8
Author: jyotirmoy-gh <[email protected]>
AuthorDate: Thu Jan 19 11:59:55 2023 +0530

    HDDS-7702. [snapshot] Add unit-testcases for Ozone fs createSnapshot (#4122)
---
 .../hadoop/fs/ozone/TestOzoneFsSnapshot.java       | 184 +++++++++++++++++++--
 1 file changed, 173 insertions(+), 11 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
index 91f5251ed2..95ba876c06 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
@@ -17,6 +17,8 @@
 package org.apache.hadoop.fs.ozone;
 
 import java.util.UUID;
+
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.ozone.MiniOzoneCluster;
 import org.apache.hadoop.ozone.om.OzoneManager;
@@ -77,6 +79,25 @@ public class TestOzoneFsSnapshot {
     }
   }
 
+  private void createVolBuckKey(String testVolBucket, String testKey)
+          throws Exception {
+    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
+      res = ToolRunner.run(shell, new String[]{"-touch", testKey});
+      assertEquals(0, res);
+      // List the bucket to make sure that bucket exists.
+      res = ToolRunner.run(shell, new String[]{"-ls", testVolBucket});
+      assertEquals(0, res);
+    } finally {
+      shell.close();
+    }
+  }
+
   @Test
   public void testCreateSnapshot() throws Exception {
     String volume = "vol1";
@@ -85,20 +106,11 @@ public class TestOzoneFsSnapshot {
     String snapshotName = "snap1";
     String testKey = testVolBucket + "/key1";
 
+    createVolBuckKey(testVolBucket, testKey);
+
     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);
-
-      res = ToolRunner.run(shell,
           new String[]{"-createSnapshot", testVolBucket, snapshotName});
       // Asserts that create request succeeded
       assertEquals(0, res);
@@ -116,4 +128,154 @@ public class TestOzoneFsSnapshot {
       shell.close();
     }
   }
+
+  @Test
+  public void testCreateSnapshotDuplicateName() throws Exception {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    String key = "key-" + RandomStringUtils.randomNumeric(5);
+    String snapshotName = "snap-" + RandomStringUtils.randomNumeric(5);
+
+    String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
+    String testKey = testVolBucket + OM_KEY_PREFIX + key;
+
+    createVolBuckKey(testVolBucket, testKey);
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, snapshotName});
+      // Asserts that create request succeeded
+      assertEquals(0, res);
+
+      res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, snapshotName});
+      // Asserts that create request fails since snapshot name provided twice
+      assertEquals(1, res);
+    } finally {
+      shell.close();
+    }
+  }
+
+  @Test
+  public void testCreateSnapshotInvalidName() throws Exception {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    String key = "key-" + RandomStringUtils.randomNumeric(5);
+    String snapshotName = "snapa?b";
+
+    String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
+    String testKey = testVolBucket + OM_KEY_PREFIX + key;
+
+    createVolBuckKey(testVolBucket, testKey);
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, snapshotName});
+      // Asserts that create request failed since invalid name passed
+      assertEquals(1, res);
+
+    } finally {
+      shell.close();
+    }
+  }
+
+  @Test
+  public void testCreateSnapshotOnlyNumericName() throws Exception {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    String key = "key-" + RandomStringUtils.randomNumeric(5);
+    String snapshotName = "1234";
+
+    String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
+    String testKey = testVolBucket + OM_KEY_PREFIX + key;
+
+    createVolBuckKey(testVolBucket, testKey);
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, snapshotName});
+      // Asserts that create request failed since only numeric name passed
+      assertEquals(1, res);
+
+    } finally {
+      shell.close();
+    }
+  }
+
+  @Test
+  public void testCreateSnapshotInvalidURI() throws Exception {
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", "invalidURI"});
+      // Asserts that create request failed since
+      // invalid volume-bucket URI passed
+      assertEquals(1, res);
+
+    } finally {
+      shell.close();
+    }
+  }
+
+  @Test
+  public void testCreateSnapshotNameLength() throws Exception {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    String key = "key-" + RandomStringUtils.randomNumeric(5);
+    String name63 =
+            "snap75795657617173401188448010125899089001363595171500499231286";
+    String name64 =
+            "snap156808943643007724443266605711479126926050896107709081166294";
+
+    String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
+    String testKey = testVolBucket + OM_KEY_PREFIX + key;
+
+    createVolBuckKey(testVolBucket, testKey);
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, name63});
+      // Asserts that create request succeeded since namelength
+      // less than 64 char
+      assertEquals(0, res);
+
+      res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot", testVolBucket, name64});
+      // Asserts that create request fails since namelength
+      // more than 64 char
+      assertEquals(1, res);
+
+      SnapshotInfo snapshotInfo = ozoneManager
+              .getMetadataManager()
+              .getSnapshotInfoTable()
+              .get(SnapshotInfo.getTableKey(volume, bucket, name63));
+
+      Assert.assertNotNull(snapshotInfo);
+
+    } finally {
+      shell.close();
+    }
+  }
+
+  @Test
+  public void testCreateSnapshotParameterMissing() throws Exception {
+
+    OzoneFsShell shell = new OzoneFsShell(clientConf);
+    try {
+
+      int res = ToolRunner.run(shell,
+              new String[]{"-createSnapshot"});
+      // Asserts that create request failed since mandatory params not passed
+      assertEquals(-1, res);
+
+    } finally {
+      shell.close();
+    }
+  }
 }


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

Reply via email to