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
MINOR: migrate ListConsumerGroupTest to use ClusterTestExtensions #15821
base: trunk
Are you sure you want to change the base?
MINOR: migrate ListConsumerGroupTest to use ClusterTestExtensions #15821
Conversation
Rely on #15766. |
7933c99
to
7c85ff9
Compare
Hi @chia7712, I rebase latest trunk branch, so we have kafka/tools/src/test/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommandTest.java Lines 327 to 335 in 21bf715
|
That is addressed already. see |
7c85ff9
to
e8307a0
Compare
Thanks. The kafka/tools/src/test/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommandTest.java Lines 274 to 287 in f4fdaa7
|
@@ -92,6 +94,7 @@ static void generator(ClusterGenerator clusterGenerator) { | |||
static <T> AutoCloseable buildConsumers(int numberOfConsumers, |
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.
Could we have two buildConsumers
to deal with "assign"/"subscribe" individually?
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.
Thank you. I update to define two buildConsumers
. May you help me take a look? If we're good with current design. I will update to #15908.
e8307a0
to
37ae9fb
Compare
@FrankYang0529 please rebase code to include 334d5d5 |
Signed-off-by: PoAn Yang <payang@apache.org>
37ae9fb
to
6191872
Compare
@@ -93,6 +95,27 @@ static <T> AutoCloseable buildConsumers(int numberOfConsumers, | |||
} | |||
} | |||
|
|||
static <T> AutoCloseable buildConsumers(int numberOfConsumers, |
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.
Please DON'T generate a bunch of duplicate code...
static <T> AutoCloseable buildConsumers(int numberOfConsumers,
boolean syncCommit,
Set<TopicPartition> partitions,
Supplier<KafkaConsumer<T, T>> consumerSupplier) {
return buildConsumers(numberOfConsumers, syncCommit, consumerSupplier,
consumer -> consumer.assign(partitions));
}
static <T> AutoCloseable buildConsumers(int numberOfConsumers,
boolean syncCommit,
String topic,
Supplier<KafkaConsumer<T, T>> consumerSupplier) {
return buildConsumers(numberOfConsumers, syncCommit, consumerSupplier,
consumer -> consumer.subscribe(Collections.singleton(topic)));
}
private static <T> AutoCloseable buildConsumers(int numberOfConsumers,
boolean syncCommit,
Supplier<KafkaConsumer<T, T>> consumerSupplier,
Consumer<KafkaConsumer<T, T>> setPartitions) {
List<KafkaConsumer<T, T>> consumers = new ArrayList<>(numberOfConsumers);
ExecutorService executor = Executors.newFixedThreadPool(numberOfConsumers);
AtomicBoolean closed = new AtomicBoolean(false);
final AutoCloseable closeable = () -> releaseConsumers(closed, consumers, executor);
try {
for (int i = 0; i < numberOfConsumers; i++) {
KafkaConsumer<T, T> consumer = consumerSupplier.get();
consumers.add(consumer);
executor.execute(() -> initConsumer(syncCommit, () -> {
setPartitions.accept(consumer);
return consumer;
}, closed));
}
return closeable;
} catch (Throwable e) {
Utils.closeQuietly(closeable, "Release Consumer");
throw e;
}
}
private static <T> void releaseConsumers(AtomicBoolean closed, List<KafkaConsumer<T, T>> consumers, ExecutorService executor) throws InterruptedException {
closed.set(true);
consumers.forEach(KafkaConsumer::wakeup);
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
}
private static <T> void initConsumer(boolean syncCommit,
Supplier<KafkaConsumer<T, T>> consumerSupplier,
AtomicBoolean closed) {
try (KafkaConsumer<T, T> kafkaConsumer = consumerSupplier.get()) {
while (!closed.get()) {
kafkaConsumer.poll(Duration.ofMillis(Long.MAX_VALUE));
if (syncCommit)
kafkaConsumer.commitSync();
}
} catch (WakeupException e) {
// OK
}
}
By using
ClusterTestExtensions
,ListConsumerGroupTest
get get away fromKafkaServerTestHarness
dependency.Committer Checklist (excluded from commit message)