jack2012aa commented on code in PR #21101: URL: https://github.com/apache/kafka/pull/21101#discussion_r2649492023
########## server/src/test/java/org/apache/kafka/server/MetadataRequestTest.java: ########## @@ -0,0 +1,431 @@ +/* + * 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.server; + +import kafka.network.SocketServer; +import kafka.server.KafkaBroker; + +import org.apache.kafka.common.Cluster; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.PartitionInfo; +import org.apache.kafka.common.Uuid; +import org.apache.kafka.common.errors.UnsupportedVersionException; +import org.apache.kafka.common.internals.Topic; +import org.apache.kafka.common.message.MetadataRequestData; +import org.apache.kafka.common.network.ListenerName; +import org.apache.kafka.common.protocol.Errors; +import org.apache.kafka.common.requests.FetchRequest; +import org.apache.kafka.common.requests.MetadataRequest; +import org.apache.kafka.common.requests.MetadataResponse; +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.ClusterTestDefaults; +import org.apache.kafka.coordinator.group.GroupCoordinatorConfig; +import org.apache.kafka.metadata.BrokerState; +import org.apache.kafka.metadata.LeaderAndIsr; +import org.apache.kafka.server.config.ReplicationConfigs; +import org.apache.kafka.test.TestUtils; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@ClusterTestDefaults( + brokers = 3, + serverProperties = { + @ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_PARTITIONS_CONFIG, value = "5"), + @ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "1"), + @ClusterConfigProperty(id = 0, key = "broker.rack", value = "rack/0"), + @ClusterConfigProperty(id = 1, key = "broker.rack", value = "rack/1"), + @ClusterConfigProperty(id = 2, key = "broker.rack", value = "rack/2") + } +) + +public class MetadataRequestTest { + + private final ClusterInstance clusterInstance; + + MetadataRequestTest(ClusterInstance clusterInstance) { + this.clusterInstance = clusterInstance; + } + + private List<KafkaBroker> brokers() { + return clusterInstance.brokers().values().stream().toList(); + } + + private SocketServer anySocketServer() throws IllegalStateException { + Map<Integer, KafkaBroker> aliveBrokers = clusterInstance.aliveBrokers(); + if (aliveBrokers.isEmpty()) { + throw new IllegalStateException("No alive brokers is available"); + } + return aliveBrokers.values().stream().map(KafkaBroker::socketServer).iterator().next(); + } + + private MetadataRequestData requestData(List<String> topics, boolean allowAutoTopicCreation) { Review Comment: The helper method is used to create v0 request, which isn't supported by the builder. I can't find any reason to restrict it . Maybe we can remove the restriction? -- 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]
