You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by si...@apache.org on 2022/10/29 01:06:29 UTC
[ozone] branch HDDS-6517-Snapshot updated: HDDS-7427. [Snapshot] Add unit-testcases for Ozone snapshot feature. (#3896)
This is an automated email from the ASF dual-hosted git repository.
siyao 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 9538954e4b HDDS-7427. [Snapshot] Add unit-testcases for Ozone snapshot feature. (#3896)
9538954e4b is described below
commit 9538954e4b06c531862ad18fe4076dfe8b40affc
Author: jyotirmoy-gh <69...@users.noreply.github.com>
AuthorDate: Sat Oct 29 06:36:22 2022 +0530
HDDS-7427. [Snapshot] Add unit-testcases for Ozone snapshot feature. (#3896)
---
.../org/apache/hadoop/ozone/om/TestOmSnapshot.java | 143 +++++++++++++--------
1 file changed, 92 insertions(+), 51 deletions(-)
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java
index 3f5b49ed99..b7ce4a8c3b 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java
@@ -190,31 +190,10 @@ public class TestOmSnapshot {
*/
String keyBaseA = "key-a-";
for (int i = 0; i < 10; i++) {
- byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
- OzoneOutputStream one = volAbucketA.createKey(
- keyBaseA + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- one.write(value);
- one.close();
- OzoneOutputStream two = volAbucketB.createKey(
- keyBaseA + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- two.write(value);
- two.close();
- OzoneOutputStream three = volBbucketA.createKey(
- keyBaseA + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- three.write(value);
- three.close();
- OzoneOutputStream four = volBbucketB.createKey(
- keyBaseA + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- four.write(value);
- four.close();
+ createFileKey(volAbucketA, keyBaseA + i + "-");
+ createFileKey(volAbucketB, keyBaseA + i + "-");
+ createFileKey(volBbucketA, keyBaseA + i + "-");
+ createFileKey(volBbucketB, keyBaseA + i + "-");
}
/*
Create 10 keys in vol-a-<random>/buc-a-<random>,
@@ -223,34 +202,12 @@ public class TestOmSnapshot {
*/
String keyBaseB = "key-b-";
for (int i = 0; i < 10; i++) {
- byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
- OzoneOutputStream one = volAbucketA.createKey(
- keyBaseB + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- one.write(value);
- one.close();
- OzoneOutputStream two = volAbucketB.createKey(
- keyBaseB + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- two.write(value);
- two.close();
- OzoneOutputStream three = volBbucketA.createKey(
- keyBaseB + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- three.write(value);
- three.close();
- OzoneOutputStream four = volBbucketB.createKey(
- keyBaseB + i + "-" + RandomStringUtils.randomNumeric(5),
- value.length, RATIS, ONE,
- new HashMap<>());
- four.write(value);
- four.close();
+ createFileKey(volAbucketA, keyBaseB + i + "-");
+ createFileKey(volAbucketB, keyBaseB + i + "-");
+ createFileKey(volBbucketA, keyBaseB + i + "-");
+ createFileKey(volBbucketB, keyBaseB + i + "-");
}
-
String snapshotKeyPrefix = createSnapshot(volumeA, bucketA);
Iterator<? extends OzoneKey> volABucketAIter =
volAbucketA.listKeys(snapshotKeyPrefix + "key-");
@@ -383,6 +340,78 @@ public class TestOmSnapshot {
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-";
+ createFileKey(volbucket, key);
+ String snapshotKeyPrefix = createSnapshot(volume, bucket);
+ deleteKeys(volbucket);
+
+ Iterator<? extends OzoneKey> volBucketIter =
+ volbucket.listKeys(snapshotKeyPrefix + "key-");
+ int volBucketKeyCount = 0;
+ while (volBucketIter.hasNext()) {
+ volBucketIter.next();
+ volBucketKeyCount++;
+ }
+ Assert.assertEquals(1, volBucketKeyCount);
+
+ snapshotKeyPrefix = createSnapshot(volume, bucket);
+ Iterator<? extends OzoneKey> volBucketIter2 =
+ volbucket.listKeys(snapshotKeyPrefix);
+ while (volBucketIter2.hasNext()) {
+ fail("The last snapshot should not have any keys in it!");
+ }
+ }
+
+ @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 key1 = "key-1-";
+ createFileKey(volbucket, key1);
+ String snapshotKeyPrefix1 = createSnapshot(volume, bucket);
+
+ String key2 = "key-2-";
+ createFileKey(volbucket, key2);
+ String snapshotKeyPrefix2 = createSnapshot(volume, bucket);
+
+ Iterator<? extends OzoneKey> volBucketIter =
+ volbucket.listKeys(snapshotKeyPrefix1 + "key-");
+ int volBucketKeyCount = 0;
+ while (volBucketIter.hasNext()) {
+ volBucketIter.next();
+ volBucketKeyCount++;
+ }
+ Assert.assertEquals(1, volBucketKeyCount);
+
+ Iterator<? extends OzoneKey> volBucketIter2 =
+ volbucket.listKeys(snapshotKeyPrefix2 + "key-");
+ int volBucketKeyCount2 = 0;
+ while (volBucketIter2.hasNext()) {
+ volBucketIter2.next();
+ volBucketKeyCount2++;
+ }
+ Assert.assertEquals(2, volBucketKeyCount2);
+
+ deleteKeys(volbucket);
+
+ }
+
private String createSnapshot()
throws IOException, InterruptedException, TimeoutException {
return createSnapshot(volumeName, bucketName);
@@ -416,5 +445,17 @@ public class TestOmSnapshot {
bucket.deleteKey(key.getName());
}
}
+
+ private void createFileKey(OzoneBucket bucket, String keyprefix)
+ throws IOException {
+ byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
+ OzoneOutputStream fileKey = bucket.createKey(
+ keyprefix + RandomStringUtils.randomNumeric(5),
+ value.length, RATIS, ONE,
+ new HashMap<>());
+ fileKey.write(value);
+ fileKey.close();
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org