chia7712 commented on code in PR #19094: URL: https://github.com/apache/kafka/pull/19094#discussion_r1986207973
########## core/src/test/java/kafka/test/api/AdminClientRebootstrapTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.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 org.apache.kafka.test.TestUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +public class AdminClientRebootstrapTest { + 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(AdminClientRebootstrapTest::getRebootstrapConfig) + .map(rebootstrapProperties -> AdminClientRebootstrapTest.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"); + 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) + .setAdminClientProperties(rebootstrapProperties) Review Comment: open https://issues.apache.org/jira/browse/KAFKA-18944 to remove those unused setters ########## core/src/test/java/kafka/test/api/AdminClientRebootstrapTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.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 org.apache.kafka.test.TestUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +public class AdminClientRebootstrapTest { + 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(AdminClientRebootstrapTest::getRebootstrapConfig) + .map(rebootstrapProperties -> AdminClientRebootstrapTest.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"); + 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) + .setAdminClientProperties(rebootstrapProperties) + .setServerProperties(serverProperties).build(); + } + + @ClusterTemplate(value = "generator") + public void testRebootstrap(ClusterInstance clusterInstance) throws InterruptedException { Review Comment: After rewriting, this test no longer covers the scenario. We need to verify that the admin can "rebootstrap" when all "known" brokers are unavailable. Therefore, we should shut down one broker before creating the admin to ensure it's aware of "one" broker. Then, we shut down the broker the admin is aware of and restart the other one. 1. Shut down broker0. 2. Create the admin with bootstrap=broker0,broker1. 3. The admin is aware of broker1. 4. Run some admin APIs to ensure everything is fine. 5. Shut down broker1 and restart broker0. 6. The admin can't connect to broker1, so it starts to rebootstrap to find other available brokers. 7. The admin finds broker0. 8. Run some admin APIs to ensure everything is fine. ########## core/src/test/java/kafka/test/api/AdminClientRebootstrapTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.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 org.apache.kafka.test.TestUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +public class AdminClientRebootstrapTest { + 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(AdminClientRebootstrapTest::getRebootstrapConfig) + .map(rebootstrapProperties -> AdminClientRebootstrapTest.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"); + 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) + .setAdminClientProperties(rebootstrapProperties) + .setServerProperties(serverProperties).build(); + } + + @ClusterTemplate(value = "generator") + public void testRebootstrap(ClusterInstance clusterInstance) throws InterruptedException { + var topic = "topic"; + var timeout = 5; + try (var admin = clusterInstance.admin()) { + admin.createTopics(List.of(new NewTopic(topic, BROKER_COUNT, (short) 2))); Review Comment: `BROKER_COUNT` should be used to define replicas rather than partitions, since our goal is to ensure each broker has a replica. ########## core/src/test/java/kafka/test/api/AdminClientRebootstrapTest.java: ########## @@ -0,0 +1,111 @@ +/* + * 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.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 org.apache.kafka.test.TestUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +public class AdminClientRebootstrapTest { + 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(AdminClientRebootstrapTest::getRebootstrapConfig) + .map(rebootstrapProperties -> AdminClientRebootstrapTest.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"); + 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) + .setAdminClientProperties(rebootstrapProperties) Review Comment: this method is no-op, and we should use `clusterInstance.admin(Map)` to build admin with custom configs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org