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" ;
31
+
29
32
private static final String DEFAULT_TEST_TENANT_NAME = "test" ;
33
+
30
34
private static final String DEFAULT_USERNAME = "root" ;
35
+
31
36
private static final String DEFAULT_PASSWORD = "" ;
37
+
32
38
private static final String DEFAULT_DATABASE_NAME = "test" ;
33
39
34
- private boolean enableFastboot ;
35
- private String mode ;
36
40
private String tenantName = DEFAULT_TEST_TENANT_NAME ;
41
+
37
42
private String driverClassName = "com.mysql.cj.jdbc.Driver" ;
38
43
39
- public OceanBaseContainer (String dockerImageName ) {
44
+ public OceanBaseCEContainer (String dockerImageName ) {
40
45
this (DockerImageName .parse (dockerImageName ));
41
46
}
42
47
43
- public OceanBaseContainer (DockerImageName dockerImageName ) {
48
+ public OceanBaseCEContainer (DockerImageName dockerImageName ) {
44
49
super (dockerImageName );
45
50
dockerImageName .assertCompatibleWith (DEFAULT_IMAGE_NAME );
46
51
@@ -83,34 +88,13 @@ protected String getTestQueryString() {
83
88
return "SELECT 1" ;
84
89
}
85
90
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
91
/**
108
92
* Set the non-system tenant to be created for testing.
109
93
*
110
94
* @param tenantName the name of tenant to be created
111
95
* @return this
112
96
*/
113
- public OceanBaseContainer withTenant (String tenantName ) {
97
+ public OceanBaseCEContainer withTenant (String tenantName ) {
114
98
if (StringUtils .isEmpty (tenantName )) {
115
99
throw new IllegalArgumentException ("Tenant name cannot be null or empty" );
116
100
}
@@ -127,30 +111,19 @@ public OceanBaseContainer withTenant(String tenantName) {
127
111
* @param driverClassName the driver class name
128
112
* @return this
129
113
*/
130
- public OceanBaseContainer withDriverClassName (String driverClassName ) {
114
+ public OceanBaseCEContainer withDriverClassName (String driverClassName ) {
131
115
if (StringUtils .isEmpty (driverClassName )) {
132
116
throw new IllegalArgumentException ("Driver class name cannot be null or empty" );
133
117
}
134
118
if (!driverClassName .contains ("mysql" ) && !driverClassName .contains ("oceanbase" )) {
135
119
throw new IllegalArgumentException ("Driver class name should contains 'mysql' or 'oceanbase'" );
136
120
}
137
- try {
138
- Class .forName (driverClassName );
139
- } catch (ClassNotFoundException e ) {
140
- throw new IllegalArgumentException ("Driver class not found" , e );
141
- }
142
121
this .driverClassName = driverClassName ;
143
122
return self ();
144
123
}
145
124
146
125
@ Override
147
126
protected void configure () {
148
- if (StringUtils .isNotBlank (mode )) {
149
- withEnv ("MODE" , mode );
150
- }
151
- if (enableFastboot ) {
152
- withEnv ("FASTBOOT" , "true" );
153
- }
154
127
if (!DEFAULT_TEST_TENANT_NAME .equals (tenantName )) {
155
128
withEnv ("OB_TENANT_NAME" , tenantName );
156
129
}
0 commit comments