-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-16557 Implemented OffsetFetchRequestState toStringBase and added a test for it #16291
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
Changes from 1 commit
81a5572
7147a27
e91891f
caf17bb
1941a55
5768017
94f26b5
837d9ea
98361ea
f061d97
2583e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1078,14 +1078,11 @@ private void chainFuture( | |
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "OffsetFetchRequestState{" + | ||
| "requestedPartitions=" + requestedPartitions + | ||
| ", memberId=" + memberInfo.memberId.orElse("undefined") + | ||
| ", memberEpoch=" + (memberInfo.memberEpoch.isPresent() ? memberInfo.memberEpoch.get() : "undefined") + | ||
| ", future=" + future + | ||
| ", " + toStringBase() + | ||
| '}'; | ||
| public String toStringBase() { | ||
| return super.toStringBase() + | ||
| ", memberInfo=" + memberInfo + | ||
| ", requestedPartitions=" + requestedPartitions + | ||
| ", future=" + future; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure whether it is worth printing |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -1278,5 +1275,12 @@ static class MemberInfo { | |
| this.memberId = Optional.empty(); | ||
| this.memberEpoch = Optional.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "MemberInfo{" + "memberId=" + memberId.orElse("undefined") + | ||
| ", memberEpoch=" + (memberEpoch.isPresent() ? memberEpoch : "undefined") + "}"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say we need to check if present. There could be no epoch/id when committing/fetching (if we haven't joined a group or left it. In those cases we would have empty here, so that no epoch/id is included in the OffsetFetch/OffsetCommit request).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! And my point was "we should call get if it is present". Otherwise, the toString will include "Optional"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented this suggestion, I will note that when testing the method, there is no difference in how the string is printed whether using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh I misread your point he he. But both on the same page in the end, great. |
||
| } | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ | |
| import static org.apache.kafka.clients.consumer.internals.ConsumerTestBuilder.DEFAULT_GROUP_ID; | ||
| import static org.apache.kafka.clients.consumer.internals.ConsumerTestBuilder.DEFAULT_GROUP_INSTANCE_ID; | ||
| import static org.apache.kafka.test.TestUtils.assertFutureThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
|
@@ -122,6 +123,50 @@ public void setup() { | |
| this.props.put(VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOffsetFetchRequestStateToStringBase() { | ||
| ConsumerConfig config = mock(ConsumerConfig.class); | ||
| CommitRequestManager.MemberInfo memberInfo = new CommitRequestManager.MemberInfo(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we had discussion about "Optional#toString", maybe we define either
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you meant now, I have implemented a setter for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brenden20 we already have an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lianetm oh I see it now, I will revert that change and use |
||
|
|
||
| CommitRequestManager commitRequestManager = new CommitRequestManager( | ||
| time, | ||
| logContext, | ||
| subscriptionState, | ||
| config, | ||
| coordinatorRequestManager, | ||
| offsetCommitCallbackInvoker, | ||
| "groupId", | ||
| Optional.of("groupInstanceId"), | ||
| metrics); | ||
|
|
||
| Set<TopicPartition> requestedPartitions = new HashSet<>(); | ||
| TopicPartition topicPartition1 = new TopicPartition("topic-1", 1); | ||
| requestedPartitions.add(topicPartition1); | ||
|
brenden20 marked this conversation as resolved.
Outdated
|
||
|
|
||
| CommitRequestManager.OffsetFetchRequestState offsetFetchRequestState = commitRequestManager.new OffsetFetchRequestState( | ||
| requestedPartitions, | ||
| retryBackoffMs, | ||
| retryBackoffMaxMs, | ||
| 1000, | ||
| memberInfo); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the line#142 - The If we want to complete the test, maybe we can remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit hesitant to change the constructor of |
||
|
|
||
| TimedRequestState timedRequestState = new TimedRequestState( | ||
| logContext, | ||
| "CommitRequestManager", | ||
| retryBackoffMs, | ||
| retryBackoffMaxMs, | ||
| TimedRequestState.deadlineTimer(time, 0) | ||
| ); | ||
|
|
||
| String target = timedRequestState.toStringBase() + | ||
| ", memberInfo=" + memberInfo + | ||
| ", requestedPartitions=" + offsetFetchRequestState.requestedPartitions + | ||
| ", future=" + offsetFetchRequestState.future(); | ||
|
|
||
| assertDoesNotThrow(timedRequestState::toString); | ||
| assertEquals(target, offsetFetchRequestState.toStringBase()); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
|
|
||
| @Test | ||
| public void testPollSkipIfCoordinatorUnknown() { | ||
| CommitRequestManager commitRequestManager = create(false, 0); | ||
|
|
||
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.
memberInfois from superRetriableRequestState. Maybe we should addtoStringBasetoRetriableRequestStatetoo?Uh oh!
There was an error while loading. Please reload this page.
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.
Agree with moving this up to the
RetriableRequestState, and once there, I would also suggest we simplify the output to show the member id and epoch directly, something like:MemberInfois just an internal wrapper to move the 2 together, but when seeing a toString for an OffsetFetch or OffsetCommit request, we just care aboutmemberIdandmemberEpoch(they will be included in the request to the broker)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 have implemented both suggestions