Package io.strimzi.test.container
Class StrimziKafkaContainer
java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<StrimziKafkaContainer>
io.strimzi.test.container.StrimziKafkaContainer
- All Implemented Interfaces:
KafkaContainer,AutoCloseable,org.junit.rules.TestRule,org.testcontainers.containers.Container<StrimziKafkaContainer>,org.testcontainers.containers.ContainerState,org.testcontainers.containers.traits.LinkableContainer,org.testcontainers.containers.wait.strategy.WaitStrategyTarget,org.testcontainers.lifecycle.Startable
@Deprecated
public class StrimziKafkaContainer
extends org.testcontainers.containers.GenericContainer<StrimziKafkaContainer>
implements KafkaContainer
Deprecated.
StrimziKafkaContainer is a single-node instance of Kafka using the image from quay.io/strimzi/kafka with the
given version.
Optionally, you can configure a
Optionally, you can configure a
proxyContainer to simulate network conditions (i.e. connection cut, latency).
This class uses getBootstrapServers() to build the KAFKA_ADVERTISED_LISTENERS configuration.
When proxyContainer is configured, the bootstrap URL returned by getBootstrapServers() contains the proxy host and port.
For this reason, Kafka clients will always pass through the proxy, even after refreshing cluster metadata.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated.Default Kafka controller portstatic final intDeprecated.Default Kafka portstatic final StringDeprecated.The file containing the startup script.Fields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, INTERNAL_HOST_HOSTNAMEFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Image name is specified lazily automatically indoStart()methodStrimziKafkaContainer(String dockerImageName) Deprecated.Image name is specified bydockerImageName -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Deprecated.Retrieves the bootstrap controllers URL for admin clients that need to connect to controllers.Deprecated.Retrieves the bootstrap servers URL for Kafka clients.Deprecated.Deprecated.Deprecated.Get the cluster id.Deprecated.Get the bootstrap controllers that containers on the same network should use to connect to controllersDeprecated.Get the bootstrap servers that containers on the same network should use to connectio.strimzi.test.container.KafkaNodeRoleDeprecated.Gets the node role for this Kafka container.Deprecated.eu.rekawek.toxiproxy.ProxygetProxy()Deprecated.Retrieves a synchronized Proxy instance for this Kafka broker.getRealm()Deprecated.Deprecated.Deprecated.Deprecated.booleanDeprecated.Checks if OAuth is enabled.voidstop()Deprecated.Deprecated.Fluent method, which sets a waiting strategy to wait until the node is ready.withAuthenticationType(AuthenticationType authType) Deprecated.Sets the authentication type for the Kafka container.withBootstrapServers(Function<StrimziKafkaContainer, String> provider) Deprecated.Fluent method, assign provider for overriding bootstrap servers stringwithBrokerId(int brokerId) Deprecated.Fluent method, which setsbrokerId.withKafkaConfigurationMap(Map<String, String> kafkaConfigurationMap) Deprecated.Fluent method, which setskafkaConfigurationMap.withKafkaLog(org.apache.logging.log4j.Level level) Deprecated.Configures the Kafka container to use the specified logging level for Kafka logs and theio.strimzilogger.withKafkaVersion(String kafkaVersion) Deprecated.Fluent method, which setskafkaVersion.Deprecated.Fluent method to enable log collection with a default log file path.withLogCollection(String logFilePath) Deprecated.Fluent method to enable log collection for all containers in the cluster with a custom log file path.withNodeId(int nodeId) Deprecated.Fluent method that sets the node ID.withNodeRole(io.strimzi.test.container.KafkaNodeRole nodeRole) Deprecated.Fluent method to set the Kafka node role.withOAuthConfig(String realm, String clientId, String clientSecret, String oauthUri, String usernameClaim) Deprecated.Fluent method to configure OAuth settings.withPort(int fixedPort) Deprecated.Fluent method, which sets fixed exposed port.withProxyContainer(org.testcontainers.containers.ToxiproxyContainer proxyContainer) Deprecated.Fluent method, which sets a proxy container.withSaslPassword(String saslPassword) Deprecated.Fluent method to set the SASL PLAIN mechanism's password.withSaslUsername(String saslUsername) Deprecated.Fluent method to set the SASL PLAIN mechanism's username.withServerProperties(org.testcontainers.utility.MountableFile serverPropertiesFile) Deprecated.Fluent method, copy server properties file to the containerMethods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addLink, apply, copyFileFromContainer, dependsOn, dependsOn, dependsOn, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPortNumbers, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, toString, waitingFor, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunningMethods inherited from interface org.testcontainers.lifecycle.Startable
close, getDependencies, start
-
Field Details
-
STARTER_SCRIPT
Deprecated.The file containing the startup script.- See Also:
-
KAFKA_PORT
public static final int KAFKA_PORTDeprecated.Default Kafka port- See Also:
-
CONTROLLER_PORT
public static final int CONTROLLER_PORTDeprecated.Default Kafka controller port- See Also:
-
-
Constructor Details
-
StrimziKafkaContainer
public StrimziKafkaContainer()Deprecated.Image name is specified lazily automatically indoStart()method -
StrimziKafkaContainer
Deprecated.Image name is specified bydockerImageName- Parameters:
dockerImageName- specific docker image name provided by constructor parameter
-
-
Method Details
-
stop
public void stop()Deprecated.- Specified by:
stopin interfaceorg.testcontainers.lifecycle.Startable- Overrides:
stopin classorg.testcontainers.containers.GenericContainer<StrimziKafkaContainer>
-
waitForRunning
Deprecated.Fluent method, which sets a waiting strategy to wait until the node is ready.This method waits for a log message in the node log. The specific message depends on the node role: - Broker and combined-role nodes wait for "Transitioning from RECOVERY to RUNNING" - Controller-only nodes wait for "Kafka Server started" You can customize the strategy using
GenericContainer.waitingFor(WaitStrategy).- Returns:
- StrimziKafkaContainer instance
-
getBootstrapServers
Deprecated.Retrieves the bootstrap servers URL for Kafka clients.- Specified by:
getBootstrapServersin interfaceKafkaContainer- Returns:
- the bootstrap servers URL
-
getNetworkBootstrapServers
Deprecated.Get the bootstrap servers that containers on the same network should use to connect- Returns:
- a comma separated list of Kafka bootstrap servers
-
getBootstrapControllers
Deprecated.Retrieves the bootstrap controllers URL for admin clients that need to connect to controllers. This is required for certain admin operations in KRaft mode, such as describing the cluster or performing controller-specific operations.- Specified by:
getBootstrapControllersin interfaceKafkaContainer- Returns:
- the bootstrap controllers URL
- Throws:
UnsupportedOperationException- if this node doesn't have controller role
-
getNetworkBootstrapControllers
Deprecated.Get the bootstrap controllers that containers on the same network should use to connect to controllers- Returns:
- a comma separated list of Kafka controller endpoints
- Throws:
UnsupportedOperationException- if this node doesn't have controller role
-
getClusterId
Deprecated.Get the cluster id. This is only supported for KRaft containers.- Returns:
- The cluster id.
-
withKafkaConfigurationMap
Deprecated.Fluent method, which setskafkaConfigurationMap.- Parameters:
kafkaConfigurationMap- kafka configuration- Returns:
- StrimziKafkaContainer instance
-
withBrokerId
Deprecated.Fluent method, which setsbrokerId.- Parameters:
brokerId- broker id- Returns:
- StrimziKafkaContainer instance
-
withNodeId
Deprecated.Fluent method that sets the node ID.- Parameters:
nodeId- the node ID- Returns:
StrimziKafkaContainerinstance
-
withKafkaVersion
Deprecated.Fluent method, which setskafkaVersion.- Parameters:
kafkaVersion- kafka version- Returns:
- StrimziKafkaContainer instance
-
withPort
Deprecated.Fluent method, which sets fixed exposed port.- Parameters:
fixedPort- fixed port to expose- Returns:
- StrimziKafkaContainer instance
-
withServerProperties
public StrimziKafkaContainer withServerProperties(org.testcontainers.utility.MountableFile serverPropertiesFile) Deprecated.Fluent method, copy server properties file to the container- Parameters:
serverPropertiesFile- the mountable config file- Returns:
- StrimziKafkaContainer instance
-
withBootstrapServers
Deprecated.Fluent method, assign provider for overriding bootstrap servers string- Parameters:
provider- provider function for bootstrapServers string- Returns:
- StrimziKafkaContainer instance
-
withProxyContainer
public StrimziKafkaContainer withProxyContainer(org.testcontainers.containers.ToxiproxyContainer proxyContainer) Deprecated.Fluent method, which sets a proxy container. This container allows to create a TCP proxy between test code and Kafka broker. Every Kafka broker request will pass through the proxy where you can simulate network conditions (i.e. connection cut, latency).- Parameters:
proxyContainer- Proxy container- Returns:
- StrimziKafkaContainer instance
-
withOAuthConfig
public StrimziKafkaContainer withOAuthConfig(String realm, String clientId, String clientSecret, String oauthUri, String usernameClaim) Deprecated.Fluent method to configure OAuth settings.- Parameters:
realm- the realmclientId- the OAuth client IDclientSecret- the OAuth client secretoauthUri- the OAuth URIusernameClaim- the preferred username claim for OAuth- Returns:
StrimziKafkaContainerinstance
-
withAuthenticationType
Deprecated.Sets the authentication type for the Kafka container.- Parameters:
authType- The authentication type to enable.- Returns:
- StrimziKafkaContainer instance for method chaining.
-
withSaslUsername
Deprecated.Fluent method to set the SASL PLAIN mechanism's username.- Parameters:
saslUsername- The desired SASL username.- Returns:
- StrimziKafkaContainer instance for method chaining.
-
withSaslPassword
Deprecated.Fluent method to set the SASL PLAIN mechanism's password.- Parameters:
saslPassword- The desired SASL password.- Returns:
- StrimziKafkaContainer instance for method chaining.
-
withNodeRole
Deprecated.Fluent method to set the Kafka node role.- Parameters:
nodeRole- the role this node should play in the cluster- Returns:
- StrimziKafkaContainer instance for method chaining
-
withKafkaLog
Deprecated.Configures the Kafka container to use the specified logging level for Kafka logs and theio.strimzilogger.This method generates a custom
Example Usage:log4j2.yamlfile with the desired logging level and copies it into the Kafka container. By setting the logging level, you can control the verbosity of Kafka's log output, which is useful for debugging or monitoring purposes.StrimziKafkaContainer kafkaContainer = new StrimziKafkaContainer() .withKafkaLog(Level.DEBUG) .start();- Parameters:
level- the desiredLevelof logging (e.g., DEBUG, INFO, WARN, ERROR)- Returns:
- the current instance of
StrimziKafkaContainerfor method chaining
-
withLogCollection
Deprecated.Fluent method to enable log collection with a default log file path. The actual filename is determined at runtime when logs are collected.- Returns:
- StrimziKafkaContainer instance for method chaining
-
withLogCollection
Deprecated.Fluent method to enable log collection for all containers in the cluster with a custom log file path. If the path ends with "/", role-based filenames are automatically appended at runtime for each container: Controller-only: "kafka-controller-{nodeId}.log" Broker-only: "kafka-broker-{brokerId}.log" Combined: "kafka-container-{brokerId}.log" otherwise, the path doesn't end with "/", it's used as the exact filename base for all containers- Parameters:
logFilePath- the base path where container logs will be saved. Use "/" suffix for automatic role-based naming.- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
getProxy
public eu.rekawek.toxiproxy.Proxy getProxy()Deprecated.Retrieves a synchronized Proxy instance for this Kafka broker. This method ensures that only one instance of Proxy is created per broker. If the proxy has not been initialized, it attempts to create one using the Toxiproxy client. If the Toxiproxy client is not initialized, it is created using the host and control port of the proxy container.- Returns:
- Proxy instance for this Kafka broker.
- Throws:
IllegalStateException- if the proxy container has not been configured.RuntimeException- if an IOException occurs during the creation of the Proxy.
-
isOAuthEnabled
public boolean isOAuthEnabled()Deprecated.Checks if OAuth is enabled.- Returns:
trueif OAuth is enabled;falseotherwise
-
getSaslUsername
Deprecated. -
getSaslPassword
Deprecated. -
getRealm
Deprecated. -
getClientId
Deprecated. -
getClientSecret
Deprecated. -
getOauthUri
Deprecated. -
getUsernameClaim
Deprecated. -
getAuthenticationType
Deprecated. -
getNodeRole
public io.strimzi.test.container.KafkaNodeRole getNodeRole()Deprecated.Gets the node role for this Kafka container.- Returns:
- the node role
-
StrimziKafkaClusterinstead, which provides better multi-node support and more comprehensive cluster management capabilities.