Skip to content

Architecture

TDBCluster

The main interface for working with a TarantoolDB cluster within testcontainers is TDBCluster:

«interface»AutoCloseableclose(): void«interface»Startablestop(): voidgetDependencies(): Set<Startable>close(): voidstart(): void«interface»TDBClusterclusterName(): StringtcmContainer(): TCMContainerstorages(): Map<String, TarantoolContainer<?>>etcdContainer(): EtcdContainerrouters(): Map<String, TarantoolContainer<?>>restart(long, TimeUnit): voidnodes(): Map<String, TarantoolContainer<?>>
«interface»AutoCloseableclose(): void«interface»Startablestop(): voidgetDependencies(): Set<Startable>close(): voidstart(): void«interface»TDBClusterclusterName(): StringtcmContainer(): TCMContainerstorages(): Map<String, TarantoolContainer<?>>etcdContainer(): EtcdContainerrouters(): Map<String, TarantoolContainer<?>>restart(long, TimeUnit): voidnodes(): Map<String, TarantoolContainer<?>>

Requirements for Interface Implementations

TDB Cluster Components

Depending on the TarantoolDB(TDB) version, the cluster may contain various components (containers) necessary for its operation:

TDBClusterTarantool NodesRoutersReplicasetsreplicaset-1replicaset-2TarantoolDB 2.x onlyRouter-1Router-2replica-1 (master)replica-2replica-Nreplica-1 (master)replica-2replica-NetcdTCMUsed forinteraction withthe cluster via UI(connection toall cluster nodes)Distributed storageof cluster configuration and migrationsof TarantoolDB.(connection toall cluster nodes)
TDBClusterTarantool NodesRoutersReplicasetsreplicaset-1replicaset-2TarantoolDB 2.x onlyRouter-1Router-2replica-1 (master)replica-2replica-Nreplica-1 (master)replica-2replica-NetcdTCMUsed forinteraction withthe cluster via UI(connection toall cluster nodes)Distributed storageof cluster configuration and migrationsof TarantoolDB.(connection toall cluster nodes)

Restarting the Cluster

Cluster restart is performed using the void restart(long delay, TimeUnit unit) method, where delay is the wait duration, and unit defines the measurement unit of delay. Implementations must ensure that mounted data is preserved when using this method.

Stopping the Cluster

Stopping the cluster with closing all resources is performed using the stop() and close() methods:

import org.junit.Test;
import org.testcontainers.containers.tdb.TDBCluster;
import org.testcontainers.utility.DockerImageName;

public class TestClass {

  @Test
  public void method() {
    final DockerImageName image = DockerImageName.parse("tarantooldb:2.2.1");

    try (TDBCluster cluster = new SomeTDBClusterImplementation()) {
      cluster.start();
      cluster.start(); //valid. idempotency

    } // call `close()` method of AutoCloseable interface
  }
}
import org.junit.Test;
import org.testcontainers.containers.tdb.TDBCluster;
import org.testcontainers.utility.DockerImageName;

public class TestClass {

  @Test
  public void method() {
    final DockerImageName image = DockerImageName.parse("tarantooldb:2.1.1");

    try (TDBCluster cluster = new SomeTDBClusterImplementation()) {
      cluster.start();

      cluster.stop();
      cluster.stop(); // valid. idempotency

      // Uncomment to see the exception
      // cluster.start(); // invalid. Throws `already closed` exception
    }
  }
}

Port Binding

After starting the cluster, each TDBCluster component (containers) is assigned a free external port. Implementations must guarantee that the assigned ports will be retained for containers until the close() or stop() methods are called.