forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleTiDBTest.java
64 lines (50 loc) · 2.13 KB
/
SimpleTiDBTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.testcontainers.junit.tidb;
import org.junit.Test;
import org.testcontainers.TiDBTestImages;
import org.testcontainers.db.AbstractContainerDatabaseTest;
import org.testcontainers.tidb.TiDBContainer;
import java.sql.ResultSet;
import java.sql.SQLException;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleTiDBTest extends AbstractContainerDatabaseTest {
@Test
public void testSimple() throws SQLException {
try (TiDBContainer tidb = new TiDBContainer(TiDBTestImages.TIDB_IMAGE)) {
tidb.start();
ResultSet resultSet = performQuery(tidb, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(tidb);
}
}
@Test
public void testExplicitInitScript() throws SQLException {
try (
TiDBContainer tidb = new TiDBContainer(TiDBTestImages.TIDB_IMAGE).withInitScript("somepath/init_tidb.sql")
) { // TiDB is expected to be compatible with MySQL
tidb.start();
ResultSet resultSet = performQuery(tidb, "SELECT foo FROM bar");
String firstColumnValue = resultSet.getString(1);
assertThat(firstColumnValue).isEqualTo("hello world");
}
}
@Test
public void testWithAdditionalUrlParamInJdbcUrl() {
TiDBContainer tidb = new TiDBContainer(TiDBTestImages.TIDB_IMAGE).withUrlParam("sslmode", "disable");
try {
tidb.start();
String jdbcUrl = tidb.getJdbcUrl();
assertThat(jdbcUrl).contains("?");
assertThat(jdbcUrl).contains("sslmode=disable");
} finally {
tidb.stop();
}
}
private void assertHasCorrectExposedAndLivenessCheckPorts(TiDBContainer tidb) {
Integer tidbPort = 4000;
Integer restApiPort = 10080;
assertThat(tidb.getExposedPorts()).containsExactlyInAnyOrder(tidbPort, restApiPort);
assertThat(tidb.getLivenessCheckPortNumbers())
.containsExactlyInAnyOrder(tidb.getMappedPort(tidbPort), tidb.getMappedPort(restApiPort));
}
}