Class StrimziKafkaCluster.StrimziKafkaClusterBuilder

java.lang.Object
io.strimzi.test.container.StrimziKafkaCluster.StrimziKafkaClusterBuilder
Enclosing class:
StrimziKafkaCluster

public static class StrimziKafkaCluster.StrimziKafkaClusterBuilder extends Object
Builder class for StrimziKafkaCluster.

Use this builder to create instances of StrimziKafkaCluster with customized configurations.

  • Constructor Details

    • StrimziKafkaClusterBuilder

      public StrimziKafkaClusterBuilder()
  • Method Details

    • withNumberOfBrokers

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withNumberOfBrokers(int brokersNum)
      Sets the number of Kafka brokers in the cluster.
      Parameters:
      brokersNum - the number of Kafka brokers
      Returns:
      the current instance of StrimziConnectClusterBuilder for method chaining
    • withInternalTopicReplicationFactor

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withInternalTopicReplicationFactor(int internalTopicReplicationFactor)
      Sets the internal topic replication factor for Kafka brokers. If not provided, it defaults to the number of brokers.
      Parameters:
      internalTopicReplicationFactor - the replication factor for internal topics
      Returns:
      the current instance of StrimziConnectClusterBuilder for method chaining
    • withAdditionalKafkaConfiguration

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withAdditionalKafkaConfiguration(Map<String,String> additionalKafkaConfiguration)
      Adds additional Kafka configuration parameters. These configurations are applied to all brokers in the cluster.
      Parameters:
      additionalKafkaConfiguration - a map of additional Kafka configuration options
      Returns:
      the current instance of StrimziConnectClusterBuilder for method chaining
    • withProxyContainer

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withProxyContainer(org.testcontainers.toxiproxy.ToxiproxyContainer proxyContainer)
      Sets a ToxiproxyContainer to simulate network conditions such as latency or disconnection.
      Parameters:
      proxyContainer - the proxy container for simulating network conditions
      Returns:
      the current instance of StrimziConnectClusterBuilder for method chaining
    • withSharedNetwork

      Enables a shared Docker network for the Kafka cluster. This allows the Kafka cluster to interact with other containers on the same network.
      Returns:
      the current instance of StrimziConnectClusterBuilder for method chaining
    • withKafkaVersion

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withKafkaVersion(String kafkaVersion)
      Specifies the Kafka version to be used for the brokers in the cluster. If no version is provided, the latest Kafka version available from KafkaVersionService will be used.
      Parameters:
      kafkaVersion - the desired Kafka version for the cluster
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withImage

      Specifies a custom Docker image to be used for the Kafka brokers in the cluster. This allows using custom Kafka images instead of the default Strimzi test container images.

      When this is set, the image specified here takes precedence over the version-based image selection.

      Parameters:
      kafkaImage - the full Docker image name
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
      Throws:
      IllegalArgumentException - if the image name is null or empty
    • withDedicatedRoles

      Configures the cluster to use dedicated controller and broker nodes instead of combined-role nodes. When enabled, you must also specify the number of controllers using withNumberOfControllers(int).
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withNumberOfControllers

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withNumberOfControllers(int controllersNum)
      Sets the number of dedicated controller nodes when using combined roles. This method should be used in conjunction with withDedicatedRoles().
      Parameters:
      controllersNum - the number of dedicated controller nodes
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withLogCollection

      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

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withLogCollection(String logFilePath)
      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-{nodeId}.log" Combined: "kafka-container-{nodeId}.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 StrimziKafkaClusterBuilder for method chaining
    • withPort

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withPort(int fixedPort)
      Sets a fixed exposed port for all broker nodes in the cluster.

      Note: When using multiple brokers, each broker needs a unique port. The first broker will use the specified port, and subsequent brokers will use incrementing port numbers (e.g., if port 9092 is specified for a 3-broker cluster, the brokers will use ports 9092, 9093, and 9094).

      Parameters:
      fixedPort - the base fixed port to expose for the first broker
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
      Throws:
      IllegalArgumentException - if the port is less than or equal to 0
    • withBootstrapServers

      Assigns a provider function for overriding the bootstrap servers string for all broker nodes.

      This is useful when you need to customize how the bootstrap servers address is generated, for example when using a shared network with specific hostnames.

      Parameters:
      provider - a function that takes a GenericContainer and returns the bootstrap servers string
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withContainerCustomizer

      Assigns a customizer function to modify each Kafka container after its creation. This allows for additional configurations or adjustments to be applied to each container.
      Parameters:
      customizer - a consumer that takes a GenericContainer for customization
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withOAuthConfig

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withOAuthConfig(String realm, String clientId, String clientSecret, String oauthUri, String usernameClaim)
      Configures OAuth settings for all nodes in the cluster.
      Parameters:
      realm - the OAuth realm name
      clientId - the OAuth client ID
      clientSecret - the OAuth client secret
      oauthUri - the OAuth server URI
      usernameClaim - the claim to use for the username
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withAuthenticationType

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withAuthenticationType(AuthenticationType authType)
      Sets the authentication type for all nodes in the cluster.
      Parameters:
      authType - the authentication type to enable
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
    • withSaslUsername

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withSaslUsername(String saslUsername)
      Sets the SASL username for OAuth over PLAIN authentication.
      Parameters:
      saslUsername - the SASL username
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
      Throws:
      IllegalArgumentException - if the username is null or empty
    • withSaslPassword

      public StrimziKafkaCluster.StrimziKafkaClusterBuilder withSaslPassword(String saslPassword)
      Sets the SASL password for OAuth over PLAIN authentication.
      Parameters:
      saslPassword - the SASL password
      Returns:
      the current instance of StrimziKafkaClusterBuilder for method chaining
      Throws:
      IllegalArgumentException - if the password is null or empty
    • build

      public StrimziKafkaCluster build()
      Builds and returns a StrimziKafkaCluster instance based on the provided configurations.
      Returns:
      a new instance of StrimziKafkaCluster