Class ShardingConfiguration

java.lang.Object
org.citrusframework.sharding.ShardingConfiguration

public final class ShardingConfiguration extends Object
A configuration class for sharded test loading and execution withing the citrus framework. It uses environment variables and system properties to configure the sharding behavior.

This class is part of the Citrus framework, designed to streamline the process of sharding test cases for efficient and scalable testing.

Configuration Example:

To configure the sharding behavior, set the following environment variables or system properties:

  • Total number of shards:
    • Environment Variable: CITRUS_SHARDING_TOTAL
    • System Property: citrus.sharding.total
    • Description: Specifies the total number of shards into which the test cases will be divided.
  • Shard number:
    • Environment Variable: CITRUS_SHARDING_NUMBER
    • System Property: citrus.sharding.number
    • Description: Indicates the specific shard number of the current test loader. This should be a value between 0 and the total number of shards minus one.
  • Shard seed:
    • Environment Variable: CITRUS_SHARDING_SEED
    • System Property: citrus.sharding.seed
    • Description: Specifies a seed value used for shuffling test cases within a shard. Providing a consistent seed value ensures the same shuffling order across different executions.

Example Usage:

To configure a system with 4 total shards and assign this instance to shard number 1 (second shard, since numbering starts at 0), set the environment variables or system properties as follows:

  • Set CITRUS_SHARDING_TOTAL or citrus.sharding.total to 4.
  • Set CITRUS_SHARDING_NUMBER or citrus.sharding.number to 1.
  • Optionally, set a seed for shuffling test cases using CITRUS_SHARDING_SEED or citrus.sharding.seed. The total number of shards will be used as see by default.
See Also:
  • Field Details

    • TOTAL_SHARD_NUMBER_PROPERTY_NAME

      public static final String TOTAL_SHARD_NUMBER_PROPERTY_NAME
      See Also:
    • TOTAL_SHARD_NUMBER_ENV_VAR_NAME

      public static final String TOTAL_SHARD_NUMBER_ENV_VAR_NAME
    • SHARD_NUMBER_PROPERTY_NAME

      public static final String SHARD_NUMBER_PROPERTY_NAME
      See Also:
    • SHARD_NUMBER_ENV_VAR_NAME

      public static final String SHARD_NUMBER_ENV_VAR_NAME
    • SHARD_SEED_PROPERTY_NAME

      public static final String SHARD_SEED_PROPERTY_NAME
      See Also:
    • SHARD_SEED_ENV_VAR_NAME

      public static final String SHARD_SEED_ENV_VAR_NAME
  • Constructor Details

    • ShardingConfiguration

      public ShardingConfiguration()
      Default sharding configuration which initializes the sharding with system properties and environment variables.
    • ShardingConfiguration

      protected ShardingConfiguration(SystemProvider systemProvider)
      Constructor that allows for injecting a custom SystemProvider. This is primarily intended for testing purposes, enabling the mocking and overriding of system environment and properties.
      Parameters:
      systemProvider - a provider for system environment variables and properties.
    • ShardingConfiguration

      public ShardingConfiguration(int totalNumberOfShards, int shardNumber)
      Create a new sharding configuration with explicit total number of shards and shard number.
      Parameters:
      totalNumberOfShards - the total number of shards to be used.
      shardNumber - the specific shard number for this loader, zero-based.
    • ShardingConfiguration

      protected ShardingConfiguration(int totalNumberOfShards, int shardNumber, SystemProvider systemProvider)
      Constructor that sets the total number of shards, shard number, and allows for injecting a custom SystemProvider. Primarily used for testing purposes.
      Parameters:
      totalNumberOfShards - the total number of shards.
      shardNumber - the shard number for this loader, zero-based.
      systemProvider - a provider for system environment variables and properties.
  • Method Details

    • getTotalNumberOfShards

      public int getTotalNumberOfShards()
    • getShardNumber

      public int getShardNumber()
    • getSeed

      public int getSeed()