[Java] Best practices for continuous-integration testing of TiDB clients?

Application environment:

Continuous integration env. (automated testing, isolated from staging environment) of Java code that would be TiDB clients

TiDB version:

Any

Question:

For automated testing during CI of Java code that would be communicating with TiDB, is there a recommended best practice for deploying and then undeploying a small TiDB cluster? For reference, for MySQL clients, we currently have code based on MariaDB4J combined with Flyway schema management to spin up and shut down a MySQL instance for the duration of a JUnit or TestNG session (or per individual unit test classes, but given the performance cost that would entail it’s not something we do lightly).

Yes, there is a recommended best practice for deploying and undeploying a small TiDB cluster for automated testing during CI of Java code that would be communicating with TiDB.

You can use TiDB Operator to deploy and manage a small TiDB cluster on Kubernetes. TiDB Operator is a Kubernetes operator that manages the lifecycle of TiDB clusters. With TiDB Operator, you can easily create, scale, and delete TiDB clusters on Kubernetes.

To use TiDB Operator for automated testing during CI, you can create a Kubernetes cluster on your CI environment and install TiDB Operator on it. Then, you can use TiDB Operator to create a small TiDB cluster for testing, and delete the cluster after testing is complete.

For more information on how to use TiDB Operator, please refer to the TiDB Operator documentation.

1 Like

Hi, we have several ways to do that. But those ways are JUST for testing, the performance is not very well. If you want to do some performance tests or use TiDB in formal scenarios, please use TiDB cluster or TiDB Cloud.

  • testcontainers-java
    It’s a test container for Java. It has a TiDB module. You can use it to build your unit tests easily.
  • Docker image(pingcap/tidb)
    You can use the docker image too. Only a tidb-server can start, but again, it’s only for tests.
  • TiUP
    If you want a deploy a column-based storage engine, you can use TiUP to deploy a local test cluster.
  • TiDB Cloud Serverless Tier
    It’s free for less than 5GiB storage now, and you can use it to test your application.