Skip to content

Conversation

@chiacyu
Copy link
Contributor

@chiacyu chiacyu commented Mar 8, 2025

What changes were proposed in this pull request?

Several callers of TestDataUtil#createKey just want to write some data, without any interest in the content being written. The goal of this task is to create a variant of the method which generates some small random byte[] content instead of accepting it via parameter. To let the caller verify data (e.g. via readKey), this variant of createKey should return the random content it generated. Please take a look, thanks!

What is the link to the Apache JIRA

HDDS-12476

How was this patch tested?

Tested by CI.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chiacyu for the patch.

Comment on lines 108 to 111
public static byte[] createKey(OzoneBucket bucket,
String keyName, int length) throws IOException {
byte[] content = RandomStringUtils.random(length, 0, 0,
true, true, null, new SecureRandom()).getBytes(UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's clarify that this method generates string content by renaming to createStringKey.
  • Please avoid new SecureRandom() or new Random() for single use. Replace with RandomStringUtils.secure().nextAlphanumeric(length).getBytes(UTF_8).
  • nit: Please do not format method signature like this. Whenever visibility / return type / method name / other modifiers are changed, we would have to reindent all parameters.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chiacyu for updating the patch.

@adoroszlai adoroszlai merged commit 2315927 into apache:master Mar 8, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants