From 26aeb9aa74fad1a0039ecaced9733d587e65e24c Mon Sep 17 00:00:00 2001 From: He Wang Date: Mon, 19 Feb 2024 14:48:32 +0800 Subject: [PATCH] address review comments --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 +- .github/ISSUE_TEMPLATE/enhancement.yaml | 2 +- .github/ISSUE_TEMPLATE/feature.yaml | 2 +- .github/dependabot.yml | 2 +- .github/labeler.yml | 4 +- docs/modules/databases/jdbc.md | 2 +- .../{oceanbasece.md => oceanbase.md} | 6 +- mkdocs.yml | 2 +- .../OceanBaseContainerProvider.java | 30 --------- ...s.containers.JdbcDatabaseContainerProvider | 1 - .../testcontainers/OceanBaseTestImages.java | 8 --- .../{oceanbase-ce => oceanbase}/build.gradle | 2 +- .../oceanbase/OceanBaseCEContainer.java} | 63 +++++-------------- .../OceanBaseCEContainerProvider.java | 32 ++++++++++ ...s.containers.JdbcDatabaseContainerProvider | 1 + .../oceanbase/OceanBaseJdbcDriverTest.java | 2 +- .../oceanbase/SimpleOceanBaseCETest.java} | 42 +++++-------- .../src/test/resources/init.sql | 0 .../src/test/resources/logback-test.xml | 0 19 files changed, 79 insertions(+), 124 deletions(-) rename docs/modules/databases/{oceanbasece.md => oceanbase.md} (82%) delete mode 100644 modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainerProvider.java delete mode 100644 modules/oceanbase-ce/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider delete mode 100644 modules/oceanbase-ce/src/test/java/org/testcontainers/OceanBaseTestImages.java rename modules/{oceanbase-ce => oceanbase}/build.gradle (72%) rename modules/{oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainer.java => oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainer.java} (65%) create mode 100644 modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainerProvider.java create mode 100644 modules/oceanbase/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider rename modules/{oceanbase-ce => oceanbase}/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java (80%) rename modules/{oceanbase-ce/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseTest.java => oceanbase/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseCETest.java} (62%) rename modules/{oceanbase-ce => oceanbase}/src/test/resources/init.sql (100%) rename modules/{oceanbase-ce => oceanbase}/src/test/resources/logback-test.xml (100%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 0337934b046..913f9958ca1 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -39,7 +39,7 @@ body: - MySQL - Neo4j - NGINX - - OceanBase CE + - OceanBase - Oracle Free - Oracle XE - OrientDB diff --git a/.github/ISSUE_TEMPLATE/enhancement.yaml b/.github/ISSUE_TEMPLATE/enhancement.yaml index 0fd5ccf8d9d..bf73d4d12d4 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.yaml +++ b/.github/ISSUE_TEMPLATE/enhancement.yaml @@ -39,7 +39,7 @@ body: - MySQL - Neo4j - NGINX - - OceanBase CE + - OceanBase - Oracle Free - Oracle XE - OrientDB diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml index 61d5c78916c..bd09a3db2e4 100644 --- a/.github/ISSUE_TEMPLATE/feature.yaml +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -39,7 +39,7 @@ body: - MySQL - Neo4j - NGINX - - OceanBase CE + - OceanBase - Oracle Free - Oracle XE - OrientDB diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0043334eb56..0f33f0a25ae 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/labeler.yml b/.github/labeler.yml index bbef114d227..208679762a9 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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: diff --git a/docs/modules/databases/jdbc.md b/docs/modules/databases/jdbc.md index 3f2129bd644..d26a43d041c 100644 --- a/docs/modules/databases/jdbc.md +++ b/docs/modules/databases/jdbc.md @@ -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 diff --git a/docs/modules/databases/oceanbasece.md b/docs/modules/databases/oceanbase.md similarity index 82% rename from docs/modules/databases/oceanbasece.md rename to docs/modules/databases/oceanbase.md index 87e84f9b5f5..b90a492a6e4 100644 --- a/docs/modules/databases/oceanbasece.md +++ b/docs/modules/databases/oceanbase.md @@ -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. @@ -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 org.testcontainers - oceanbase-ce + oceanbase {{latest_version}} test diff --git a/mkdocs.yml b/mkdocs.yml index 086f11de147..4b95b76ccda 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainerProvider.java b/modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainerProvider.java deleted file mode 100644 index fd84a04d328..00000000000 --- a/modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainerProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -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(); - } - } -} diff --git a/modules/oceanbase-ce/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/oceanbase-ce/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider deleted file mode 100644 index 977e58989c9..00000000000 --- a/modules/oceanbase-ce/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider +++ /dev/null @@ -1 +0,0 @@ -org.testcontainers.containers.OceanBaseContainerProvider diff --git a/modules/oceanbase-ce/src/test/java/org/testcontainers/OceanBaseTestImages.java b/modules/oceanbase-ce/src/test/java/org/testcontainers/OceanBaseTestImages.java deleted file mode 100644 index b758e8b605f..00000000000 --- a/modules/oceanbase-ce/src/test/java/org/testcontainers/OceanBaseTestImages.java +++ /dev/null @@ -1,8 +0,0 @@ -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"); -} diff --git a/modules/oceanbase-ce/build.gradle b/modules/oceanbase/build.gradle similarity index 72% rename from modules/oceanbase-ce/build.gradle rename to modules/oceanbase/build.gradle index 0e4f901fada..e1f13a7a6a1 100644 --- a/modules/oceanbase-ce/build.gradle +++ b/modules/oceanbase/build.gradle @@ -1,4 +1,4 @@ -description = "Testcontainers :: JDBC :: OceanBase CE" +description = "Testcontainers :: JDBC :: OceanBase" dependencies { api project(':jdbc') diff --git a/modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainer.java b/modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainer.java similarity index 65% rename from modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainer.java rename to modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainer.java index b609ca099fa..68406fd0442 100644 --- a/modules/oceanbase-ce/src/main/java/org/testcontainers/containers/OceanBaseContainer.java +++ b/modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainer.java @@ -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. *

* Supported image: {@code oceanbase/oceanbase-ce} *

@@ -14,33 +15,35 @@ *

  • RPC: 2882
  • * */ -public class OceanBaseContainer extends JdbcDatabaseContainer { +public class OceanBaseCEContainer extends JdbcDatabaseContainer { - 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); @@ -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 Docker Hub 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"); } @@ -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); } } diff --git a/modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainerProvider.java b/modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainerProvider.java new file mode 100644 index 00000000000..88bb8514e07 --- /dev/null +++ b/modules/oceanbase/src/main/java/org/testcontainers/oceanbase/OceanBaseCEContainerProvider.java @@ -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(); + } + } +} diff --git a/modules/oceanbase/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/oceanbase/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider new file mode 100644 index 00000000000..505bfe5e088 --- /dev/null +++ b/modules/oceanbase/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider @@ -0,0 +1 @@ +org.testcontainers.oceanbase.OceanBaseCEContainerProvider diff --git a/modules/oceanbase-ce/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java b/modules/oceanbase/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java similarity index 80% rename from modules/oceanbase-ce/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java rename to modules/oceanbase/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java index d540c71e7cf..67331a0c09a 100644 --- a/modules/oceanbase-ce/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java +++ b/modules/oceanbase/src/test/java/org/testcontainers/jdbc/oceanbase/OceanBaseJdbcDriverTest.java @@ -13,7 +13,7 @@ public class OceanBaseJdbcDriverTest extends AbstractJDBCDriverTest { @Parameterized.Parameters(name = "{index} - {0}") public static Iterable 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) } } ); } } diff --git a/modules/oceanbase-ce/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseTest.java b/modules/oceanbase/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseCETest.java similarity index 62% rename from modules/oceanbase-ce/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseTest.java rename to modules/oceanbase/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseCETest.java index c447883beff..5012e39f9b1 100644 --- a/modules/oceanbase-ce/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseTest.java +++ b/modules/oceanbase/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseCETest.java @@ -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"); @@ -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"); @@ -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(); @@ -68,7 +60,7 @@ public void testWithAdditionalUrlParamInJdbcUrl() { } } - private void assertHasCorrectExposedAndLivenessCheckPorts(OceanBaseContainer container) { + private void assertHasCorrectExposedAndLivenessCheckPorts(OceanBaseCEContainer container) { int sqlPort = 2881; int rpcPort = 2882; diff --git a/modules/oceanbase-ce/src/test/resources/init.sql b/modules/oceanbase/src/test/resources/init.sql similarity index 100% rename from modules/oceanbase-ce/src/test/resources/init.sql rename to modules/oceanbase/src/test/resources/init.sql diff --git a/modules/oceanbase-ce/src/test/resources/logback-test.xml b/modules/oceanbase/src/test/resources/logback-test.xml similarity index 100% rename from modules/oceanbase-ce/src/test/resources/logback-test.xml rename to modules/oceanbase/src/test/resources/logback-test.xml