Skip to content

KAFKA-14133: Migrate Consumer mock in TaskManagerTest to Mockito#13873

Closed
clolov wants to merge 3 commits intoapache:trunkfrom
clolov:KAFKA-14133-PART10
Closed

KAFKA-14133: Migrate Consumer mock in TaskManagerTest to Mockito#13873
clolov wants to merge 3 commits intoapache:trunkfrom
clolov:KAFKA-14133-PART10

Conversation

@clolov
Copy link
Copy Markdown
Contributor

@clolov clolov commented Jun 19, 2023

This pull requests migrates the Consumer mock in TaskManagerTest from EasyMock to Mockito.
The change is restricted to a single mock to minimize the scope and make it easier for review.

The reasoning as to why we would like to migrate a single mock rather than all mocks in the file at the same time has been discussed in #12607 (comment)

It takes the same approach as in:
#13529
#13621
#13681
#13711

@clolov clolov requested review from cadonna and divijvaidya June 19, 2023 10:38
@divijvaidya divijvaidya added the tests Test fixes (including flaky tests) label Jun 19, 2023
Copy link
Copy Markdown
Member

@divijvaidya divijvaidya left a comment

Choose a reason for hiding this comment

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

I took an initial look but it seems like a lot of verification is missing. Can you please ensure that whenever we remove a easymock stub, we are adding a powermock verification for it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why are we checking for atLeastOnce and not the exact times? Isn't this relaxing constrains from what we were doing with easy mock?

(same for verifyResumeWasCalledWith)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are a couple of tests where consumer.resume() is called twice. I will amend this to be stricter if possible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would inline this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/verifyResumeWasCalledWith /verifyResumeWasCalledWithAssignment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would inline this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

verify this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not called, this is why I removed it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

verify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is just not called, that's why I removed it originally

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

verify

Copy link
Copy Markdown
Contributor Author

@clolov clolov Jun 26, 2023

Choose a reason for hiding this comment

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

I don't think there is a need for verification here. The consumer was only replayed in EasyMock and the replayed behaviour comes by default in Mockito
This is just not called, that's why I removed it originally

Comment on lines 2695 to 2985
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

verify

Copy link
Copy Markdown
Contributor Author

@clolov clolov Jun 23, 2023

Choose a reason for hiding this comment

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

I actually do not know why these were being verified with EasyMock given that taskXY are not mocks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, that seems weird...

Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Hi @clolov ! Thanks for the PR!

I started to review the PR and have the following feedback so far.

Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, @clolov !

Here some more comments.

Comment on lines 4388 to 4664
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would inline this function since it became an one-liner.

when(consumer.assignment()).thenReturn(singleton(new TopicPartition("assignment", 0)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would inline this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would inline this function.

Comment on lines 1925 to 1926
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you union a single set?

Suggested change
final Set<TopicPartition> partitions = union(HashSet::new, taskId00Partitions);
when(consumer.assignment()).thenReturn(partitions);
when(consumer.assignment()).thenReturn(taskId00Partitions);

... and isn't this a duplicate of line 1923 (except the differing partitions).

expectAssignmentToBeCalled(consumer);

Could it be that you can remove line 1923?

Copy link
Copy Markdown
Contributor Author

@clolov clolov Jun 26, 2023

Choose a reason for hiding this comment

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

Because I couldn't figure out a better way to create a set with only one element and Collections does not have a singletonSet 😞

Copy link
Copy Markdown
Contributor Author

@clolov clolov Jun 26, 2023

Choose a reason for hiding this comment

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

Oh, silly me, there is a mkSet method in Utils. Okay, I will remedy this.
Silly me x2, the thing is already a set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are correct, it appears I can remove line 1923

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above also here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you verify? It was not verified in the original code.

I added a couple of this comments below. However, I am not sure whether the original author did not want to verify the consumer or if they forgot about it. I will leave it to you if you want to keep them or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you verify? It was not verified in the original code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you verify? It was not verified in the original code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you verify? It was not verified in the original code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Mockito.verifyNoMoreInteractions(consumer);
Mockito.verifyNoInteractions(consumer);

@clolov clolov force-pushed the KAFKA-14133-PART10 branch from 2a5ccfd to 349a9d0 Compare June 26, 2023 13:53
@clolov clolov requested review from cadonna and divijvaidya June 27, 2023 13:00
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 9, 2023

This PR is being marked as stale since it has not had any activity in 90 days. If you would like to keep this PR alive, please ask a committer for review. If the PR has merge conflicts, please update it with the latest from trunk (or appropriate release branch)

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added stale Stale PRs and removed stale Stale PRs labels Oct 9, 2023
@clolov
Copy link
Copy Markdown
Contributor Author

clolov commented Oct 19, 2023

I will provide an update on this pull request in order to not close it!

@clolov clolov force-pushed the KAFKA-14133-PART10 branch from 910effb to 7c917f0 Compare October 19, 2023 09:20
@mimaison
Copy link
Copy Markdown
Member

Can this be closed now? It looks like this has been done in a33c47e / 8b72a2c

@cadonna
Copy link
Copy Markdown
Member

cadonna commented Jun 10, 2024

Yes

@cadonna cadonna closed this Jun 10, 2024
@clolov clolov deleted the KAFKA-14133-PART10 branch February 3, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants