KAFKA-16000 Migrated MembershipManagerImplTest away from ConsumerTestBuilder#16312
KAFKA-16000 Migrated MembershipManagerImplTest away from ConsumerTestBuilder#16312mjsax merged 87 commits intoapache:trunkfrom
Conversation
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
|
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
does changing backgroundEventHandler to a mock break a lot of tests?
There was a problem hiding this comment.
Yeah, breaks 16/81, all test failures are on asserting an empty queue or number of events in the queue
lianetm
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
For my own education: why move this here and not keep logContext as final?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@mjsax thank you for the feedback! I made a small change with |
|
All test failures are unrelated to the changes made in this PR |
|
Thanks for the PR @brenden20. Merged to |
…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>
I completely migrated MembershipManagerImplTest away from ConsumerTestBuilder and removed all spy objects. All tests passing, none were removed.