Skip to content

HDDS-12884.unit tests for Ozone reconciler #8320

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

Conversation

babluraul
Copy link

@babluraul babluraul commented Apr 22, 2025

-Added unit test for
ContainerChecksumTreeManager,
ReconcileContainerEventHandler

What is the link to the Apache JIRA

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

@jojochuang
Copy link
Contributor

@babluraul please add jira id and update the PR description according to the template, thanks!

@babluraul
Copy link
Author

@babluraul please add jira id and update the PR description according to the template, thanks!

@jojochuang I've added the JIRA ID and updated the PR description according to the template. Let me know if there's anything else needed. Thanks!

@babluraul babluraul changed the title added test case HDDS-12884.unit tests for Ozone reconciler Apr 22, 2025
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few style issues.

As Ethan mentioned in the jira, please update the jira summary to make it more descriptive.

@Test
void testGetContainerChecksumInfoSuccess() throws IOException {
String content = "mock-checksum";
Files.write(checksumFile.toPath(), content.getBytes());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not write dummy content to the class object i.e container or checksumFile as it may break the other test

Files.write(checksumFile.toPath(), "dummy content".getBytes());

Container mockContainer = mock(Container.class);
when(mockContainer.getContainerData()).thenReturn(container);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we returning container instead of mockContainer?

Copy link
Author

Choose a reason for hiding this comment

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

in the implemention
public KeyValueContainerData getContainerData() {
return containerData;
}
its returning a KeyValueContainerData type
so in my case container which i return is KeyValueContainer type

void testChecksumFileExistFalse() {

Container mockContainer = mock(Container.class);
when(mockContainer.getContainerData()).thenReturn(container);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we returning container instead of mockContainer?

Copy link
Author

Choose a reason for hiding this comment

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

When the getContainerData() method of the mockContainer is called, it returns the real container object


@Test
void testChecksumFileExistTrue() throws IOException {
Files.write(checksumFile.toPath(), "dummy content".getBytes());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not update the content of class object

Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be creating checksumFile manually

public void testReconcileFailsWithNotEligibleReplicas() throws Exception {
addContainer(RATIS_THREE_REP, LifeCycleState.CLOSED);

addReplicasToContainer(State.CLOSED, State.DELETED, State.DELETED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we parametrize this with other states as well

Copy link
Author

Choose a reason for hiding this comment

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

The current test is already a duplicate, so adding more states likely won’t add coverage. I’ll go ahead and remove it


@Test
public void testReconcileFailsDueToInvalidContainerState() throws Exception {
addContainer(RATIS_THREE_REP, LifeCycleState.DELETING);
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate test

Copy link
Author

Choose a reason for hiding this comment

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

The current test is already a duplicate, so adding more states likely won’t add coverage. I’ll go ahead and remove it

}

@Test
public void testScmNotLeader() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the Test name

Copy link
Author

Choose a reason for hiding this comment

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

i will update

@adoroszlai adoroszlai mentioned this pull request Apr 25, 2025
@babluraul
Copy link
Author

closing since most of the changes are duplicates

@babluraul babluraul closed this Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants