-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase CE | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase CE | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase CE | ||
- Oracle Free | ||
- Oracle XE | ||
- OrientDB | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# OceanBase-CE Module | ||
|
||
See [Database containers](./index.md) for documentation and usage that is common to all relational database container types. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
||
=== "Gradle" | ||
```groovy | ||
testImplementation "org.testcontainers:oceanbase-ce:{{latest_version}}" | ||
``` | ||
|
||
=== "Maven" | ||
```xml | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>oceanbase-ce</artifactId> | ||
<version>{{latest_version}}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
``` | ||
|
||
!!! hint | ||
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
description = "Testcontainers :: JDBC :: OceanBase CE" | ||
|
||
dependencies { | ||
api project(':jdbc') | ||
|
||
testImplementation project(':jdbc-test') | ||
testRuntimeOnly 'mysql:mysql-connector-java:8.0.33' | ||
} |
163 changes: 163 additions & 0 deletions
163
modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Testcontainers implementation for OceanBase. | ||
* <p> | ||
* Supported image: {@code oceanbase/oceanbase-ce} | ||
* <p> | ||
* Exposed ports: | ||
* <ul> | ||
* <li>SQL: 2881</li> | ||
* <li>RPC: 2882</li> | ||
* </ul> | ||
*/ | ||
public class OceanBaseContainer extends JdbcDatabaseContainer<OceanBaseContainer> { | ||
|
||
static final String NAME = "oceanbase"; | ||
|
||
static final String DOCKER_IMAGE_NAME = "oceanbase/oceanbase-ce"; | ||
|
||
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(DOCKER_IMAGE_NAME); | ||
|
||
private static final Integer SQL_PORT = 2881; | ||
private static final Integer RPC_PORT = 2882; | ||
|
||
private static final String SYSTEM_TENANT_NAME = "sys"; | ||
private static final String DEFAULT_TEST_TENANT_NAME = "test"; | ||
private static final String DEFAULT_USERNAME = "root"; | ||
private static final String DEFAULT_PASSWORD = ""; | ||
private static final String DEFAULT_DATABASE_NAME = "test"; | ||
|
||
private boolean enableFastboot; | ||
private String mode; | ||
private String tenantName = DEFAULT_TEST_TENANT_NAME; | ||
private String driverClassName = "com.mysql.cj.jdbc.Driver"; | ||
|
||
public OceanBaseContainer(String dockerImageName) { | ||
this(DockerImageName.parse(dockerImageName)); | ||
} | ||
|
||
public OceanBaseContainer(DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
||
addExposedPorts(SQL_PORT, RPC_PORT); | ||
} | ||
|
||
@Override | ||
public Integer getMappedPort(int originalPort) { | ||
return "host".equals(getNetworkMode()) ? originalPort : super.getMappedPort(originalPort); | ||
} | ||
|
||
@Override | ||
public String getDriverClassName() { | ||
return driverClassName; | ||
} | ||
|
||
@Override | ||
public String getJdbcUrl() { | ||
return getJdbcUrl(DEFAULT_DATABASE_NAME); | ||
} | ||
|
||
public String getJdbcUrl(String databaseName) { | ||
String additionalUrlParams = constructUrlParameters("?", "&"); | ||
String prefix = driverClassName.contains("mysql") ? "jdbc:mysql://" : "jdbc:oceanbase://"; | ||
return prefix + getHost() + ":" + getMappedPort(SQL_PORT) + "/" + databaseName + additionalUrlParams; | ||
} | ||
|
||
@Override | ||
public String getDatabaseName() { | ||
return DEFAULT_DATABASE_NAME; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return DEFAULT_USERNAME + "@" + tenantName; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return DEFAULT_PASSWORD; | ||
} | ||
|
||
@Override | ||
protected String getTestQueryString() { | ||
return "SELECT 1"; | ||
} | ||
|
||
/** | ||
* Enable fastboot. | ||
* | ||
* @return this | ||
*/ | ||
public OceanBaseContainer enableFastboot() { | ||
this.enableFastboot = true; | ||
return self(); | ||
} | ||
|
||
/** | ||
* Set the deployment mode, see <a href="https://hub.docker.com/r/oceanbase/oceanbase-ce">Docker Hub</a> for more details. | ||
* | ||
* @param mode the deployment mode | ||
* @return this | ||
*/ | ||
public OceanBaseContainer withMode(String mode) { | ||
this.mode = mode; | ||
return self(); | ||
} | ||
|
||
/** | ||
* Set the non-system tenant to be created for testing. | ||
* | ||
* @param tenantName the name of tenant to be created | ||
* @return this | ||
*/ | ||
public OceanBaseContainer withTenant(String tenantName) { | ||
if (StringUtils.isEmpty(tenantName)) { | ||
throw new IllegalArgumentException("Tenant name cannot be null or empty"); | ||
} | ||
if (SYSTEM_TENANT_NAME.equals(tenantName)) { | ||
throw new IllegalArgumentException("Tenant name cannot be " + SYSTEM_TENANT_NAME); | ||
} | ||
this.tenantName = tenantName; | ||
return self(); | ||
} | ||
|
||
/** | ||
* Set the driver class name. | ||
* | ||
* @param driverClassName the driver class name | ||
* @return this | ||
*/ | ||
public OceanBaseContainer withDriverClassName(String driverClassName) { | ||
if (StringUtils.isEmpty(driverClassName)) { | ||
throw new IllegalArgumentException("Driver class name cannot be null or empty"); | ||
} | ||
if (!driverClassName.contains("mysql") && !driverClassName.contains("oceanbase")) { | ||
throw new IllegalArgumentException("Driver class name should contains 'mysql' or 'oceanbase'"); | ||
} | ||
try { | ||
Class.forName(driverClassName); | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalArgumentException("Driver class not found", e); | ||
} | ||
this.driverClassName = driverClassName; | ||
return self(); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
if (StringUtils.isNotBlank(mode)) { | ||
withEnv("MODE", mode); | ||
} | ||
if (enableFastboot) { | ||
withEnv("FASTBOOT", "true"); | ||
} | ||
if (!DEFAULT_TEST_TENANT_NAME.equals(tenantName)) { | ||
withEnv("OB_TENANT_NAME", tenantName); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Factory for OceanBase containers. | ||
*/ | ||
public class OceanBaseContainerProvider extends JdbcDatabaseContainerProvider { | ||
|
||
private static final String DEFAULT_TAG = "4.2.1_bp3"; | ||
|
||
@Override | ||
public boolean supports(String databaseType) { | ||
return databaseType.equals(OceanBaseContainer.NAME); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance() { | ||
return newInstance(DEFAULT_TAG); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(String tag) { | ||
if (tag != null) { | ||
return new OceanBaseContainer(DockerImageName.parse(OceanBaseContainer.DOCKER_IMAGE_NAME).withTag(tag)); | ||
} else { | ||
return newInstance(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.testcontainers.containers.OceanBaseContainerProvider |
8 changes: 8 additions & 0 deletions
8
modules/oceanbase-ce/src/test/java/org/testcontainers/OceanBaseTestImages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.testcontainers; | ||
|
||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class OceanBaseTestImages { | ||
|
||
public static final DockerImageName OCEANBASE_CE_IMAGE = DockerImageName.parse("oceanbase/oceanbase-ce:4.2.1_bp3"); | ||
} |
19 changes: 19 additions & 0 deletions
19
...oceanbase-ce/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.testcontainers.jdbc.oceanbase; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.testcontainers.jdbc.AbstractJDBCDriverTest; | ||
|
||
import java.util.Arrays; | ||
import java.util.EnumSet; | ||
|
||
@RunWith(Parameterized.class) | ||
public class OceanBaseJdbcDriverTest extends AbstractJDBCDriverTest { | ||
|
||
@Parameterized.Parameters(name = "{index} - {0}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList( | ||
new Object[][] { { "jdbc:tc:oceanbase://hostname/databasename", EnumSet.noneOf(Options.class) } } | ||
); | ||
} | ||
} |
Oops, something went wrong.