Class ClusterTestExtensions
java.lang.Object
org.apache.kafka.common.test.junit.ClusterTestExtensions
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
public class ClusterTestExtensions
extends Object
implements org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
This class is a custom JUnit extension that will generate some number of test invocations depending on the processing
of 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:
ClusterTest, define a single cluster configurationClusterTests, provide multiple instances of @ClusterTestClusterTemplate, define a static method that generates cluster configurations
ClusterConfig will be
generated. Each ClusterConfig is used to create an underlying Kafka cluster that is used for the actual test
invocation.
For example:
class SomeIntegrationTest {
@ClusterTest(brokers = 1, controllers = 1, types = {Type.KRAFT, Type.CO_KRAFT})
void someTest(ClusterInstance cluster) {
assertTrue(condition)
}
}
will generate two invocations of "someTest" (since two cluster types were specified). For each invocation, the test class
SomeIntegrationTest will be instantiated, lifecycle methods (before/after) will be run, and "someTest" will be invoked.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) booleanmayReturnZeroTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) Indicates whether this provider may return zero test template invocation contexts.Stream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) booleansupportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext context)
-
Constructor Details
-
ClusterTestExtensions
public ClusterTestExtensions()
-
-
Method Details
-
supportsTestTemplate
public boolean supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
supportsTestTemplatein interfaceorg.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
-
mayReturnZeroTestTemplateInvocationContexts
public boolean mayReturnZeroTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) Indicates whether this provider may return zero test template invocation contexts. Prior to JUnit 5.12, returning zero contexts was silently allowed. Starting from JUnit 5.12, a PreconditionViolationException is thrown unless this method explicitly returnstrue.- Specified by:
mayReturnZeroTestTemplateInvocationContextsin interfaceorg.junit.jupiter.api.extension.TestTemplateInvocationContextProvider- Parameters:
context- the extension context for the test template method- Returns:
trueto allow this provider to return zero invocation contexts- See Also:
-
provideTestTemplateInvocationContexts
public Stream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
provideTestTemplateInvocationContextsin interfaceorg.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback
-