This is an example for testcontainers-java and TiDB.
mvn clean test
- And there is NOT the second step.
------------ TiDB default version ------------
db: test
username: root
password:
jdbc: jdbc:mysql://localhost:56464/test
5.7.25-TiDB-v6.1.1
------------ TiDB v6.2.0 version ------------
db: test
username: root
password:
jdbc: jdbc:mysql://localhost:56470/test
5.7.25-TiDB-v6.2.0
protected ResultSet performQuery(TiDBContainer container, String sql) throws SQLException {
DataSource ds = getDataSource(container);
Statement statement = ds.getConnection().createStatement();
statement.execute(sql);
return statement.getResultSet();
}
protected DataSource getDataSource(TiDBContainer container) throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setURL(container.getJdbcUrl());
dataSource.setUser(container.getUsername());
dataSource.setPassword(container.getPassword());
dataSource.setUseSSL(false);
return dataSource;
}
public void printParticularTiDBVersion() throws SQLException {
// Appoint TiDB version to v6.2.0
try (TiDBContainer tidb62 = new TiDBContainer("pingcap/tidb:v6.2.0")) {
tidb62.start();
System.out.println("------------ TiDB v6.2.0 version ------------");
printTiDBParams(tidb62);
ResultSet rs = performQuery(tidb62, "SELECT VERSION()");
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
}
You can get more information at AppTest.java.