Skip to content

Commit b5649c4

Browse files
committed
update OceanBaseCEContainer for new image
1 parent 181b56e commit b5649c4

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
lines changed

docs/modules/databases/jdbc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database
5757

5858
#### Using OceanBase
5959

60-
`jdbc:tc:oceanbasece:4.2.2:///databasename`
60+
`jdbc:tc:oceanbasece:4.2.1-lts:///databasename`
6161

6262
#### Using Oracle
6363

modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainer.java

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.testcontainers.oceanbase;
22

33
import org.testcontainers.containers.JdbcDatabaseContainer;
4+
import org.testcontainers.containers.wait.strategy.Wait;
45
import org.testcontainers.utility.DockerImageName;
56

67
/**
@@ -26,14 +27,54 @@ public class OceanBaseCEContainer extends JdbcDatabaseContainer<OceanBaseCEConta
2627

2728
private static final Integer RPC_PORT = 2882;
2829

29-
private static final String DEFAULT_TEST_TENANT_NAME = "test";
30+
private static final String DEFAULT_USER_TENANT_NAME = "test";
3031

31-
private static final String DEFAULT_USERNAME = "root";
32+
private static final String DEFAULT_USER = "root";
3233

3334
private static final String DEFAULT_PASSWORD = "";
3435

3536
private static final String DEFAULT_DATABASE_NAME = "test";
3637

38+
public enum Mode {
39+
/**
40+
* Use as much hardware resources as possible for deployment by default,
41+
* and all environment variables are available.
42+
*/
43+
NORMAL,
44+
/**
45+
* Use the minimum hardware resources for deployment by default,
46+
* and all environment variables are available.
47+
*/
48+
MINI,
49+
/**
50+
* Use minimal hardware resources and pre-built deployment files for quick startup,
51+
* and password of user tenant is the only available environment variable.
52+
*/
53+
SLIM;
54+
55+
public static Mode fromString(String mode) {
56+
if (mode == null) {
57+
throw new IllegalArgumentException("Mode cannot be null");
58+
}
59+
switch (mode.toUpperCase()) {
60+
case "NORMAL":
61+
return NORMAL;
62+
case "MINI":
63+
return MINI;
64+
case "SLIM":
65+
return SLIM;
66+
default:
67+
throw new IllegalArgumentException("Unknown mode: " + mode);
68+
}
69+
}
70+
}
71+
72+
private Mode mode = Mode.SLIM;
73+
74+
private String tenantName = DEFAULT_USER_TENANT_NAME;
75+
76+
private String password = DEFAULT_PASSWORD;
77+
3778
public OceanBaseCEContainer(String dockerImageName) {
3879
this(DockerImageName.parse(dockerImageName));
3980
}
@@ -43,6 +84,28 @@ public OceanBaseCEContainer(DockerImageName dockerImageName) {
4384
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
4485

4586
addExposedPorts(SQL_PORT, RPC_PORT);
87+
setWaitStrategy(Wait.forLogMessage(".*boot success!.*", 1));
88+
}
89+
90+
@Override
91+
protected void configure() {
92+
addEnv("MODE", mode.name().toLowerCase());
93+
94+
if (!DEFAULT_USER_TENANT_NAME.equals(tenantName)) {
95+
if (mode == Mode.SLIM) {
96+
throw new IllegalArgumentException("Tenant name is not configurable on slim mode");
97+
}
98+
addEnv("OB_TENANT_NAME", tenantName);
99+
}
100+
101+
if (!DEFAULT_PASSWORD.equals(password)) {
102+
addEnv("OB_TENANT_PASSWORD", password);
103+
}
104+
}
105+
106+
@Override
107+
protected void waitUntilContainerStarted() {
108+
getWaitStrategy().waitUntilReady(this);
46109
}
47110

48111
@Override
@@ -64,19 +127,31 @@ public String getDatabaseName() {
64127

65128
@Override
66129
public String getUsername() {
67-
// In OceanBase, the jdbc username is related to the name of user, tenant and cluster,
68-
// if a tenant name other than the default value 'test' is used, you should manually
69-
// construct the jdbc username by yourself.
70-
return DEFAULT_USERNAME + "@" + DEFAULT_TEST_TENANT_NAME;
130+
return DEFAULT_USER + "@" + tenantName;
71131
}
72132

73133
@Override
74134
public String getPassword() {
75-
return DEFAULT_PASSWORD;
135+
return password;
76136
}
77137

78138
@Override
79139
protected String getTestQueryString() {
80140
return "SELECT 1";
81141
}
142+
143+
public OceanBaseCEContainer withMode(String mode) {
144+
this.mode = Mode.fromString(mode);
145+
return this;
146+
}
147+
148+
public OceanBaseCEContainer withTenantName(String tenantName) {
149+
this.tenantName = tenantName;
150+
return this;
151+
}
152+
153+
public OceanBaseCEContainer withPassword(String password) {
154+
this.password = password;
155+
return this;
156+
}
82157
}

modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class OceanBaseCEContainerProvider extends JdbcDatabaseContainerProvider {
1111

12-
private static final String DEFAULT_TAG = "4.2.2";
12+
private static final String DEFAULT_TAG = "4.2.1-lts";
1313

1414
@Override
1515
public boolean supports(String databaseType) {

modules/oceanbase/src/test/java/org/testcontainers/oceanbase/SimpleOceanBaseCETest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public class SimpleOceanBaseCETest extends AbstractContainerDatabaseTest {
1919

2020
@SuppressWarnings("resource")
2121
private OceanBaseCEContainer testContainer() {
22-
return ((OceanBaseCEContainer) containerProvider.newInstance()).withEnv("MODE", "slim")
23-
.withEnv("FASTBOOT", "true")
24-
.withLogConsumer(new Slf4jLogConsumer(logger));
22+
return ((OceanBaseCEContainer) containerProvider.newInstance()).withLogConsumer(new Slf4jLogConsumer(logger));
2523
}
2624

2725
@Test

0 commit comments

Comments
 (0)