You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "clarkwtc (via GitHub)" <gi...@apache.org> on 2025/02/27 01:07:24 UTC

[PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

clarkwtc opened a new pull request, #19046:
URL: https://github.com/apache/kafka/pull/19046

   
   Migrate RebootstrapTest to new test infra and remove the old Scala test.
   
   The test results 
   <img width="1571" alt="Screenshot 2025-02-27 at 9 05 52 AM" src="https://github.com/user-attachments/assets/35812c96-13f7-41f8-829d-40947f768646" />
   


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973122449


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();

Review Comment:
   Please use `List.of()` instead `Collections.singletonList`, and  I don't think we need to get the future value.
   ```
   admin.createTopics(List.of(new NewTopic(topic, BROKER_COUNT, (short) 2)));
   ```



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata0.offset());
+
+            server0.shutdown();
+            server0.awaitShutdown();
+            server1.startup();
+
+            // Current server 0 is offline.
+            // However, the server 1 from the bootstrap list is online.
+            // Should be able to produce records.
+            RecordMetadata recordMetadata1 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata1.offset());
+
+            server1.shutdown();
+            server1.awaitShutdown();
+            server0.startup();
+
+            // The same situation, but the server 1 has gone and server 0 is back.
+            RecordMetadata recordMetadata2 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   ditto: Variables should be declared using var to maintain consistency throughout the file.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata0.offset());
+
+            server0.shutdown();
+            server0.awaitShutdown();
+            server1.startup();
+
+            // Current server 0 is offline.
+            // However, the server 1 from the bootstrap list is online.
+            // Should be able to produce records.
+            RecordMetadata recordMetadata1 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   ditto: Variables should be declared using var to maintain consistency throughout the file.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   ditto: Variables should be declared using var to maintain consistency throughout the file.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {

Review Comment:
   nit: Variables should be declared using `var` to maintain consistency throughout the file.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   We could use `CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG` instead of plaintext, other configs are same.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);

Review Comment:
   ditto: Variables should be declared using var to maintain consistency throughout the file.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "ijuma (via GitHub)" <gi...@apache.org>.
ijuma commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2709290586

   We should probably create the clients integration test module before doing these conversions so that the Java classes end up in a Java only module.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973779776


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   I can't do it because the styleAction check blocks the reference by`CommonClientConfigs` in test.
   I only just wrote it in plaintext.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   I can't do it because the styleAction check blocks the reference by`CommonClientConfigs` in tests.
   I only just wrote it in plaintext.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1975509750


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   Thank you, the method effectively relaxes the conditions.
   I updated the `org.apache.kafka.clients` pkg in `import-control-core.xml`. 
   Is it okay to submit this change directly on commit?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973857804


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   You can relax the conditions for core module `import-control`.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1976438924


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));

Review Comment:
   nit: `Map.of()`



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "5000");
+        } else {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "3600000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG, "1000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1000");
+        }
+        properties.put(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {

Review Comment:
   `private`



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "5000");
+        } else {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "3600000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG, "1000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1000");
+        }
+        properties.put(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        var topic = "topic";
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(topic, BROKER_COUNT, (short) 2)));
+        }
+
+        var part = 0;
+        var server0 = clusterInstance.brokers().get(0);
+        var server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            var recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   Please extract `key 1` and `value 1` as variables.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {

Review Comment:
   `private`



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {

Review Comment:
   `private`



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973769247


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata0.offset());
+
+            server0.shutdown();
+            server0.awaitShutdown();
+            server1.startup();
+
+            // Current server 0 is offline.
+            // However, the server 1 from the bootstrap list is online.
+            // Should be able to produce records.
+            RecordMetadata recordMetadata1 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata1.offset());
+
+            server1.shutdown();
+            server1.awaitShutdown();
+            server0.startup();
+
+            // The same situation, but the server 1 has gone and server 0 is back.
+            RecordMetadata recordMetadata2 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   I've fixed it to maintain consistency by using `var`.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);

Review Comment:
   I've fixed it to maintain consistency by using `var`.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2718481150

   @chia7712 @ijuma 
   I already moved this test to clients-integration-tests.
   I have also added `<allow pkg="org.junit" />` on `import-control-clients-integration-tests.xml`


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1976536482


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "5000");
+        } else {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "3600000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG, "1000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1000");
+        }
+        properties.put(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {

Review Comment:
   I've fixed the access modifiers.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1976536401


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));

Review Comment:
   Thank you for your comments.
   It is preferable to use an immutable map here.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2709298334

   > We should probably create the clients integration test module before doing these conversions so that the Java classes end up in a Java only module.
   
   yes, @mumrah has created pull request #19144 to address this issue. After merging #19144, we can submit a minor pull request to relocate the Java test code from the core module to the client module.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1976536992


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "5000");
+        } else {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "3600000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG, "1000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1000");
+        }
+        properties.put(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        var topic = "topic";
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(topic, BROKER_COUNT, (short) 2)));
+        }
+
+        var part = 0;
+        var server0 = clusterInstance.brokers().get(0);
+        var server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            var recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   I've fixed it, then I found a mistake for sending the record with `key 0` and `value 0` first, when comparing it to the old Scala test.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1975509750


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   Thank you, the method effectively relaxes the conditions.
   I updated the `org.apache.kafka.clients` pkg in `import-control-core.xml`. 
   Is it okay to submit this change directly?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973767767


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {

Review Comment:
   I've fixed it to maintain consistency by using `var`.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1986197277


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    private static List<ClusterConfig> generator() {
+        // Enable unclean leader election for the test topic
+        Map<String, String> serverProperties = Map.of(
+            TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true",
+            GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT)
+        );
+
+        return Stream.of(false, true)
+            .map(ProducerRebootstrapTest::getRebootstrapConfig)
+            .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+            .toList();
+    }
+
+    private static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "5000");
+        } else {
+            properties.put(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG, "3600000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG, "5000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG, "1000");
+            properties.put(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG, "1000");
+        }
+        properties.put(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG, "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    private static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+            .setTypes(Set.of(Type.KRAFT))
+            .setBrokers(BROKER_COUNT)
+            .setProducerProperties(rebootstrapProperties)
+            .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        var topic = "topic";
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(topic, BROKER_COUNT, (short) 2)));

Review Comment:
   Should we use `BROKER_COUNT` to define `replicationFactor` rather than partition?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973768673


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   I've fixed it to maintain consistency by using `var`.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();
+        }
+
+        int part = 0;
+        KafkaBroker server0 = clusterInstance.brokers().get(0);
+        KafkaBroker server1 = clusterInstance.brokers().get(1);
+
+        // It's ok to shut the leader down, cause the reelection is small enough to the producer timeout.
+        server1.shutdown();
+        server1.awaitShutdown();
+
+        try (var producer = clusterInstance.producer()) {
+            // Only the server 0 is available for the producer during the bootstrap.
+            RecordMetadata recordMetadata0 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();
+            assertEquals(0, recordMetadata0.offset());
+
+            server0.shutdown();
+            server0.awaitShutdown();
+            server1.startup();
+
+            // Current server 0 is offline.
+            // However, the server 1 from the bootstrap list is online.
+            // Should be able to produce records.
+            RecordMetadata recordMetadata1 = producer.send(new ProducerRecord<>(topic, part, "key 1".getBytes(), "value 1".getBytes())).get();

Review Comment:
   I've fixed it to maintain consistency by using `var`.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973779776


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   I can't do it because the styleAction check blocks the reference by`CommonClientConfigs`.
   I only just wrote it in plaintext.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2708653416

   this PR has same issues to https://github.com/apache/kafka/pull/19094#discussion_r1986208718


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1976536463


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {

Review Comment:
   I've fixed the access modifiers.



##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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 kafka.test.api;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {

Review Comment:
   I've fixed the access modifiers.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2718333704

   @chia7712 
   Thank you for your note.
   I have also updated this PR to fix the related issues from https://github.com/apache/kafka/pull/19094#discussion_r1986208718


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #19046:
URL: https://github.com/apache/kafka/pull/19046


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate ProducerRebootstrapTest to new test infra [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #19046:
URL: https://github.com/apache/kafka/pull/19046#issuecomment-2718360474

   @clarkwtc could you please move this test to clients-integration-tests ?


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1973760130


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");
+        properties.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+        return properties;
+    }
+
+    static ClusterConfig buildConfig(Map<String, String> serverProperties, Map<String, String> rebootstrapProperties) {
+        return ClusterConfig.defaultBuilder()
+                .setTypes(Set.of(Type.KRAFT))
+                .setBrokers(BROKER_COUNT)
+                .setProducerProperties(rebootstrapProperties)
+                .setServerProperties(serverProperties).build();
+    }
+
+    @ClusterTemplate(value = "generator")
+    public void testRebootstrap(ClusterInstance clusterInstance) throws ExecutionException, InterruptedException {
+        String topic = "topic";
+        try (Admin admin = clusterInstance.admin()) {
+            admin.createTopics(Collections.singletonList(new NewTopic(topic, BROKER_COUNT, (short) 2))).all().get();

Review Comment:
   Thank you for your comments.
   Sure, we don't need to get any future value.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "clarkwtc (via GitHub)" <gi...@apache.org>.
clarkwtc commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1975509750


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   Thank you, the method effectively relaxes the conditions.
   I have tested to update the `org.apache.kafka.clients` pkg in `import-control-core.xml`. 
   Is it okay to submit this change directly on commit?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-18276 Migrate RebootstrapTest to new test infra [kafka]

Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #19046:
URL: https://github.com/apache/kafka/pull/19046#discussion_r1975600010


##########
core/src/test/java/kafka/test/api/ProducerRebootstrapTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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 kafka.test.api;
+
+import kafka.server.KafkaBroker;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfig;
+import org.apache.kafka.common.test.api.ClusterTemplate;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ProducerRebootstrapTest {
+    private static final int BROKER_COUNT = 2;
+
+    static List<ClusterConfig> generator() {
+        Map<String, String> serverProperties = new HashMap<>();
+        // Enable unclean leader election for the test topic
+        serverProperties.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");
+        serverProperties.put(GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, String.valueOf(BROKER_COUNT));
+
+        return Stream.of(false, true)
+                .map(ProducerRebootstrapTest::getRebootstrapConfig)
+                .map(rebootstrapProperties -> ProducerRebootstrapTest.buildConfig(serverProperties, rebootstrapProperties))
+                .toList();
+    }
+
+    static Map<String, String> getRebootstrapConfig(boolean useRebootstrapTriggerMs) {
+        Map<String, String> properties = new HashMap<>();
+        if (useRebootstrapTriggerMs) {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "5000");
+        } else {
+            properties.put("metadata.recovery.rebootstrap.trigger.ms", "3600000");
+            properties.put("socket.connection.setup.timeout.ms", "5000");
+            properties.put("socket.connection.setup.timeout.max.ms", "5000");
+            properties.put("reconnect.backoff.ms", "1000");
+            properties.put("reconnect.backoff.max.ms", "1000");
+        }
+        properties.put("metadata.recovery.strategy", "rebootstrap");

Review Comment:
   I think it's not a problem.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org