Class MongoDbShardedCluster

java.lang.Object
io.debezium.testing.testcontainers.MongoDbShardedCluster
All Implemented Interfaces:
MongoDbDeployment, AutoCloseable, org.testcontainers.lifecycle.Startable

public class MongoDbShardedCluster extends Object implements MongoDbDeployment
A MongoDB sharded cluster.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • shardCount

      private final int shardCount
    • replicaCount

      private final int replicaCount
    • routerCount

      private final int routerCount
    • network

      private final org.testcontainers.containers.Network network
    • portResolver

      private final PortResolver portResolver
    • configServers

      private final MongoDbReplicaSet configServers
    • shards

      private final List<MongoDbReplicaSet> shards
    • routers

      private final List<MongoDbContainer> routers
    • imageName

      private final org.testcontainers.utility.DockerImageName imageName
    • started

      private volatile boolean started
  • Constructor Details

  • Method Details

    • shardedCluster

      public static MongoDbShardedCluster.Builder shardedCluster()
    • start

      public void start()
      Specified by:
      start in interface org.testcontainers.lifecycle.Startable
    • stop

      public void stop()
      Specified by:
      stop in interface org.testcontainers.lifecycle.Startable
    • size

      public int size()
    • getConnectionString

      public String getConnectionString()
      Specified by:
      getConnectionString in interface MongoDbDeployment
      Returns:
      the standard connection string to the sharded cluster, comprised of only the mongos hosts.
    • getShard

      public MongoDbReplicaSet getShard(int i)
    • enableSharding

      public void enableSharding(String databaseName)
    • shardCollection

      public void shardCollection(String databaseName, String collectionName, String keyField)
    • createShards

      private List<MongoDbReplicaSet> createShards()
    • createShard

      private MongoDbReplicaSet createShard(int i)
    • createConfigServers

      private MongoDbReplicaSet createConfigServers()
    • createRouters

      private List<MongoDbContainer> createRouters()
    • createRouter

      private MongoDbContainer createRouter(org.testcontainers.containers.Network network, int i)
    • addShard

      public void addShard()
      Invokes sh.addShard on a router to add a new shard replica set to the sharded cluster.
    • removeShard

      public void removeShard()
      Invokes the removeShard command to remove the last added shard from the sharded cluster.

      Waits until the state of the shard is completed before shutting down the shard replica set.

    • addShards

      private void addShards()
      Adds the previously created and started shards to the shards to the cluster.
    • addShard

      private void addShard(MongoDbReplicaSet shard)
      Adds the previously created and started supplied shard to the cluster.
      Parameters:
      shard - the shard to add
    • stream

      private Stream<org.testcontainers.lifecycle.Startable> stream()
    • getHostNames

      public List<String> getHostNames()
    • formatReplicaSetAddress

      private static String formatReplicaSetAddress(MongoDbReplicaSet replicaSet, boolean namedAddress)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • stream

      private static <T> Stream<T> stream(Iterable<T> iterable)