1
- package org .testcontainers .containers ;
1
+ package org .testcontainers .oceanbase ;
2
2
3
3
import org .apache .commons .lang3 .StringUtils ;
4
+ import org .testcontainers .containers .JdbcDatabaseContainer ;
4
5
import org .testcontainers .utility .DockerImageName ;
5
6
6
7
/**
7
- * Testcontainers implementation for OceanBase.
8
+ * Testcontainers implementation for OceanBase Community Edition .
8
9
* <p>
9
10
* Supported image: {@code oceanbase/oceanbase-ce}
10
11
* <p>
14
15
* <li>RPC: 2882</li>
15
16
* </ul>
16
17
*/
17
- public class OceanBaseContainer extends JdbcDatabaseContainer <OceanBaseContainer > {
18
+ public class OceanBaseCEContainer extends JdbcDatabaseContainer <OceanBaseCEContainer > {
18
19
19
- static final String NAME = "oceanbase " ;
20
+ static final String NAME = "oceanbasece " ;
20
21
21
22
static final String DOCKER_IMAGE_NAME = "oceanbase/oceanbase-ce" ;
22
23
23
24
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName .parse (DOCKER_IMAGE_NAME );
24
25
25
26
private static final Integer SQL_PORT = 2881 ;
27
+
26
28
private static final Integer RPC_PORT = 2882 ;
27
29
28
30
private static final String SYSTEM_TENANT_NAME = "sys" ;
29
- private static final String DEFAULT_TEST_TENANT_NAME = "test" ;
31
+
30
32
private static final String DEFAULT_USERNAME = "root" ;
33
+
31
34
private static final String DEFAULT_PASSWORD = "" ;
35
+
32
36
private static final String DEFAULT_DATABASE_NAME = "test" ;
33
37
34
- private boolean enableFastboot ;
35
- private String mode ;
36
- private String tenantName = DEFAULT_TEST_TENANT_NAME ;
38
+ private String tenantName = "test" ;
39
+
37
40
private String driverClassName = "com.mysql.cj.jdbc.Driver" ;
38
41
39
- public OceanBaseContainer (String dockerImageName ) {
42
+ public OceanBaseCEContainer (String dockerImageName ) {
40
43
this (DockerImageName .parse (dockerImageName ));
41
44
}
42
45
43
- public OceanBaseContainer (DockerImageName dockerImageName ) {
46
+ public OceanBaseCEContainer (DockerImageName dockerImageName ) {
44
47
super (dockerImageName );
45
48
dockerImageName .assertCompatibleWith (DEFAULT_IMAGE_NAME );
46
49
@@ -83,34 +86,13 @@ protected String getTestQueryString() {
83
86
return "SELECT 1" ;
84
87
}
85
88
86
- /**
87
- * Enable fastboot.
88
- *
89
- * @return this
90
- */
91
- public OceanBaseContainer enableFastboot () {
92
- this .enableFastboot = true ;
93
- return self ();
94
- }
95
-
96
- /**
97
- * Set the deployment mode, see <a href="https://hub.docker.com/r/oceanbase/oceanbase-ce">Docker Hub</a> for more details.
98
- *
99
- * @param mode the deployment mode
100
- * @return this
101
- */
102
- public OceanBaseContainer withMode (String mode ) {
103
- this .mode = mode ;
104
- return self ();
105
- }
106
-
107
89
/**
108
90
* Set the non-system tenant to be created for testing.
109
91
*
110
92
* @param tenantName the name of tenant to be created
111
93
* @return this
112
94
*/
113
- public OceanBaseContainer withTenant (String tenantName ) {
95
+ public OceanBaseCEContainer withTenant (String tenantName ) {
114
96
if (StringUtils .isEmpty (tenantName )) {
115
97
throw new IllegalArgumentException ("Tenant name cannot be null or empty" );
116
98
}
@@ -127,32 +109,19 @@ public OceanBaseContainer withTenant(String tenantName) {
127
109
* @param driverClassName the driver class name
128
110
* @return this
129
111
*/
130
- public OceanBaseContainer withDriverClassName (String driverClassName ) {
112
+ public OceanBaseCEContainer withDriverClassName (String driverClassName ) {
131
113
if (StringUtils .isEmpty (driverClassName )) {
132
114
throw new IllegalArgumentException ("Driver class name cannot be null or empty" );
133
115
}
134
116
if (!driverClassName .contains ("mysql" ) && !driverClassName .contains ("oceanbase" )) {
135
117
throw new IllegalArgumentException ("Driver class name should contains 'mysql' or 'oceanbase'" );
136
118
}
137
- try {
138
- Class .forName (driverClassName );
139
- } catch (ClassNotFoundException e ) {
140
- throw new IllegalArgumentException ("Driver class not found" , e );
141
- }
142
119
this .driverClassName = driverClassName ;
143
120
return self ();
144
121
}
145
122
146
123
@ Override
147
124
protected void configure () {
148
- if (StringUtils .isNotBlank (mode )) {
149
- withEnv ("MODE" , mode );
150
- }
151
- if (enableFastboot ) {
152
- withEnv ("FASTBOOT" , "true" );
153
- }
154
- if (!DEFAULT_TEST_TENANT_NAME .equals (tenantName )) {
155
- withEnv ("OB_TENANT_NAME" , tenantName );
156
- }
125
+ withEnv ("OB_TENANT_NAME" , tenantName );
157
126
}
158
127
}
0 commit comments