Skip to content
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

KAFKA-16001: Migrated ConsumerNetworkThreadTest away from ConsumerTestBuilder #16140

Merged
merged 75 commits into from
Jun 13, 2024

Conversation

brenden20
Copy link
Contributor

@brenden20 brenden20 commented May 30, 2024

Completely migrated ConsumerNetworkThreadTest away from ConsumerTestBuilder and removed all usages of spy objects and replaced with mocks. Removed testEnsureMetadataUpdateOnPoll() since it was doing integration testing. Also I added 2 new tests to get more complete test coverage of ConsumerNetworkThread. All tests are passing

brenden20 and others added 27 commits May 24, 2024 12:08
Removed dependencies upon ConsumerTestBuilder
Removed change of toString to toStringBase, moving change to separate branch
Added test for RMs, seeing if pollWaitTimeMs is computed correctly
Cleaning up comments
Added a new param test to ensure ConsumerNetworkThread wait times are being computed correctly.
Removed all redundant/integration tests
Changed variables names in testConsumerNetworkThreadWaitTimeComputations to be more descriptive
Removed vars and methods with no usage
Removed unused imports
Updating comments
Comments
Updated constructor to include correct parameters
Added previously removed tests and changed some imports and edited the constructor
Did some minor updates, changed testMetadataUpdateEvent since it was integration testing
Updated constructor, removed unnecessary variables. Also updated a few tests to make them work or to make them unit tests rather than integration tests
Updated comment on testEnsureMetadataUpdateOnPoll
Remove comment
Added testEnsureCloseStopsRunningThread.

Updated testConsumerNetworkThreadWaitTimeComputations to also test that networkClientDelegate polls with correct times.

Removed one instance of a spy object, replaced with mock.
Cleaning up warnings, changed lambda expressions to explicit method references
Removed tests from this test that seem to be more like integration testing
Removed testEnsureMetadataUpdateOnPoll().

This is an integration test, tried many different ways to still get it to pass but could not. The issue is that for the metadata. updateWithCurrentRequestVersion() method to be invoked, many objects must not be mocks. This causes issues when trying to use verify(), as it can only take a mock, not an actual instantiated object.

I also cleaned up the code a little bit
Changed instantiation of MockClient to not include metadata in constructor
Moved all code from ConsumerNetworkThreadUnitTest to ConsumerNetworkThreadTest and removed ConsumerNetworkThreadUnitTest
Comment removal
Copy link
Collaborator

@kirktrue kirktrue left a comment

Choose a reason for hiding this comment

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

Thanks @brenden20. This is a welcome change and I only have minor nits at this point.

@kirktrue
Copy link
Collaborator

Looks like there are some checkstyle failures due to the use of wildcard imports.

Copy link
Collaborator

@kirktrue kirktrue left a comment

Choose a reason for hiding this comment

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

Left some suggestions as to the checkstyle issues.

You should be able to run this command locally to verify the checkstyle rules pass:

./gradlew check -x test

@brenden20
Copy link
Contributor Author

@lianetm implemented your suggestions on the description and testConsumerNetworkThreadPollTimeComputations(). Let me know how it looks

Updates testConsumerNetworkThreadPollTimeComputations() and fixed a checkstyle error
@brenden20
Copy link
Contributor Author

@lianetm I implemented your new suggestions, let me know if it looks good

Copy link
Contributor

@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 changes @brenden20 , this LGTM.

Really nice how you got rid of the heavy use of unneeded spy objects that the ConsumerTestBuilder was bringing in. Thanks!

Copy link
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

I am not very familiar with the control flow of the consumer, but it seems this PR is doing much more than an "in place" rewrite of the test. Would be good to understand better why so many test methods got removed.

}

@Test
public void testEnsureCloseStopsRunningThread() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this is one of the newly added tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes


@ParameterizedTest
@ValueSource(longs = {ConsumerNetworkThread.MAX_POLL_TIMEOUT_MS - 1, ConsumerNetworkThread.MAX_POLL_TIMEOUT_MS, ConsumerNetworkThread.MAX_POLL_TIMEOUT_MS + 1})
public void testConsumerNetworkThreadPollTimeComputations(long exampleTime) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this is the second newly added tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

public void testConsumerNetworkThreadPollTimeComputations(long exampleTime) {
List<Optional<? extends RequestManager>> list = new ArrayList<>();
list.add(Optional.of(coordinatorRequestManager));
list.add(Optional.of(heartbeatRequestManager));
Copy link
Member

Choose a reason for hiding this comment

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

Why do we only add two of the three request managers to this list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really just to declutter, I thought it might make that specific test kind of long if I added every request manager. 2 was the minimum amount necessary to test the functionality of the test. It just needs to return the shortest timeUntilNextPollMs. So in order to test this I just did 2 request managers with different poll times to make sure it was being calculated correctly.

I can add the offsetsRequestManager if needed.

Copy link
Contributor

@lianetm lianetm Jun 12, 2024

Choose a reason for hiding this comment

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

It wouldn't hurt to have all managers, but agree that having just a subset > 1 should be enough, because the logic is not specific to the managers (the consumerNetworkThread is blind on the managers, it only knows it has a set of them wrapped in a RequestManagers collection)

@@ -148,35 +169,32 @@ public void testStartupAndTearDown() throws InterruptedException {
}

@Test
public void testApplicationEvent() {
Copy link
Member

Choose a reason for hiding this comment

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

It seems this test is rewritten as testApplicationEventIsProcessed further below? And testRequestsTransferFromManagersToClientOnThreadRun is another newly added test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this test as well as many of the other application event tests were rewritten into a single parameterized test. It gets the parameters from applicationEvents(), where it supplies a stream of different kinds of events. This was done to condense the code a bit.

And testRequestsTransferFromManagersToClientOnThreadRun() is a new test

}

@Test
public void testMetadataUpdateEvent() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this test was effectively removed? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refer to previous comment for all event tests that were removed


@Test
public void testAsyncCommitEvent() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this test was effectively removed? Why?


@Test
public void testSyncCommitEvent() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this test was effectively removed? Why?

@@ -190,15 +208,6 @@ public void testListOffsetsEventIsProcessed(boolean requireTimestamp) {
assertTrue(applicationEventsQueue.isEmpty());
}

@Test
public void testResetPositionsEventIsProcessed() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this test was effectively removed? Why?

Same for more test below

Copy link
Contributor

@philipnee philipnee left a comment

Choose a reason for hiding this comment

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

hi @brenden20 - i left a comment, otherwise lgtm.

@brenden20
Copy link
Contributor Author

@mjsax can you take a look?

@mjsax mjsax changed the title KAFKA-16001 Migrated ConsumerNetworkThreadTest away from ConsumerTestBuilder KAFKA-16001: Migrated ConsumerNetworkThreadTest away from ConsumerTestBuilder Jun 13, 2024
@mjsax mjsax merged commit a0b716e into apache:trunk Jun 13, 2024
1 check was pending
@mjsax
Copy link
Member

mjsax commented Jun 13, 2024

Thanks for the PR @brenden20! Merged to trunk.

@brenden20 brenden20 deleted the 16001 branch June 13, 2024 20:37
@brenden20
Copy link
Contributor Author

@mjsax thank you for the review!

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 <[email protected]>
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.

6 participants