xBis7 commented on code in PR #4134:
URL: https://github.com/apache/ozone/pull/4134#discussion_r1095989765
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java:
##########
@@ -65,259 +77,229 @@ public static void initClass() throws Exception {
ozoneManager = cluster.getOzoneManager();
}
- @Before
- public void init() {
+ @BeforeEach
+ public void init() throws Exception {
String hostPrefix = OZONE_OFS_URI_SCHEME + "://" + OM_SERVICE_ID;
- clientConf = new OzoneConfiguration(cluster.getConf());
+ OzoneConfiguration clientConf =
+ new OzoneConfiguration(cluster.getConf());
clientConf.set(FS_DEFAULT_NAME_KEY, hostPrefix);
+
+ shell = new OzoneFsShell(clientConf);
+
+ this.volume = "vol-" + RandomStringUtils.randomNumeric(5);
+ this.bucket = "buck-" + RandomStringUtils.randomNumeric(5);
+ this.key = "key-" + RandomStringUtils.randomNumeric(5);
+
+ this.bucketPath = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
+ this.bucketWithSnapshotIndicatorPath = bucketPath +
+ OM_KEY_PREFIX + OM_SNAPSHOT_INDICATOR;
+
+ String keyPath = bucketPath + OM_KEY_PREFIX + key;
+ createVolBuckKey(bucketPath, keyPath);
+ }
+
+ @AfterEach
+ public void cleanup() throws IOException {
+ shell.close();
}
- @AfterClass
+ @AfterAll
public static void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}
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";
- String bucket = "bucket1";
- String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
- String snapshotName = "snap1";
- String testKey = testVolBucket + "/key1";
+ throws Exception {
+
+ // Create volume and bucket
+ int res = ToolRunner.run(shell,
+ new String[]{"-mkdir", "-p", testVolBucket});
+ Assertions.assertEquals(0, res);
+ // Create key
+ res = ToolRunner.run(shell, new String[]{"-touch", testKey});
+ Assertions.assertEquals(0, res);
+ // List the bucket to make sure that bucket exists.
+ res = ToolRunner.run(shell, new String[]{"-ls", testVolBucket});
+ Assertions.assertEquals(0, res);
- 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);
-
- 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();
- }
}
@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;
+ int res = ToolRunner.run(shell,
+ new String[]{"-createSnapshot", bucketPath, snapshotName});
+ // Asserts that create request succeeded
+ Assertions.assertEquals(0, res);
- createVolBuckKey(testVolBucket, testKey);
+ res = ToolRunner.run(shell,
+ new String[]{"-createSnapshot", bucketPath, snapshotName});
+ // Asserts that create request fails since snapshot name provided twice
+ Assertions.assertEquals(1, res);
+ }
- 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();
- }
+ /**
+ * Create snapshot should succeed.
+ * 1st case: valid snapshot name
+ * 2nd case: snapshot name length is less than 64 chars
+ */
+ @ParameterizedTest
+ @ValueSource(strings = {"snap-1",
+ "snap75795657617173401188448010125899089001363595171500499231286"})
+ public void testCreateSnapshotSuccess(String snapshotName)
+ throws Exception {
+ int res = ToolRunner.run(shell,
+ new String[]{"-createSnapshot", bucketPath, snapshotName});
+ // Asserts that create request succeeded
+ Assertions.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.
+ Assertions.assertNotNull(snapshotInfo);
}
- @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";
+ /**
+ * Create snapshot should fail.
+ * 1st case: snapshot name contains invalid char
+ * 2nd case: snapshot name consists only of numbers
+ * 3rd case: bucket path is invalid
+ * 4th case: snapshot name length is more than 64 chars
+ */
+ @ParameterizedTest
+ @ValueSource(strings = {"snapa?b", "1234",
+ "snap156808943643007724443266605711479126926050896107709081166294"})
+ public void testCreateSnapshotFailure(String snapshotName)
+ throws Exception {
+
+ int res = ToolRunner.run(shell,
+ new String[]{"-createSnapshot", bucketPath, snapshotName});
+ // Asserts that create request failed
+ Assertions.assertEquals(1, res);
+ }
- String testVolBucket = OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket;
- String testKey = testVolBucket + OM_KEY_PREFIX + key;
+ @Test
+ public void testCreateSnapshotParameterMissing() throws Exception {
Review Comment:
I can't group it with the rest because it expects `-1` as the result integer
instead of `1`. It actually tests `createSnapshot` without any parameters,
since a snapshot without a name can be created.
--
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]