FrankYang0529 commented on code in PR #22294: URL: https://github.com/apache/kafka/pull/22294#discussion_r3254415918
########## storage/src/test/java/org/apache/kafka/tiered/storage/HarnessBackedClusterInstance.java: ########## @@ -0,0 +1,175 @@ +/* + * 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.tiered.storage; + +import kafka.server.ControllerServer; +import kafka.server.KafkaBroker; + +import org.apache.kafka.common.network.ListenerName; +import org.apache.kafka.common.test.ClusterInstance; +import org.apache.kafka.common.test.api.ClusterConfig; +import org.apache.kafka.common.test.api.Type; +import org.apache.kafka.server.fault.FaultHandlerException; +import org.apache.kafka.test.TestUtils; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import scala.jdk.javaapi.CollectionConverters; + +/** + * A {@link ClusterInstance} implementation backed by a {@link TieredStorageTestHarness}. + * This allows {@link TieredStorageTestContext} to depend only on {@link ClusterInstance} + * rather than on the concrete harness class. + */ +public class HarnessBackedClusterInstance implements ClusterInstance { + + private final TieredStorageTestHarness harness; + + public HarnessBackedClusterInstance(TieredStorageTestHarness harness) { + this.harness = harness; + } + + @Override + public Type type() { + return Type.KRAFT; + } + + @Override + public ClusterConfig config() { + return ClusterConfig.defaultBuilder().build(); + } + + @Override + public Set<Integer> controllerIds() { + return controllers().keySet(); + } + + @Override + public ListenerName clientListener() { + return harness.listenerName(); + } + + @Override + public ListenerName controllerListenerName() { + return controllers().values().stream() + .map(c -> new ListenerName(c.config().controllerListenerNames().get(0))) + .findFirst() + .orElseThrow(() -> new RuntimeException("No controllers available")); + } + + @Override + public String bootstrapServers() { + return harness.bootstrapServers(harness.listenerName()); + } + + @Override + public String bootstrapControllers() { + return harness.bootstrapServers(harness.listenerName()); Review Comment: Thanks for the suggestion. The HarnessBackedClusterInstance is a temporary class. If we change to use ClusterTemplate to replace TieredStorageTestHarness, we can remove HarnessBackedClusterInstance in the future. I leave this as unsupported function in HarnessBackedClusterInstance. -- 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]
