hachikuji commented on a change in pull request #9986: URL: https://github.com/apache/kafka/pull/9986#discussion_r567078580
########## File path: core/src/test/java/kafka/test/junit/ClusterForEach.java ########## @@ -0,0 +1,219 @@ +/* + * 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.junit; + +import kafka.test.ClusterConfig; +import kafka.test.ClusterGenerator; +import kafka.test.annotation.ClusterTestDefaults; +import kafka.test.annotation.ClusterProperty; +import kafka.test.annotation.ClusterTemplate; +import kafka.test.annotation.ClusterTest; +import kafka.test.annotation.ClusterTests; +import kafka.test.annotation.Type; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.junit.platform.commons.util.ReflectionUtils; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Properties; +import java.util.function.Consumer; +import java.util.stream.Stream; + +/** + * ClusterForEach is a custom JUnit extension that will generate some number of test invocations depending on a few + * custom annotations. These annotations are placed on so-called test template methods. Template methods look like + * normal JUnit test methods, but instead of being invoked directly, they are used as templates for generating + * multiple test invocations. + * + * Test class that use this extension should use one of the following annotations on each template method: + * + * <ul> + * <li>{@link ClusterTest}, define a single cluster configuration</li> + * <li>{@link ClusterTests}, provide multiple instances of @ClusterTest</li> + * <li>{@link ClusterTemplate}, define a static method that generates cluster configurations</li> + * </ul> + * + * Any combination of these annotations may be used on a given test template method. If no test invocations are + * generated after processing the annotations, an error is thrown. + * + * Depending on which annotations are used, and what values are given, different {@link ClusterConfig} will be + * generated. Each ClusterConfig is used to create an underlying Kafka cluster that is used for the actual test + * invocation. + * + * For example: + * + * <pre> + * @ExtendWith(value = Array(classOf[ClusterForEach])) + * class SomeIntegrationTest { + * @ClusterTest(brokers = 1, controllers = 1, clusterType = ClusterType.Both) + * def someTest(): Unit = { + * assertTrue(condition) + * } + * } + * </pre> + * + * will generate two invocations of "someTest" (since ClusterType.Both was given). For each invocation, the test class + * SomeIntegrationTest will be instantiated, lifecycle methods (before/after) will be run, and "someTest" will be invoked. + * + **/ +public class ClusterForEach implements TestTemplateInvocationContextProvider { Review comment: Wonder if the name could be improved. It's boring, but how about `ClusterTestExtensions`? ```scala @ExtendWith(Array(classOf[ClusterTestExtensions])) class SomeIntegrationTest ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org