Class TestClusterBuilder

java.lang.Object
io.camunda.zeebe.qa.util.cluster.TestClusterBuilder

public final class TestClusterBuilder extends Object
  • Constructor Details

    • TestClusterBuilder

      public TestClusterBuilder()
  • Method Details

    • withEmbeddedGateway

      public TestClusterBuilder withEmbeddedGateway(boolean useEmbeddedGateway)
      If true, the brokers created by this cluster will use embedded gateways. By default this is true.
      Parameters:
      useEmbeddedGateway - true or false to enable the embedded gateway on the brokers
      Returns:
      this builder instance for chaining
    • withGatewaysCount

      public TestClusterBuilder withGatewaysCount(int gatewaysCount)
      The number of standalone gateway to create in this cluster. By default, this is 0, and the brokers have embedded gateways.

      Note that this parameter has no impact on the use of embedded gateways, and a cluster can contain both standalone and embedded gateways.

      Parameters:
      gatewaysCount - the number of standalone gateways to create
      Returns:
      this builder instance for chaining
    • withBrokersCount

      public TestClusterBuilder withBrokersCount(int brokersCount)
      The number of brokers to create in this cluster. By default, this is 1.

      Note that it's possible to create a cluster with no brokers, as this is could be a valid setup for testing purposes. If that's the case, the gateways will not wait for the topology to be complete (as they cannot know the topology), and will not be configured with a contact point.

      NOTE: setting this to 0 will also set the replication factor and partitions count to 0.

      Parameters:
      brokersCount - the number of brokers to create
      Returns:
      this builder instance for chaining
    • withPartitionsCount

      public TestClusterBuilder withPartitionsCount(int partitionsCount)
      Will set the number of partitions to distribute across the cluster. For example, if there are 3 brokers, 3 partitions, but replication factor of 1, then each broker will get exactly one partition.

      Note that the number of partitions must be greater than or equal to 1! If you do not want to have any brokers, then set withBrokersCount(int) to 0 instead.

      Parameters:
      partitionsCount - the number of partitions to distribute across the cluster
      Returns:
      this builder instance for chaining
    • withReplicationFactor

      public TestClusterBuilder withReplicationFactor(int replicationFactor)
      Sets the replication factor for each partition in the cluster. Note that this cannot be less than 1, or greater than the broker count (see withBrokersCount(int)).
      Parameters:
      replicationFactor - the replication factor for each partition
      Returns:
      this builder instance for chaining
    • withName

      public TestClusterBuilder withName(String name)
      Sets the name of the cluster. This can be used to prevent nodes in one cluster from inadvertently communicating with nodes in another cluster.

      Unless you're deploying multiple clusters in the same network, leave as is.

      Parameters:
      name - the cluster name
      Returns:
      this builder instance for chaining
    • withNodeConfig

      public TestClusterBuilder withNodeConfig(Consumer<TestApplication<?>> modifier)
      Sets the configuration function that will be executed in the build() method on both brokers and gateways (embedded gateways included). NOTE: this configuration has the lowest priority, e.g. other configurations (gatewayConfig or brokerConfig) will override this configuration in case of conflicts.
      Parameters:
      modifier - the function that will be applied on all cluster nodes
      Returns:
      this builder instance for chaining
    • withGatewayConfig

      public TestClusterBuilder withGatewayConfig(BiConsumer<MemberId,TestGateway<?>> modifier)
      Sets the configuration function that will be executed in the build() method on each gateway (including embedded gateways). The first argument of is the member ID of the gateway, and the second argument is the gateway itself.

      NOTE: in case of conflicts with nodeConfig this configuration will override nodeConfig.

      NOTE: in case of conflicts with this configuration is an embedded gateway configuration and a broker configuration, broker configuration will override this configuration.

      Parameters:
      modifier - the function that will be applied on all cluster gateways (embedded ones included)
      Returns:
      this builder instance for chaining
    • withGatewayConfig

      public TestClusterBuilder withGatewayConfig(Consumer<TestGateway<?>> modifier)
      Sets the configuration function that will be executed in the build() method on each gateway (including embedded gateways).

      NOTE: in case of conflicts with nodeConfig this configuration will override nodeConfig.

      NOTE: in case of conflicts with this configuration is an embedded gateway configuration and a broker configuration, broker configuration will override this configuration.

      Parameters:
      modifier - the function that will be applied on all cluster gateways (embedded ones included)
      Returns:
      this builder instance for chaining
    • withBrokerConfig

      public TestClusterBuilder withBrokerConfig(BiConsumer<MemberId,TestStandaloneBroker> modifier)
      Sets the configuration function that will be executed in the build() method on each broker. The first argument is the broker ID, and the second argument is the broker itself.

      NOTE: in case of conflicts with nodeConfig or gatewayConfig this configuration will override them.

      Parameters:
      modifier - the function that will be applied on all cluster brokers
      Returns:
      this builder instance for chaining
    • withBrokerConfig

      public TestClusterBuilder withBrokerConfig(Consumer<TestStandaloneBroker> modifier)
      Sets the configuration function that will be executed in the build() method on each broker.

      NOTE: in case of conflicts with nodeConfig or gatewayConfig this configuration will override them.

      Parameters:
      modifier - the function that will be applied on all cluster brokers
      Returns:
      this builder instance for chaining
    • useRecordingExporter

      public TestClusterBuilder useRecordingExporter(boolean useRecordingExporter)
      If true, registers the RecordingExporter for each broker. Defaults to true.
      Parameters:
      useRecordingExporter - whether to enable the recording exporter
      Returns:
      this builder instance for chaining
    • build

      public TestCluster build()
      Builds a new Zeebe cluster. Will create brokersCount brokers (accessible later via TestCluster.brokers()) and gatewaysCount standalone gateways (accessible later via TestCluster.gateways()).

      If useEmbeddedGateway is true, then all brokers will have the embedded gateway enabled and the right topology check configured. Additionally, TestCluster.gateways() will also include them, along with any other additional standalone gateway.

      For standalone gateways, if brokersCount is at least one, then a random broker is picked as the contact point for all gateways.

      Returns:
      a new Zeebe cluster