Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Feb 19, 2024
1 parent 76aa6f5 commit 26aeb9a
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OceanBase CE
- OceanBase
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OceanBase CE
- OceanBase
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OceanBase CE
- OceanBase
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ updates:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/oceanbase-ce"
directory: "/modules/oceanbase"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
Expand Down
4 changes: 2 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/nginx/**/*
"modules/oceanbase-ce":
"modules/oceanbase":
- changed-files:
- any-glob-to-any-file:
- modules/oceanbase-ce/**/*
- modules/oceanbase/**/*
"modules/oracle":
- changed-files:
- any-glob-to-any-file:
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/databases/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database

#### Using OceanBase

`jdbc:tc:oceanbase:4.2.1_bp3:///databasename`
`jdbc:tc:oceanbasece:4.2.1_bp3:///databasename`

#### Using Oracle

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OceanBase-CE Module
# OceanBase Module

See [Database containers](./index.md) for documentation and usage that is common to all relational database container types.

Expand All @@ -8,14 +8,14 @@ Add the following dependency to your `pom.xml`/`build.gradle` file:

=== "Gradle"
```groovy
testImplementation "org.testcontainers:oceanbase-ce:{{latest_version}}"
testImplementation "org.testcontainers:oceanbase:{{latest_version}}"
```

=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oceanbase-ce</artifactId>
<artifactId>oceanbase</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ nav:
- modules/databases/mssqlserver.md
- modules/databases/mysql.md
- modules/databases/neo4j.md
- modules/databases/oceanbasece.md
- modules/databases/oceanbase.md
- modules/databases/oraclefree.md
- modules/databases/oraclexe.md
- modules/databases/orientdb.md
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description = "Testcontainers :: JDBC :: OceanBase CE"
description = "Testcontainers :: JDBC :: OceanBase"

dependencies {
api project(':jdbc')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.testcontainers.containers;
package org.testcontainers.oceanbase;

import org.apache.commons.lang3.StringUtils;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.utility.DockerImageName;

/**
* Testcontainers implementation for OceanBase.
* Testcontainers implementation for OceanBase Community Edition.
* <p>
* Supported image: {@code oceanbase/oceanbase-ce}
* <p>
Expand All @@ -14,33 +15,35 @@
* <li>RPC: 2882</li>
* </ul>
*/
public class OceanBaseContainer extends JdbcDatabaseContainer<OceanBaseContainer> {
public class OceanBaseCEContainer extends JdbcDatabaseContainer<OceanBaseCEContainer> {

static final String NAME = "oceanbase";
static final String NAME = "oceanbasece";

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 tenantName = "test";

private String driverClassName = "com.mysql.cj.jdbc.Driver";

public OceanBaseContainer(String dockerImageName) {
public OceanBaseCEContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public OceanBaseContainer(DockerImageName dockerImageName) {
public OceanBaseCEContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

Expand Down Expand Up @@ -83,34 +86,13 @@ 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) {
public OceanBaseCEContainer withTenant(String tenantName) {
if (StringUtils.isEmpty(tenantName)) {
throw new IllegalArgumentException("Tenant name cannot be null or empty");
}
Expand All @@ -127,32 +109,19 @@ public OceanBaseContainer withTenant(String tenantName) {
* @param driverClassName the driver class name
* @return this
*/
public OceanBaseContainer withDriverClassName(String driverClassName) {
public OceanBaseCEContainer 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);
}
withEnv("OB_TENANT_NAME", tenantName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.testcontainers.oceanbase;

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.JdbcDatabaseContainerProvider;
import org.testcontainers.utility.DockerImageName;

/**
* Factory for OceanBase Community Edition containers.
*/
public class OceanBaseCEContainerProvider extends JdbcDatabaseContainerProvider {

private static final String DEFAULT_TAG = "4.2.1_bp3";

@Override
public boolean supports(String databaseType) {
return databaseType.equals(OceanBaseCEContainer.NAME);
}

@Override
public JdbcDatabaseContainer newInstance() {
return newInstance(DEFAULT_TAG);
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
if (tag != null) {
return new OceanBaseCEContainer(DockerImageName.parse(OceanBaseCEContainer.DOCKER_IMAGE_NAME).withTag(tag));
} else {
return newInstance();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.testcontainers.oceanbase.OceanBaseCEContainerProvider
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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) } }
new Object[][] { { "jdbc:tc:oceanbasece://hostname/databasename", EnumSet.noneOf(Options.class) } }
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.OceanBaseTestImages;
import org.testcontainers.containers.OceanBaseContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.db.AbstractContainerDatabaseTest;
import org.testcontainers.oceanbase.OceanBaseCEContainer;
import org.testcontainers.oceanbase.OceanBaseCEContainerProvider;

import java.sql.ResultSet;
import java.sql.SQLException;

import static org.assertj.core.api.Assertions.assertThat;

public class SimpleOceanBaseTest extends AbstractContainerDatabaseTest {
public class SimpleOceanBaseCETest extends AbstractContainerDatabaseTest {

private static final Logger logger = LoggerFactory.getLogger(SimpleOceanBaseTest.class);
private static final Logger logger = LoggerFactory.getLogger(SimpleOceanBaseCETest.class);

private final OceanBaseCEContainerProvider containerProvider = new OceanBaseCEContainerProvider();

@SuppressWarnings("resource")
private OceanBaseCEContainer testContainer() {
return ((OceanBaseCEContainer) containerProvider.newInstance()).withEnv("MODE", "slim")
.withEnv("FASTBOOT", "true")
.withLogConsumer(new Slf4jLogConsumer(logger));
}

@Test
public void testSimple() throws SQLException {
try (
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE)
.withMode("slim")
.enableFastboot()
.withLogConsumer(new Slf4jLogConsumer(logger))
) {
try (OceanBaseCEContainer container = testContainer()) {
container.start();

ResultSet resultSet = performQuery(container, "SELECT 1");
Expand All @@ -36,13 +40,7 @@ public void testSimple() throws SQLException {

@Test
public void testExplicitInitScript() throws SQLException {
try (
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE)
.withMode("slim")
.enableFastboot()
.withInitScript("init.sql")
.withLogConsumer(new Slf4jLogConsumer(logger))
) {
try (OceanBaseCEContainer container = testContainer().withInitScript("init.sql")) {
container.start();

ResultSet resultSet = performQuery(container, "SELECT foo FROM bar");
Expand All @@ -53,13 +51,7 @@ public void testExplicitInitScript() throws SQLException {

@Test
public void testWithAdditionalUrlParamInJdbcUrl() {
try (
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE)
.withMode("slim")
.enableFastboot()
.withUrlParam("useSSL", "false")
.withLogConsumer(new Slf4jLogConsumer(logger))
) {
try (OceanBaseCEContainer container = testContainer().withUrlParam("useSSL", "false")) {
container.start();

String jdbcUrl = container.getJdbcUrl();
Expand All @@ -68,7 +60,7 @@ public void testWithAdditionalUrlParamInJdbcUrl() {
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(OceanBaseContainer container) {
private void assertHasCorrectExposedAndLivenessCheckPorts(OceanBaseCEContainer container) {
int sqlPort = 2881;
int rpcPort = 2882;

Expand Down

0 comments on commit 26aeb9a

Please sign in to comment.