Skip to content

Commit a1054a0

Browse files
committed
HDDS-12476. Add TestDataUtil#createKey variant with small random content
1 parent d95ca4c commit a1054a0

File tree

7 files changed

+27
-37
lines changed

7 files changed

+27
-37
lines changed

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,9 @@ public void testListKeysWithNotNormalizedPath() throws Exception {
352352
keys.add(OmUtils.normalizeKey(key2, false));
353353
keys.add(OmUtils.normalizeKey(key3, false));
354354

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);
355+
createAndAssertKey(ozoneBucket, key1, 10);
356+
createAndAssertKey(ozoneBucket, key2, 10);
357+
createAndAssertKey(ozoneBucket, key3, 10);
362358

363359
// Iterator with key name as prefix.
364360

@@ -403,10 +399,10 @@ private void checkKeyList(Iterator<? extends OzoneKey > ozoneKeyIterator,
403399
assertEquals(keys, outputKeys);
404400
}
405401

406-
private void createAndAssertKey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
402+
private void createAndAssertKey(OzoneBucket ozoneBucket, String key, int length)
407403
throws Exception {
408404

409-
createKey(ozoneBucket, key, input);
405+
byte[] input = createKey(ozoneBucket, key, length);
410406
// Read the key with given key name.
411407
readKey(ozoneBucket, key, length, input);
412408

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

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.IOException;
2626
import java.io.InputStream;
2727
import java.io.OutputStream;
28+
import java.security.SecureRandom;
2829
import java.util.ArrayList;
2930
import java.util.HashMap;
3031
import java.util.List;
@@ -104,6 +105,14 @@ public static OzoneVolume createVolume(OzoneClient client,
104105

105106
}
106107

108+
public static byte[] createKey(OzoneBucket bucket,
109+
String keyName, int length) throws IOException{
110+
byte[] content = RandomStringUtils.random(length, 0, 0
111+
, true, true, null, new SecureRandom()).getBytes(UTF_8);
112+
createKey(bucket, keyName, content);
113+
return content;
114+
}
115+
107116
public static void createKey(OzoneBucket bucket, String keyName,
108117
byte[] content) throws IOException {
109118
createKey(bucket, keyName, null, content);

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,10 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
371371

372372
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
373373
throws Exception {
374-
int length = 10;
375-
byte[] input = new byte[length];
376-
Arrays.fill(input, (byte) 96);
377374
for (String key : keys) {
378-
createKey(ozoneBucket, key, input);
375+
byte[] input = createKey(ozoneBucket, key, 10);
379376
// Read the key with given key name.
380-
readkey(ozoneBucket, key, length, input);
377+
readkey(ozoneBucket, key, 10, input);
381378
}
382379
}
383380

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.nio.charset.StandardCharsets;
2626
import java.util.ArrayList;
27-
import java.util.Arrays;
2827
import java.util.Iterator;
2928
import java.util.LinkedList;
3029
import java.util.List;
@@ -643,13 +642,10 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
643642

644643
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
645644
throws Exception {
646-
int length = 10;
647-
byte[] input = new byte[length];
648-
Arrays.fill(input, (byte) 96);
649645
for (String key : keys) {
650-
createKey(ozoneBucket, key, input);
646+
byte[] input = createKey(ozoneBucket, key, 10);
651647
// Read the key with given key name.
652-
readkey(ozoneBucket, key, length, input);
648+
readkey(ozoneBucket, key, 10, input);
653649
}
654650
}
655651

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,10 @@ private void checkKeyList(Iterator<? extends OzoneKey > ozoneKeyIterator,
559559
private void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
560560
throws Exception {
561561

562-
int length = 10;
563-
byte[] input = new byte[length];
564-
Arrays.fill(input, (byte) 96);
565-
566562
for (String key : keys) {
567-
createKey(ozoneBucket, key, input);
563+
byte[] input = createKey(ozoneBucket, key, 10);
568564
// Read the key with given key name.
569-
readKey(ozoneBucket, key, length, input);
565+
readKey(ozoneBucket, key, 10, input);
570566
}
571567
}
572568

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,11 @@ private void setKeyAcl(ObjectStore objectStore, String volumeName,
329329

330330
private void createKeys(ObjectStore objectStore, OzoneBucket ozoneBucket,
331331
List<String> keys) throws Exception {
332-
int length = 10;
332+
333333
String aclWorldAll = "world::a";
334-
byte[] input = new byte[length];
335-
Arrays.fill(input, (byte) 96);
334+
336335
for (String key : keys) {
337-
createKey(ozoneBucket, key, input);
336+
createKey(ozoneBucket, key, 10);
338337
setKeyAcl(objectStore, ozoneBucket.getVolumeName(), ozoneBucket.getName(),
339338
key, aclWorldAll);
340339
}

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.createKey(ozoneBucket, key, length);
364361
// Read the key with given key name.
365362
readkey(ozoneBucket, key, length, input);
366363
}

0 commit comments

Comments
 (0)