-
Notifications
You must be signed in to change notification settings - Fork 15k
KAFKA-15106 fix AbstractStickyAssignor isBalanced predict #13920
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 all commits
33a4667
49a4388
0decfe1
fab5a9a
950da4c
97e72d1
b1ba8b0
1272a14
d1d4730
2e0e08c
0b71678
02371f2
6178243
eaac639
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import java.util.Optional; | ||
| import java.util.Random; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Subscription; | ||
| import org.apache.kafka.clients.consumer.StickyAssignor; | ||
|
|
@@ -724,6 +725,91 @@ public void testLargeAssignmentAndGroupWithNonEqualSubscription(boolean hasConsu | |
| assignor.assignPartitions(partitionsPerTopic, subscriptions); | ||
| } | ||
|
|
||
| @Timeout(90) | ||
|
Contributor
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. Just an opinion here: Other tests also use timeout annotation, but it might be better to use
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. Oh, this 90 should be sec, I set 90 sec because in my m1 air this test may run about 25 sec or more time. I tried
Contributor
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. Ah no problem. 25s is surprisingly long! |
||
| @ParameterizedTest(name = TEST_NAME_WITH_CONSUMER_RACK) | ||
| @ValueSource(booleans = {false, true}) | ||
| public void testAssignmentAndGroupWithNonEqualSubscriptionNotTimeout(boolean hasConsumerRack) { | ||
| initializeRacks(hasConsumerRack ? RackConfig.BROKER_AND_CONSUMER_RACK : RackConfig.NO_CONSUMER_RACK); | ||
| int topicCount = hasConsumerRack ? 50 : 100; | ||
| int partitionCount = 2_00; | ||
| int consumerCount = 5_00; | ||
|
|
||
| List<String> topics = new ArrayList<>(); | ||
| Map<String, List<PartitionInfo>> partitionsPerTopic = new HashMap<>(); | ||
| for (int i = 0; i < topicCount; i++) { | ||
| String topicName = getTopicName(i, topicCount); | ||
| topics.add(topicName); | ||
| partitionsPerTopic.put(topicName, partitionInfos(topicName, partitionCount)); | ||
| } | ||
| for (int i = 0; i < consumerCount; i++) { | ||
| if (i % 4 == 0) { | ||
| subscriptions.put(getConsumerName(i, consumerCount), | ||
| subscription(topics.subList(0, topicCount / 2), i)); | ||
| } else { | ||
| subscriptions.put(getConsumerName(i, consumerCount), | ||
| subscription(topics.subList(topicCount / 2, topicCount), i)); | ||
| } | ||
| } | ||
|
|
||
| Map<String, List<TopicPartition>> assignment = assignor.assignPartitions(partitionsPerTopic, subscriptions); | ||
|
|
||
| for (int i = 1; i < consumerCount; i++) { | ||
| String consumer = getConsumerName(i, consumerCount); | ||
| if (i % 4 == 0) { | ||
| subscriptions.put( | ||
| consumer, | ||
| buildSubscriptionV2Above(topics.subList(0, topicCount / 2), | ||
| assignment.get(consumer), generationId, i) | ||
| ); | ||
| } else { | ||
| subscriptions.put( | ||
| consumer, | ||
| buildSubscriptionV2Above(topics.subList(topicCount / 2, topicCount), | ||
| assignment.get(consumer), generationId, i) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| assignor.assignPartitions(partitionsPerTopic, subscriptions); | ||
|
Contributor
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. Can we directly test the
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. for now |
||
| } | ||
|
|
||
| @Test | ||
| public void testSubscriptionNotEqualAndAssignSamePartitionWith3Generation() { | ||
|
Contributor
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. Thanks for the test! I wrote a similar test,
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. this method is to test but this bug in I couldn't understand how to reuse such test style, could you provide any example? |
||
| Map<String, List<PartitionInfo>> partitionsPerTopic = new HashMap<>(); | ||
| partitionsPerTopic.put(topic, partitionInfos(topic, 6)); | ||
| partitionsPerTopic.put(topic1, partitionInfos(topic1, 1)); | ||
| int[][] sequence = new int[][]{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}; | ||
| for (int[] ints : sequence) { | ||
| subscriptions.put( | ||
| consumer1, | ||
| buildSubscriptionV2Above(topics(topic), | ||
| partitions(tp(topic, 0), tp(topic, 2)), ints[0], 0) | ||
| ); | ||
| subscriptions.put( | ||
| consumer2, | ||
| buildSubscriptionV2Above(topics(topic), | ||
| partitions(tp(topic, 1), tp(topic, 2), tp(topic, 3)), ints[1], 1) | ||
| ); | ||
| subscriptions.put( | ||
| consumer3, | ||
| buildSubscriptionV2Above(topics(topic), | ||
| partitions(tp(topic, 2), tp(topic, 4), tp(topic, 5)), ints[2], 2) | ||
| ); | ||
| subscriptions.put( | ||
| consumer4, | ||
| buildSubscriptionV2Above(topics(topic1), | ||
| partitions(tp(topic1, 0)), 2, 3) | ||
| ); | ||
|
|
||
| Map<String, List<TopicPartition>> assign = assignor.assignPartitions(partitionsPerTopic, subscriptions); | ||
| assertEquals(assign.values().stream().mapToInt(List::size).sum(), | ||
| assign.values().stream().flatMap(List::stream).collect(Collectors.toSet()).size()); | ||
| for (List<TopicPartition> list: assign.values()) { | ||
| assertTrue(list.size() >= 1 && list.size() <= 2); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Timeout(60) | ||
| @ParameterizedTest(name = TEST_NAME_WITH_CONSUMER_RACK) | ||
| @ValueSource(booleans = {false, true}) | ||
|
|
||
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.
We'd Have to add a put here too
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.
fixed, plz take a look