Skip to content

HDDS-12807. Clean up TestKeyManagerImpl unit test#10640

Open
echonesis wants to merge 1 commit into
apache:masterfrom
echonesis:HDDS-12807
Open

HDDS-12807. Clean up TestKeyManagerImpl unit test#10640
echonesis wants to merge 1 commit into
apache:masterfrom
echonesis:HDDS-12807

Conversation

@echonesis

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR cleans up TestKeyManagerImpl by replacing the long parameter lists in the parameterized table iterator tests with a small TableIteratorTestCase builder.
The change also separates successful and invalid table iterator cases, so the expected exception path is tested explicitly instead of being mixed into the common assertion flow.

Generated-by: OpenAI Codex (GPT-5)

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-12807

How was this patch tested?

Tested with:

mvn clean test -pl :ozone-manager -am \
  -Dtest=TestKeyManagerImpl \
  -DskipShade -DskipRecon -DskipDocs

GitHub Actions CI: https://github.com/echonesis/ozone/actions/runs/28430712787

@adoroszlai adoroszlai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @echonesis for the patch. Overall LGTM, few minor improvements suggested.

for (int j = 0; j < testCase.getNumberOfBucketsPerVolume(); j++) {
for (int k = 0; k < testCase.getNumberOfKeysPerBucket(); k++) {
String key = getTableKey(volumeNamePrefix, i, bucketNamePrefix, j, keyPrefix, k);
V value = valueClass == String.class ? (V) key : mock(valueClass);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This lets us avoid the need for SuppressWarnings("unchecked"):

Suggested change
V value = valueClass == String.class ? (V) key : mock(valueClass);
V value = valueClass == String.class ? valueClass.cast(key) : mock(valueClass);

throws IOException {
@ParameterizedTest(name = "{0}")
@MethodSource("getSuccessfulTableIteratorParameters")
public void testGetDeletedKeyEntries(TableIteratorTestCase testCase) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Class 'TableIteratorTestCase' is exposed outside its defined visibility scope

Suggested change
public void testGetDeletedKeyEntries(TableIteratorTestCase testCase) throws IOException {
void testGetDeletedKeyEntries(TableIteratorTestCase testCase) throws IOException {

Also applies to other parameterized test methods.

Since JUnit 5, test methods do not need to be public. It's better to keep them package-private for simplicity/brevity regardless of this warning.

String bucketNamePrefix = "bucket";
String keyPrefix = "key";
OzoneConfiguration configuration = new OzoneConfiguration();
OMMetadataManager metadataManager = Mockito.mock(OMMetadataManager.class);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mockito.mock is already imported

Suggested change
OMMetadataManager metadataManager = Mockito.mock(OMMetadataManager.class);
OMMetadataManager metadataManager = mock(OMMetadataManager.class);

Also in few other places.

return Long.parseLong(key.split("/")[3]);
}

private static final class TableIteratorTestCase {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: class can be renamed to TestCase since it's private

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