-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Conversation
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
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
There was a problem hiding this 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.
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
clients/src/main/java/org/apache/kafka/clients/consumer/internals/CommitRequestManager.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
Looks like there are some checkstyle failures due to the use of wildcard imports. |
There was a problem hiding this 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
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
@lianetm implemented your suggestions on the description and testConsumerNetworkThreadPollTimeComputations(). Let me know how it looks |
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
Updates testConsumerNetworkThreadPollTimeComputations() and fixed a checkstyle error
@lianetm I implemented your new suggestions, let me know if it looks good |
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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!
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
...nts/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThreadTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
@mjsax can you take a look? |
Thanks for the PR @brenden20! Merged to |
@mjsax thank you for the review! |
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]>
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