Skip to content

Commit 2315927

Browse files
authored
HDDS-12476. Add TestDataUtil#createKey variant with small random content (apache#8028)
1 parent d95ca4c commit 2315927

File tree

7 files changed

+26
-41
lines changed

7 files changed

+26
-41
lines changed

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFSWithObjectStoreCreate.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.apache.hadoop.ozone.OzoneConsts.ETAG;
2222
import static org.apache.hadoop.ozone.OzoneConsts.MD5_HASH;
2323
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
24-
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
2524
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_A_FILE;
2625
import static org.assertj.core.api.Assertions.assertThat;
2726
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -352,13 +351,9 @@ public void testListKeysWithNotNormalizedPath() throws Exception {
352351
keys.add(OmUtils.normalizeKey(key2, false));
353352
keys.add(OmUtils.normalizeKey(key3, false));
354353

355-
int length = 10;
356-
byte[] input = new byte[length];
357-
Arrays.fill(input, (byte)96);
358-
359-
createAndAssertKey(ozoneBucket, key1, 10, input);
360-
createAndAssertKey(ozoneBucket, key2, 10, input);
361-
createAndAssertKey(ozoneBucket, key3, 10, input);
354+
createAndAssertKey(ozoneBucket, key1, 10);
355+
createAndAssertKey(ozoneBucket, key2, 10);
356+
createAndAssertKey(ozoneBucket, key3, 10);
362357

363358
// Iterator with key name as prefix.
364359

@@ -403,10 +398,10 @@ private void checkKeyList(Iterator<? extends OzoneKey > ozoneKeyIterator,
403398
assertEquals(keys, outputKeys);
404399
}
405400

406-
private void createAndAssertKey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
401+
private void createAndAssertKey(OzoneBucket ozoneBucket, String key, int length)
407402
throws Exception {
408403

409-
createKey(ozoneBucket, key, input);
404+
byte[] input = TestDataUtil.createStringKey(ozoneBucket, key, length);
410405
// Read the key with given key name.
411406
readKey(ozoneBucket, key, length, input);
412407

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestDataUtil.java

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ public static OzoneVolume createVolume(OzoneClient client,
104104

105105
}
106106

107+
public static byte[] createStringKey(OzoneBucket bucket, String keyName, int length)
108+
throws IOException {
109+
byte[] content = RandomStringUtils.secure().nextAlphanumeric(length).getBytes(UTF_8);
110+
createKey(bucket, keyName, content);
111+
return content;
112+
}
113+
107114
public static void createKey(OzoneBucket bucket, String keyName,
108115
byte[] content) throws IOException {
109116
createKey(bucket, keyName, null, content);

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeys.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.common.collect.Lists.newLinkedList;
2121
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE;
2222
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
23-
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
2423
import static org.junit.jupiter.api.Assertions.assertEquals;
2524
import static org.junit.jupiter.params.provider.Arguments.of;
2625

@@ -371,13 +370,10 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
371370

372371
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
373372
throws Exception {
374-
int length = 10;
375-
byte[] input = new byte[length];
376-
Arrays.fill(input, (byte) 96);
377373
for (String key : keys) {
378-
createKey(ozoneBucket, key, input);
374+
byte[] input = TestDataUtil.createStringKey(ozoneBucket, key, 10);
379375
// Read the key with given key name.
380-
readkey(ozoneBucket, key, length, input);
376+
readkey(ozoneBucket, key, 10, input);
381377
}
382378
}
383379

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestListKeysWithFSO.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919

2020
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE;
2121
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
22-
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
2322
import static org.junit.jupiter.api.Assertions.assertEquals;
2423

2524
import java.nio.charset.StandardCharsets;
2625
import java.util.ArrayList;
27-
import java.util.Arrays;
2826
import java.util.Iterator;
2927
import java.util.LinkedList;
3028
import java.util.List;
@@ -643,13 +641,10 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
643641

644642
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
645643
throws Exception {
646-
int length = 10;
647-
byte[] input = new byte[length];
648-
Arrays.fill(input, (byte) 96);
649644
for (String key : keys) {
650-
createKey(ozoneBucket, key, input);
645+
byte[] input = TestDataUtil.createStringKey(ozoneBucket, key, 10);
651646
// Read the key with given key name.
652-
readkey(ozoneBucket, key, length, input);
647+
readkey(ozoneBucket, key, 10, input);
653648
}
654649
}
655650

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
2323
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
2424
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
25-
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
2625
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_ALREADY_EXISTS;
2726
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
2827
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -559,14 +558,10 @@ private void checkKeyList(Iterator<? extends OzoneKey > ozoneKeyIterator,
559558
private void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
560559
throws Exception {
561560

562-
int length = 10;
563-
byte[] input = new byte[length];
564-
Arrays.fill(input, (byte) 96);
565-
566561
for (String key : keys) {
567-
createKey(ozoneBucket, key, input);
562+
byte[] input = TestDataUtil.createStringKey(ozoneBucket, key, 10);
568563
// Read the key with given key name.
569-
readKey(ozoneBucket, key, length, input);
564+
readKey(ozoneBucket, key, 10, input);
570565
}
571566
}
572567

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestRecursiveAclWithFSO.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.commons.lang3.RandomStringUtils;
3434
import org.apache.hadoop.hdds.protocol.StorageType;
3535
import org.apache.hadoop.ozone.OzoneAcl;
36+
import org.apache.hadoop.ozone.TestDataUtil;
3637
import org.apache.hadoop.ozone.client.BucketArgs;
3738
import org.apache.hadoop.ozone.client.ObjectStore;
3839
import org.apache.hadoop.ozone.client.OzoneBucket;
@@ -329,12 +330,11 @@ private void setKeyAcl(ObjectStore objectStore, String volumeName,
329330

330331
private void createKeys(ObjectStore objectStore, OzoneBucket ozoneBucket,
331332
List<String> keys) throws Exception {
332-
int length = 10;
333+
333334
String aclWorldAll = "world::a";
334-
byte[] input = new byte[length];
335-
Arrays.fill(input, (byte) 96);
335+
336336
for (String key : keys) {
337-
createKey(ozoneBucket, key, input);
337+
TestDataUtil.createStringKey(ozoneBucket, key, 10);
338338
setKeyAcl(objectStore, ozoneBucket.getVolumeName(), ozoneBucket.getName(),
339339
key, aclWorldAll);
340340
}

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOmSnapshotFileSystem.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,15 @@ private void checkKeyList(Iterator<? extends OzoneKey> ozoneKeyIterator,
349349

350350
private void createKeys(OzoneBucket ozoneBucket, List<String> keys)
351351
throws Exception {
352-
int length = 10;
353-
byte[] input = new byte[length];
354-
Arrays.fill(input, (byte) 96);
355352
for (String key : keys) {
356-
createKey(ozoneBucket, key, 10, input);
353+
createKey(ozoneBucket, key, 10);
357354
}
358355
}
359356

360-
private void createKey(OzoneBucket ozoneBucket, String key, int length,
361-
byte[] input) throws Exception {
357+
private void createKey(OzoneBucket ozoneBucket, String key, int length)
358+
throws Exception {
362359

363-
TestDataUtil.createKey(ozoneBucket, key, input);
360+
byte[] input = TestDataUtil.createStringKey(ozoneBucket, key, length);
364361
// Read the key with given key name.
365362
readkey(ozoneBucket, key, length, input);
366363
}

0 commit comments

Comments
 (0)