Skip to content

KAFKA-16000 Migrated MembershipManagerImplTest away from ConsumerTestBuilder#16312

Merged
mjsax merged 87 commits intoapache:trunkfrom
brenden20:16000
Jun 28, 2024
Merged

KAFKA-16000 Migrated MembershipManagerImplTest away from ConsumerTestBuilder#16312
mjsax merged 87 commits intoapache:trunkfrom
brenden20:16000

Conversation

@brenden20
Copy link
Copy Markdown
Contributor

I completely migrated MembershipManagerImplTest away from ConsumerTestBuilder and removed all spy objects. All tests passing, none were removed.

brenden20 added 30 commits June 4, 2024 16:02
Updated mockStableMember()
Added a few stubs to make this method work
Removed verifyReconciliationNotTriggered(). My thinking here is that this method requires membershipManager to be a mock or spy, but we need to test with a real object
Similar to last commit, removed all instances of clearInvocations(membershipManager) and edited verifyReconciliationTriggered() to remove some calls to a non mock
Again removing methods/test where it is expecting a mock of MembershipManager
Added a bunch of stubbing
Created method createCoordinatorRequestManager(). It changes the commitRequestManager variable from a mock to an actual object, which needs to be done for many of the tests
Updated tests by commenting out some lines in methods and editing private methods
Updated tests to perform unit testing instead of integration testing
A few of the tests did not work without instantiated backgroundEventQueue and handler
…gnment()

Updated testMemberJoiningCallsRebalanceListenerWhenReceivingEmptyAssignment() to work properly, it is an integration test
Updated testOnPartitionsLost() to work properly, again integration testing
Updated testReconciliationSkippedWhenSameAssignmentReceived()
Updated createCommitRequestManager() to enable autoCommit on the commitRequestManager.

Also updated testAddedPartitionsNotEnabledAfterFailedOnPartitionsAssignedCallback() to work
Added a line to create commitRequestManager
@brenden20
Copy link
Copy Markdown
Contributor Author

Thank you for the feedback @lianetm, I just made all the suggested improvements!


assertEquals(MemberState.STALE, membershipManager.state());
verify(backgroundEventHandler).add(any(ConsumerRebalanceListenerCallbackNeededEvent.class));
assertFalse(backgroundEventQueue.isEmpty());
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.

the original implementation was better, any reason for changing that? verify(backgroundEventHandler).add(any(ConsumerRebalanceListenerCallbackNeededEvent.class));

it was better because backgroundEventQueue is in the implementation. we just need to make sure the event was added to the handler.

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.

Since backgroundEventHandler is an actual instance of an object, we cannot verify() on it. So in order to still test what it was trying to test, the two assert statements must be there instead

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.

does changing backgroundEventHandler to a mock break a lot of tests?

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.

Yeah, breaks 16/81, all test failures are on asserting an empty queue or number of events in the queue

Copy link
Copy Markdown
Member

@lianetm lianetm 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 great improvement and all the updates @brenden20 ! Let's make sure @philipnee 's concerns are clarified but this LGTM. Thanks!

commitRequestManager = mock(CommitRequestManager.class);
backgroundEventQueue = new LinkedBlockingQueue<>();
backgroundEventHandler = new BackgroundEventHandler(backgroundEventQueue);
logContext = new LogContext();
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.

For my own education: why move this here and not keep logContext as final?

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.

It was mostly to keep consistency with variables being private/private and final. Although I did not consider that I could make it private static final and it would still work without issue and keep the variables consistent. I am going to make that change now.

// Member should update the subscription and send ack when the delayed reconciliation
// completes.
verify(subscriptionState).assignFromSubscribed(Collections.emptySet());
verify(subscriptionState).assignFromSubscribedAwaitingCallback(Collections.emptySet(), Collections.emptySet());
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 we verify something else here? This PR only updates test code, so where does this change in behavior come from? Seems I am missing something.

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.

assignFromSubscribed() is called from assignFromSubscribedAwaitingCallback(). Since subscriptionState was changed from a spy to a mock, we could not test for this behavior. So instead I changed the verify to be the calling function assignFromSubscribedAwaitingCallback() and the correct, expected parameters. If assignFromSubscribedAwaitingCallback() is getting the correct parameters, then it should implicitly verify that assignFromSubscribed() is being called with the correct parameter.

@brenden20
Copy link
Copy Markdown
Contributor Author

@mjsax thank you for the feedback! I made a small change with logContext and replied to your other comment. If there is anything else let me know!

@brenden20
Copy link
Copy Markdown
Contributor Author

All test failures are unrelated to the changes made in this PR

@mjsax mjsax merged commit 836f52b into apache:trunk Jun 28, 2024
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Jun 28, 2024

Thanks for the PR @brenden20. Merged to trunk.

@brenden20 brenden20 deleted the 16000 branch June 28, 2024 19:50
abhi-ksolves pushed a commit to ksolves/kafka that referenced this pull request Jul 31, 2024
…tBuilder (apache#16312)

Finishing migration of MembershipManagerImplTest away from ConsumerTestBuilder and removed all spy objects.

Reviewers: Lianet Magrans <lianetmr@gmail.com>, Philip Nee <pnee@confluent.io>, Matthias J. Sax <matthias@confluent.io>
chia7712 pushed a commit that referenced this pull request Aug 5, 2024
The purpose of this PR is to remove ConsumerTestBuilder.java since it is no longer needed. The following PRs have eliminated the use of ConsumerTestBuilder:
#14930
#16140
#16200
#16312

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consumer tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants