-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
328 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 |
---|---|---|
|
@@ -38,6 +38,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase-CE | ||
- Oracle-XE | ||
- OrientDB | ||
- PostgreSQL | ||
|
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase-CE | ||
- Oracle-XE | ||
- OrientDB | ||
- PostgreSQL | ||
|
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ body: | |
- MySQL | ||
- Neo4j | ||
- NGINX | ||
- OceanBase-CE | ||
- Oracle-XE | ||
- OrientDB | ||
- PostgreSQL | ||
|
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,10 @@ | ||
description = "Testcontainers :: JDBC :: OceanBase" | ||
|
||
dependencies { | ||
api project(':jdbc') | ||
|
||
testImplementation project(':jdbc-test') | ||
testRuntimeOnly 'com.oceanbase:oceanbase-client:2.4.3' | ||
|
||
compileOnly 'org.jetbrains:annotations:24.0.1' | ||
} |
93 changes: 93 additions & 0 deletions
93
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,93 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* 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 final String databaseName = "test"; | ||
private final String username = "root@test"; | ||
private final String password = ""; | ||
|
||
public OceanBaseContainer(String dockerImageName) { | ||
this(DockerImageName.parse(dockerImageName)); | ||
} | ||
|
||
public OceanBaseContainer(DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
||
this.waitStrategy = Wait.forLogMessage(".*boot success!.*", 1).withStartupTimeout(Duration.ofMinutes(3)); | ||
|
||
addExposedPorts(SQL_PORT, RPC_PORT); | ||
} | ||
|
||
public Integer getSqlPort() { | ||
return getMappedPort(SQL_PORT); | ||
} | ||
|
||
public Integer getRpcPort() { | ||
return getMappedPort(RPC_PORT); | ||
} | ||
|
||
@Override | ||
public String getDriverClassName() { | ||
return "com.oceanbase.jdbc.Driver"; | ||
} | ||
|
||
@Override | ||
public String getJdbcUrl() { | ||
String additionalUrlParams = constructUrlParameters("?", "&"); | ||
return ( | ||
"jdbc:oceanbase://" + getHost() + ":" + getMappedPort(SQL_PORT) + "/" + databaseName + additionalUrlParams | ||
); | ||
} | ||
|
||
@Override | ||
public String getDatabaseName() { | ||
return databaseName; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
@Override | ||
protected String getTestQueryString() { | ||
return "SELECT 1"; | ||
} | ||
|
||
@Override | ||
protected void waitUntilContainerStarted() { | ||
getWaitStrategy().waitUntilReady(this); | ||
} | ||
} |
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.1.0.0"; | ||
|
||
@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.1.0.0"); | ||
} |
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) } } | ||
); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...es/oceanbase-ce/src/test/java/org/testcontainers/junit/oceanbase/SimpleOceanBaseTest.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,66 @@ | ||
package org.testcontainers.junit.oceanbase; | ||
|
||
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 java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SimpleOceanBaseTest extends AbstractContainerDatabaseTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SimpleOceanBaseTest.class); | ||
|
||
@Test | ||
public void testSimple() throws SQLException { | ||
try ( | ||
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE) | ||
.withLogConsumer(new Slf4jLogConsumer(logger)) | ||
) { | ||
container.start(); | ||
|
||
ResultSet resultSet = performQuery(container, "SELECT 1"); | ||
int resultSetInt = resultSet.getInt(1); | ||
|
||
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void testExplicitInitScript() throws SQLException { | ||
try ( | ||
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE) | ||
.withInitScript("init.sql") | ||
.withLogConsumer(new Slf4jLogConsumer(logger)) | ||
) { | ||
container.start(); | ||
|
||
ResultSet resultSet = performQuery(container, "SELECT foo FROM bar"); | ||
String firstColumnValue = resultSet.getString(1); | ||
|
||
assertThat(firstColumnValue).as("Value from init script should equal real value").isEqualTo("hello world"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testWithAdditionalUrlParamInJdbcUrl() { | ||
try ( | ||
OceanBaseContainer container = new OceanBaseContainer(OceanBaseTestImages.OCEANBASE_CE_IMAGE) | ||
.withUrlParam("useSSL", "false") | ||
.withLogConsumer(new Slf4jLogConsumer(logger)) | ||
) { | ||
container.start(); | ||
|
||
container.start(); | ||
String jdbcUrl = container.getJdbcUrl(); | ||
assertThat(jdbcUrl).contains("?"); | ||
assertThat(jdbcUrl).contains("useSSL=false"); | ||
} | ||
} | ||
} |
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,45 @@ | ||
CREATE TABLE bar ( | ||
foo VARCHAR(255) | ||
); | ||
|
||
DROP PROCEDURE IF EXISTS -- ; | ||
count_foo; | ||
|
||
SELECT "a /* string literal containing comment characters like -- here"; | ||
SELECT "a 'quoting' \"scenario ` involving BEGIN keyword\" here"; | ||
SELECT * from `bar`; | ||
-- What about a line comment containing imbalanced string delimiters? " | ||
CREATE PROCEDURE count_foo() | ||
BEGIN | ||
BEGIN | ||
SELECT * | ||
FROM bar; | ||
SELECT 1 | ||
FROM dual; | ||
END; | ||
BEGIN | ||
select * from bar; | ||
END; | ||
-- we can do comments | ||
/* including block | ||
comments | ||
*/ | ||
/* what if BEGIN appears inside a comment? */ | ||
select "or what if BEGIN appears inside a literal?"; | ||
END /*; */; | ||
/* or a block comment | ||
containing imbalanced string delimiters? | ||
' " | ||
*/ | ||
INSERT INTO bar (foo) /* ; */ VALUES ('hello world'); |
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,16 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="org.testcontainers" level="INFO"/> | ||
</configuration> |