-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Introducing Oracle Free module #7749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+617
−3
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aa0cfcd
Introducing Oracle Free module
gvenzl 9df3e92
Remove deprecated constructor
gvenzl ab1d112
Apply suggestions from code review
gvenzl e76e5ec
Merge branch 'main' into main
gvenzl 448ec15
Update templates
gvenzl c88bede
Merge branch 'main' of github.com:gvenzl/testcontainers-java
gvenzl 9a09792
Add doc
gvenzl 823db9a
Address comments
gvenzl 96bb36f
rename meta-inf file
gvenzl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| # Oracle Database Free Module | ||
|
|
||
| See [Database containers](./index.md) for documentation and usage that is common to all relational database container types. | ||
|
|
||
| ## Usage example | ||
|
|
||
| You can use `OracleContainer` like any other JDBC container: | ||
| <!--codeinclude--> | ||
| [Container creation](../../../modules/oracle-free/src/test/java/org/testcontainers/junit/oracle/SimpleOracleTest.java) inside_block:constructor | ||
| <!--/codeinclude--> | ||
|
|
||
| ## Adding this module to your project dependencies | ||
|
|
||
| Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
|
||
| === "Gradle" | ||
| ```groovy | ||
| testImplementation "org.testcontainers:oracle-free:{{latest_version}}" | ||
| ``` | ||
| === "Maven" | ||
| ```xml | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>oracle-free</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 hidden or 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,32 @@ | ||
| description = "Testcontainers :: JDBC :: Oracle Database Free" | ||
|
|
||
| dependencies { | ||
| annotationProcessor 'com.google.auto.service:auto-service:1.1.1' | ||
| compileOnly 'com.google.auto.service:auto-service:1.1.1' | ||
|
|
||
| api project(':jdbc') | ||
|
|
||
| compileOnly project(':r2dbc') | ||
| compileOnly 'com.oracle.database.r2dbc:oracle-r2dbc:1.1.1' | ||
|
|
||
| testImplementation project(':jdbc-test') | ||
| testImplementation 'com.oracle.database.jdbc:ojdbc11:23.3.0.23.09' | ||
|
|
||
| compileOnly 'org.jetbrains:annotations:24.0.1' | ||
|
|
||
| testImplementation testFixtures(project(':r2dbc')) | ||
| testRuntimeOnly 'com.oracle.database.r2dbc:oracle-r2dbc:1.1.1' | ||
| } | ||
|
|
||
| test { | ||
| javaLauncher = javaToolchains.launcherFor { | ||
| languageVersion = JavaLanguageVersion.of(11) | ||
| } | ||
| } | ||
|
|
||
| compileTestJava { | ||
| javaCompiler = javaToolchains.compilerFor { | ||
| languageVersion = JavaLanguageVersion.of(11) | ||
| } | ||
| options.release.set(11) | ||
| } |
194 changes: 194 additions & 0 deletions
194
modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainer.java
This file contains hidden or 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,194 @@ | ||
| package org.testcontainers.oracle; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.testcontainers.containers.JdbcDatabaseContainer; | ||
| import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Testcontainers implementation for Oracle Database Free. | ||
| * <p> | ||
| * Supported image: {@code gvenzl/oracle-free} | ||
| * <p> | ||
| * Exposed ports: 1521 | ||
| */ | ||
| public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> { | ||
|
|
||
| static final String NAME = "oracle"; | ||
|
|
||
| private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-free"); | ||
|
|
||
| static final String DEFAULT_TAG = "slim"; | ||
|
|
||
| static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart(); | ||
|
|
||
| static final int ORACLE_PORT = 1521; | ||
|
|
||
| private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 60; | ||
|
|
||
| private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 60; | ||
|
|
||
| // Container defaults | ||
| static final String DEFAULT_DATABASE_NAME = "freepdb1"; | ||
|
|
||
| static final String DEFAULT_SID = "free"; | ||
|
|
||
| static final String DEFAULT_SYSTEM_USER = "system"; | ||
|
|
||
| static final String DEFAULT_SYS_USER = "sys"; | ||
|
|
||
| // Test container defaults | ||
| static final String APP_USER = "test"; | ||
|
|
||
| static final String APP_USER_PASSWORD = "test"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really should default to secure random passwords in the future (in the baseclass) |
||
|
|
||
| // Restricted user and database names | ||
| private static final List<String> ORACLE_SYSTEM_USERS = Arrays.asList(DEFAULT_SYSTEM_USER, DEFAULT_SYS_USER); | ||
|
|
||
| private String databaseName = DEFAULT_DATABASE_NAME; | ||
|
|
||
| private String username = APP_USER; | ||
|
|
||
| private String password = APP_USER_PASSWORD; | ||
|
|
||
| private boolean usingSid = false; | ||
|
|
||
| public OracleContainer(String dockerImageName) { | ||
| this(DockerImageName.parse(dockerImageName)); | ||
| } | ||
|
|
||
| public OracleContainer(final DockerImageName dockerImageName) { | ||
| super(dockerImageName); | ||
| dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
| this.waitStrategy = | ||
| new LogMessageWaitStrategy() | ||
| .withRegEx(".*DATABASE IS READY TO USE!.*\\s") | ||
| .withTimes(1) | ||
| .withStartupTimeout(Duration.of(DEFAULT_STARTUP_TIMEOUT_SECONDS, ChronoUnit.SECONDS)); | ||
| withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS); | ||
| addExposedPorts(ORACLE_PORT); | ||
| } | ||
|
|
||
| @Override | ||
| protected void waitUntilContainerStarted() { | ||
| getWaitStrategy().waitUntilReady(this); | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public Set<Integer> getLivenessCheckPortNumbers() { | ||
| return Collections.singleton(getMappedPort(ORACLE_PORT)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getDriverClassName() { | ||
| return "oracle.jdbc.driver.OracleDriver"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getJdbcUrl() { | ||
| return isUsingSid() | ||
| ? "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + ":" + getSid() | ||
| : "jdbc:oracle:thin:" + "@" + getHost() + ":" + getOraclePort() + "/" + getDatabaseName(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getUsername() { | ||
| // An application user is tied to the database, and therefore not authenticated to connect to SID. | ||
| return isUsingSid() ? DEFAULT_SYSTEM_USER : username; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPassword() { | ||
| return password; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDatabaseName() { | ||
| return databaseName; | ||
| } | ||
|
|
||
| protected boolean isUsingSid() { | ||
| return usingSid; | ||
| } | ||
|
|
||
| @Override | ||
| public OracleContainer withUsername(String username) { | ||
| if (StringUtils.isEmpty(username)) { | ||
| throw new IllegalArgumentException("Username cannot be null or empty"); | ||
| } | ||
| if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) { | ||
| throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS); | ||
| } | ||
| this.username = username; | ||
| return self(); | ||
| } | ||
|
|
||
| @Override | ||
| public OracleContainer withPassword(String password) { | ||
| if (StringUtils.isEmpty(password)) { | ||
| throw new IllegalArgumentException("Password cannot be null or empty"); | ||
| } | ||
| this.password = password; | ||
| return self(); | ||
| } | ||
|
|
||
| @Override | ||
| public OracleContainer withDatabaseName(String databaseName) { | ||
| if (StringUtils.isEmpty(databaseName)) { | ||
| throw new IllegalArgumentException("Database name cannot be null or empty"); | ||
| } | ||
|
|
||
| if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) { | ||
| throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME); | ||
| } | ||
|
|
||
| this.databaseName = databaseName; | ||
| return self(); | ||
| } | ||
|
|
||
| public OracleContainer usingSid() { | ||
| this.usingSid = true; | ||
| return self(); | ||
| } | ||
|
|
||
| @Override | ||
| public OracleContainer withUrlParam(String paramName, String paramValue) { | ||
| throw new UnsupportedOperationException("The Oracle Database driver does not support this"); | ||
| } | ||
|
|
||
| @SuppressWarnings("SameReturnValue") | ||
| public String getSid() { | ||
| return DEFAULT_SID; | ||
| } | ||
|
|
||
| public Integer getOraclePort() { | ||
| return getMappedPort(ORACLE_PORT); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTestQueryString() { | ||
| return "SELECT 1 FROM DUAL"; | ||
| } | ||
|
|
||
| @Override | ||
| protected void configure() { | ||
| withEnv("ORACLE_PASSWORD", password); | ||
|
|
||
| // Only set ORACLE_DATABASE if different than the default. | ||
| if (databaseName != DEFAULT_DATABASE_NAME) { | ||
| withEnv("ORACLE_DATABASE", databaseName); | ||
| } | ||
|
|
||
| withEnv("APP_USER", username); | ||
| withEnv("APP_USER_PASSWORD", password); | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainerProvider.java
This file contains hidden or 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,29 @@ | ||
| package org.testcontainers.oracle; | ||
|
|
||
| import org.testcontainers.containers.JdbcDatabaseContainer; | ||
| import org.testcontainers.containers.JdbcDatabaseContainerProvider; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| /** | ||
| * Factory for Oracle containers. | ||
| */ | ||
| public class OracleContainerProvider extends JdbcDatabaseContainerProvider { | ||
|
|
||
| @Override | ||
| public boolean supports(String databaseType) { | ||
| return databaseType.equals(OracleContainer.NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public JdbcDatabaseContainer newInstance() { | ||
| return newInstance(OracleContainer.DEFAULT_TAG); | ||
| } | ||
|
|
||
| @Override | ||
| public JdbcDatabaseContainer newInstance(String tag) { | ||
| if (tag != null) { | ||
| return new OracleContainer(DockerImageName.parse(OracleContainer.IMAGE).withTag(tag)); | ||
| } | ||
| return newInstance(); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...les/oracle-free/src/main/java/org/testcontainers/oracle/OracleR2DBCDatabaseContainer.java
This file contains hidden or 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,35 @@ | ||
| package org.testcontainers.oracle; | ||
|
|
||
| import io.r2dbc.spi.ConnectionFactoryOptions; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.experimental.Delegate; | ||
| import org.testcontainers.lifecycle.Startable; | ||
| import org.testcontainers.r2dbc.R2DBCDatabaseContainer; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class OracleR2DBCDatabaseContainer implements R2DBCDatabaseContainer { | ||
|
|
||
| @Delegate(types = Startable.class) | ||
| private final OracleContainer container; | ||
|
|
||
| public static ConnectionFactoryOptions getOptions(OracleContainer container) { | ||
| ConnectionFactoryOptions options = ConnectionFactoryOptions | ||
| .builder() | ||
| .option(ConnectionFactoryOptions.DRIVER, OracleR2DBCDatabaseContainerProvider.DRIVER) | ||
| .build(); | ||
|
|
||
| return new OracleR2DBCDatabaseContainer(container).configure(options); | ||
| } | ||
|
|
||
| @Override | ||
| public ConnectionFactoryOptions configure(ConnectionFactoryOptions options) { | ||
| return options | ||
| .mutate() | ||
| .option(ConnectionFactoryOptions.HOST, container.getHost()) | ||
| .option(ConnectionFactoryOptions.PORT, container.getMappedPort(OracleContainer.ORACLE_PORT)) | ||
| .option(ConnectionFactoryOptions.DATABASE, container.getDatabaseName()) | ||
| .option(ConnectionFactoryOptions.USER, container.getUsername()) | ||
| .option(ConnectionFactoryOptions.PASSWORD, container.getPassword()) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also accept the official Oracle image.