frankvicky commented on code in PR #19651: URL: https://github.com/apache/kafka/pull/19651#discussion_r2080748529
########## clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/consumer/BaseConsumerTest.java: ########## @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer; + +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.common.ClusterResource; +import org.apache.kafka.common.ClusterResourceListener; +import org.apache.kafka.common.PartitionInfo; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.internals.Topic; +import org.apache.kafka.common.serialization.Deserializer; +import org.apache.kafka.common.serialization.Serializer; +import org.apache.kafka.common.test.ClusterInstance; +import org.apache.kafka.common.test.TestUtils; + +import java.time.Duration; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.apache.kafka.clients.ClientsTestUtils.consumeAndVerifyRecords; +import static org.apache.kafka.clients.ClientsTestUtils.sendRecords; +import static org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG; +import static org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG; +import static org.apache.kafka.clients.producer.ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG; +import static org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class BaseConsumerTest { + + public static final AtomicInteger UPDATE_PRODUCER_COUNT = new AtomicInteger(); + public static final AtomicInteger UPDATE_CONSUMER_COUNT = new AtomicInteger(); + public static final int BROKER_COUNT = 3; + + public static class Testcase { + + public static final String TOPIC = "topic"; + public static final TopicPartition TP = new TopicPartition(TOPIC, 0); + + public static void testSimpleConsumption( + ClusterInstance cluster, + Map<String, Object> config + ) throws InterruptedException { + var numRecords = 10000; + var startingTimestamp = System.currentTimeMillis(); + sendRecords(cluster, TP, numRecords, startingTimestamp); + try (Consumer<byte[], byte[]> consumer = cluster.consumer(config)) { + assertEquals(0, consumer.assignment().size()); + consumer.assign(List.of(TP)); + assertEquals(1, consumer.assignment().size()); + + consumer.seek(TP, 0); + consumeAndVerifyRecords(consumer, TP, numRecords, 0, 0, startingTimestamp); + // check async commit callbacks + sendAndAwaitAsyncCommit(consumer, Optional.empty()); + } + } + + public static void testClusterResourceListener( + ClusterInstance cluster, + Map<String, Object> consumerConfig + ) throws InterruptedException { + var numRecords = 100; + Map<String, Object> producerConfig = Map.of( + KEY_SERIALIZER_CLASS_CONFIG, TestClusterResourceListenerSerializer.class, + VALUE_SERIALIZER_CLASS_CONFIG, TestClusterResourceListenerSerializer.class + ); + Map<String, Object> consumerConfigOverrides = new HashMap<>(consumerConfig); + consumerConfigOverrides.put(KEY_DESERIALIZER_CLASS_CONFIG, TestClusterResourceListenerDeserializer.class); + consumerConfigOverrides.put(VALUE_DESERIALIZER_CLASS_CONFIG, TestClusterResourceListenerDeserializer.class); Review Comment: I get your point. But it seems that we don't need consumerConfig, which could also pass the tests. Could you verify it ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org