hemantk-12 commented on code in PR #5924:
URL: https://github.com/apache/ozone/pull/5924#discussion_r1443138391
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java:
##########
@@ -257,41 +258,70 @@ void testCreateSnapshotFailure(String description,
/**
* Test list snapshot and snapshot keys with "ozone fs -ls".
+ * It also verifies that list .snapshot only lists active snapshots.
*/
@Test
void testFsLsSnapshot(@TempDir Path tempDir) throws Exception {
- String newKey = "key-" + RandomStringUtils.randomNumeric(5);
- String newKeyPath = BUCKET_PATH + OM_KEY_PREFIX + newKey;
-
+ String key1 = "key-" + RandomStringUtils.randomNumeric(5);
+ String newKeyPath = BUCKET_PATH + OM_KEY_PREFIX + key1;
+ // Pause SnapshotDeletingService so that Snapshot marked deleted is not
reclaimed.
+ ozoneManager.getKeyManager().getSnapshotDeletingService().suspend();
// Write a non-zero byte key.
Path tempFile = tempDir.resolve("testFsLsSnapshot-any-suffix");
FileUtils.write(tempFile.toFile(), "random data", UTF_8);
- execShellCommandAndGetOutput(0,
- new String[]{"-put", tempFile.toString(), newKeyPath});
- Files.deleteIfExists(tempFile);
-
- // Create snapshot
- String snapshotName = createSnapshot();
- // Setup snapshot paths
- String snapshotPath = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
- OM_KEY_PREFIX + snapshotName;
- String snapshotKeyPath = snapshotPath + OM_KEY_PREFIX + newKey;
-
- // Check for snapshot with "ozone fs -ls"
- String listSnapOut = execShellCommandAndGetOutput(0,
- new String[]{"-ls", BUCKET_WITH_SNAPSHOT_INDICATOR_PATH});
-
- // Assert that output contains above snapshotName
- Assertions.assertTrue(listSnapOut
- .contains(snapshotPath));
-
- // Check for snapshot keys with "ozone fs -ls"
- String listSnapKeyOut = execShellCommandAndGetOutput(0,
- new String[]{"-ls", snapshotPath});
+ try {
+ execShellCommandAndGetOutput(0,
+ new String[]{"-put", tempFile.toString(), newKeyPath});
+
+ // Create snapshot
+ String snapshotName1 = createSnapshot();
+ // Setup snapshot paths
+ String snapshotPath1 = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
+ OM_KEY_PREFIX + snapshotName1;
+
+ String key2 = "key-" + RandomStringUtils.randomNumeric(5);
+ String newKeyPath2 = BUCKET_PATH + OM_KEY_PREFIX + key2;
+ execShellCommandAndGetOutput(0,
+ new String[]{"-put", tempFile.toString(), newKeyPath2});
+ String snapshotName2 = createSnapshot();
+ String snapshotPath2 = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
+ OM_KEY_PREFIX + snapshotName2;
+ String snapshotKeyPath2 = snapshotPath2 + OM_KEY_PREFIX + key2;
+
+ int res = ToolRunner.run(shell,
+ new String[]{"-deleteSnapshot", BUCKET_PATH, snapshotName1});
+ // Asserts that delete request succeeded
+ Assertions.assertEquals(0, res);
- // Assert that output contains the snapshot key
- Assertions.assertTrue(listSnapKeyOut
- .contains(snapshotKeyPath));
+ // Wait for the snapshot to be marked deleted.
+ SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
Review Comment:
I copied it from other place. Fixed it.
Thanks for catching it.
--
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]