-
Notifications
You must be signed in to change notification settings - Fork 15.3k
KAFKA-13834: add normal test case #12092
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9a61e49
bugfix for KAFKA-13834
8e7964b
KAFKA-13834: fix drain batch starving issue
3dbbefd
change import * to single class
e213a79
1:make the nodesDrainIndex as private final
ff88937
1:remove unchecked identification
8ec5da3
add more context
e817088
add space between [,] and next argument.
d628cd1
fix the infinite loop
d200801
add the drain index test case
d6232e9
add the continue case
159b020
Modify comments
4c76bd0
Code format change
cdb1432
change test name to testDrainBatches
c43d3e9
modify code comments
ba866d6
change code style
6f7597b
Merge branch 'apache:trunk' into trunk
ruanliang-hualun fedab82
KAFKA-13834: add normal test case
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| import java.nio.ByteBuffer; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Deque; | ||
| import java.util.HashSet; | ||
|
|
@@ -61,6 +62,7 @@ | |
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.stream.Collectors; | ||
| import static java.util.Arrays.asList; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
|
@@ -107,7 +109,7 @@ public void testDrainBatches() throws Exception { | |
| PartitionInfo part4 = new PartitionInfo(topic, partition4, node2, null, null); | ||
|
|
||
| long batchSize = value.length + DefaultRecordBatch.RECORD_BATCH_OVERHEAD; | ||
| RecordAccumulator accum = createTestRecordAccumulator((int) batchSize, 1024, CompressionType.NONE, 10); | ||
| RecordAccumulator accum = createTestRecordAccumulator((int) batchSize, Integer.MAX_VALUE, CompressionType.NONE, 10); | ||
| Cluster cluster = new Cluster(null, Arrays.asList(node1, node2), Arrays.asList(part1, part2, part3, part4), | ||
| Collections.emptySet(), Collections.emptySet()); | ||
|
|
||
|
|
@@ -142,15 +144,25 @@ public void testDrainBatches() throws Exception { | |
| // drain batches from 2 nodes: node1 => tp2, node2 => tp3 (because tp4 is muted) | ||
| Map<Integer, List<ProducerBatch>> batches4 = accum.drain(cluster, new HashSet<Node>(Arrays.asList(node1, node2)), (int) batchSize, 0); | ||
| verifyTopicPartitionInBatches(batches4, tp2, tp3); | ||
|
|
||
| // add record for tp1, tp2, tp3, and unmute tp4 | ||
| accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs, false, time.milliseconds()); | ||
| accum.append(tp2, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs, false, time.milliseconds()); | ||
| accum.append(tp3, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs, false, time.milliseconds()); | ||
| accum.unmutePartition(tp4); | ||
| // set maxSize as a max value, so that the all partitions in 2 nodes should be drained: node1 => [tp1, tp2], node2 => [tp3, tp4] | ||
| Map<Integer, List<ProducerBatch>> batches5 = accum.drain(cluster, new HashSet<Node>(Arrays.asList(node1, node2)), Integer.MAX_VALUE, 0); | ||
| verifyTopicPartitionInBatches(batches5, tp1, tp2, tp3, tp4); | ||
| } | ||
|
|
||
| private void verifyTopicPartitionInBatches(Map<Integer, List<ProducerBatch>> batches, TopicPartition... tp) { | ||
| assertEquals(tp.length, batches.size()); | ||
| private void verifyTopicPartitionInBatches(Map<Integer, List<ProducerBatch>> nodeBatches, TopicPartition... tp) { | ||
| int allTpBatchCount = nodeBatches.values().stream().flatMap(Collection::stream).collect(Collectors.toList()).size(); | ||
| assertEquals(tp.length, allTpBatchCount); | ||
| List<TopicPartition> topicPartitionsInBatch = new ArrayList<TopicPartition>(); | ||
| for (Map.Entry<Integer, List<ProducerBatch>> entry : batches.entrySet()) { | ||
| List<ProducerBatch> batchList = entry.getValue(); | ||
| assertEquals(1, batchList.size()); | ||
|
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. because the batcheList.size() can be 1 or 2, remove this assert statement |
||
| topicPartitionsInBatch.add(batchList.get(0).topicPartition); | ||
| for (Map.Entry<Integer, List<ProducerBatch>> entry : nodeBatches.entrySet()) { | ||
| List<ProducerBatch> tpBatchList = entry.getValue(); | ||
| List<TopicPartition> tpList = tpBatchList.stream().map(producerBatch -> producerBatch.topicPartition).collect(Collectors.toList()); | ||
| topicPartitionsInBatch.addAll(tpList); | ||
| } | ||
|
|
||
| for (int i = 0; i < tp.length; i++) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
allTpBatchCount represent the count of the producerbatch from the nodeBatches map