-
Notifications
You must be signed in to change notification settings - Fork 620
HDDS-10151. Replace single-use Random objects with RandomUtils in test classes #6041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bb5383c
a7d4b06
7e0c326
4a4cc7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Random; | ||
| import org.apache.commons.lang3.RandomUtils; | ||
| import java.util.zip.Checksum; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
@@ -59,11 +59,10 @@ void testCorrectness() { | |
|
|
||
| checkBytes("hello world!".getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| final Random random = new Random(); | ||
| final byte[] bytes = new byte[1 << 10]; | ||
| for (int i = 0; i < 1000; i++) { | ||
| random.nextBytes(bytes); | ||
| checkBytes(bytes, random.nextInt(bytes.length)); | ||
| RandomUtils.nextBytes(bytes.length); | ||
| checkBytes(bytes, RandomUtils.nextInt(0, bytes.length)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since this results in a new array in each iteration, we can remove the original final int len = 1 << 10;
for (int i = 0; i < 1000; i++) {
checkBytes(RandomUtils.nextBytes(len), RandomUtils.nextInt(0, len));
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion, it is corrected. |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please try to keep alphabetical order, move to:
ozone/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockReconstructedStripeInputStream.java
Lines 20 to 21 in a7d4b06
(the same minor issue applies to some of the other files)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.