chia7712 commented on code in PR #19187:
URL: https://github.com/apache/kafka/pull/19187#discussion_r3832525543


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/ClientRebootstrapTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.clients;
+
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfigProperty;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ClientRebootstrapTest {
+    private static final String TOPIC = "topic";
+    private static final int REPLICAS = 2;
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrap(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+        var timeout = 60;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) 
REPLICAS)));
+
+            // Only the broker 1 is available for the admin client during the 
bootstrap.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));
+
+            clusterInstance.shutdownBroker(broker1);
+            clusterInstance.startBroker(broker0);
+
+            // The broker 1, originally cached during the bootstrap, is 
offline.
+            // However, the broker 0 from the bootstrap list is online.
+            // Should be able to list topics again.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));

Review Comment:
   ditto



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/ClientRebootstrapTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.clients;
+
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfigProperty;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ClientRebootstrapTest {
+    private static final String TOPIC = "topic";
+    private static final int REPLICAS = 2;
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrap(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+        var timeout = 60;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) 
REPLICAS)));
+
+            // Only the broker 1 is available for the admin client during the 
bootstrap.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));

Review Comment:
   We should verify the existence of `TOPIC` here ...



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/ClientRebootstrapTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.clients;
+
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfigProperty;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ClientRebootstrapTest {
+    private static final String TOPIC = "topic";
+    private static final int REPLICAS = 2;
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrap(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+        var timeout = 60;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) 
REPLICAS)));
+
+            // Only the broker 1 is available for the admin client during the 
bootstrap.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));
+
+            clusterInstance.shutdownBroker(broker1);
+            clusterInstance.startBroker(broker0);
+
+            // The broker 1, originally cached during the bootstrap, is 
offline.
+            // However, the broker 0 from the bootstrap list is online.
+            // Should be able to list topics again.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));
+        }
+    }
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrapDisabled(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        var admin = 
clusterInstance.admin(Map.of(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG,
 "none"));
+        admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) REPLICAS)));
+
+        // Only the broker 1 is available for the admin client during the 
bootstrap.
+        assertDoesNotThrow(() -> admin.listTopics().names().get(60, 
TimeUnit.SECONDS).contains(TOPIC));

Review Comment:
   ditto



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/ClientRebootstrapTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.clients;
+
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterConfigProperty;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.Type;
+import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ClientRebootstrapTest {
+    private static final String TOPIC = "topic";
+    private static final int REPLICAS = 2;
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrap(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+        var timeout = 60;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        try (var admin = clusterInstance.admin()) {
+            admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) 
REPLICAS)));
+
+            // Only the broker 1 is available for the admin client during the 
bootstrap.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));
+
+            clusterInstance.shutdownBroker(broker1);
+            clusterInstance.startBroker(broker0);
+
+            // The broker 1, originally cached during the bootstrap, is 
offline.
+            // However, the broker 0 from the bootstrap list is online.
+            // Should be able to list topics again.
+            assertDoesNotThrow(() -> admin.listTopics().names().get(timeout, 
TimeUnit.SECONDS).contains(TOPIC));
+        }
+    }
+
+    @ClusterTest(
+        brokers = REPLICAS,
+        types = {Type.KRAFT},
+        serverProperties = {
+            @ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")
+        }
+    )
+    public void testAdminRebootstrapDisabled(ClusterInstance clusterInstance) {
+        var broker0 = 0;
+        var broker1 = 1;
+
+        clusterInstance.shutdownBroker(broker0);
+
+        var admin = 
clusterInstance.admin(Map.of(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG,
 "none"));

Review Comment:
   We should use try-finally​ to make sure the admin gets closed even if an 
assertion fails!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to