sadanand48 commented on code in PR #3896:
URL: https://github.com/apache/ozone/pull/3896#discussion_r1006563012


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -383,6 +383,98 @@ public void checkKey() throws Exception {
         snapshotKeyPrefix + key1);
   }
 
+  @Test
+  public void testListDeleteKey()
+          throws IOException, InterruptedException, TimeoutException {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    store.createVolume(volume);
+    OzoneVolume vol = store.getVolume(volume);
+    vol.createBucket(bucket);
+    OzoneBucket volbucket = vol.getBucket(bucket);
+
+    String key = "key-";
+    byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
+    OzoneOutputStream oneKey = volbucket.createKey(
+            key + RandomStringUtils.randomNumeric(5),
+            value.length, RATIS, ONE,
+            new HashMap<>());
+    oneKey.write(value);
+    oneKey.close();
+
+    String snapshotKeyPrefix = createSnapshot(volume, bucket);
+    Iterator<? extends OzoneKey> volBucketIter =
+            volbucket.listKeys(snapshotKeyPrefix + "key-");
+    int volBucketKeyCount = 0;
+    while (volBucketIter.hasNext()) {
+      volBucketIter.next();
+      volBucketKeyCount++;
+    }
+    Assert.assertEquals(1, volBucketKeyCount);
+
+    deleteKeys(volbucket);
+
+    snapshotKeyPrefix = createSnapshot(volume, bucket);
+    Iterator<? extends OzoneKey> volBucketIter2 =
+            volbucket.listKeys(snapshotKeyPrefix);
+    while (volBucketIter2.hasNext()) {
+      fail();
+    }
+  }
+
+  @Test
+  public void testListAddNewKey()
+          throws IOException, InterruptedException, TimeoutException {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    store.createVolume(volume);
+    OzoneVolume vol = store.getVolume(volume);
+    vol.createBucket(bucket);
+    OzoneBucket volbucket = vol.getBucket(bucket);
+
+    String key = "key-";
+    byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
+    OzoneOutputStream oneKey = volbucket.createKey(

Review Comment:
   There are many occurrences of this code to create and write to a key, we can 
maybe create a method for this to reduce duplicates.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -383,6 +383,98 @@ public void checkKey() throws Exception {
         snapshotKeyPrefix + key1);
   }
 
+  @Test
+  public void testListDeleteKey()
+          throws IOException, InterruptedException, TimeoutException {
+    String volume = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket = "buc-" + RandomStringUtils.randomNumeric(5);
+    store.createVolume(volume);
+    OzoneVolume vol = store.getVolume(volume);
+    vol.createBucket(bucket);
+    OzoneBucket volbucket = vol.getBucket(bucket);
+
+    String key = "key-";
+    byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
+    OzoneOutputStream oneKey = volbucket.createKey(
+            key + RandomStringUtils.randomNumeric(5),
+            value.length, RATIS, ONE,
+            new HashMap<>());
+    oneKey.write(value);
+    oneKey.close();
+
+    String snapshotKeyPrefix = createSnapshot(volume, bucket);
+    Iterator<? extends OzoneKey> volBucketIter =
+            volbucket.listKeys(snapshotKeyPrefix + "key-");
+    int volBucketKeyCount = 0;
+    while (volBucketIter.hasNext()) {
+      volBucketIter.next();
+      volBucketKeyCount++;
+    }
+    Assert.assertEquals(1, volBucketKeyCount);
+
+    deleteKeys(volbucket);

Review Comment:
   nit : It may be better to delete right after createSnapshot and then verify 
whether the snapshot has count of 1 key. 



-- 
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