| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>oracle-xe</artifactId> | ||
| <description>Test Containers :: JDBC :: Oracle</description> | ||
|
|
||
| <parent> | ||
| <groupId>org.rnorth.test-containers</groupId> | ||
| <artifactId>test-containers-parent</artifactId> | ||
| <version>0.9.5-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>test-containers</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>jdbc</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Database connection pool for testing --> | ||
| <dependency> | ||
| <groupId>com.zaxxer</groupId> | ||
| <artifactId>HikariCP</artifactId> | ||
| <version>2.3.5</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>commons-dbutils</groupId> | ||
| <artifactId>commons-dbutils</artifactId> | ||
| <version>1.6</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Oracle JDBC Driver --> | ||
| <dependency> | ||
| <groupId>com.oracle</groupId> | ||
| <artifactId>ojdbc6</artifactId> | ||
| <version>11.2.0.3</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI imagine the Oracle JDBC driver needs to be added here - please make sure you're using the standard groupId:artifactId for it (can't remember what the convention is off the top of my head)
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAdded
Sorry, something went wrong.
All reactions
|
||
|
|
||
|
|
||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.rnorth.testcontainers.containers; | ||
|
|
||
| import com.spotify.docker.client.messages.ContainerConfig; | ||
| import com.spotify.docker.client.messages.ContainerInfo; | ||
| import oracle.jdbc.pool.OracleDataSource; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| /** | ||
| * Created by gusohal on 26/04/15. | ||
| */ | ||
| public class OracleContainer extends AbstractContainer implements DatabaseContainer { | ||
|
|
||
| private static final String IMAGE = "alexeiled/docker-oracle-xe-11g"; | ||
| private String oraclePort; | ||
|
|
||
| @Override | ||
| protected void containerIsStarting(ContainerInfo containerInfo) { | ||
| oraclePort = containerInfo.networkSettings().ports().get("1521/tcp").get(0).hostPort(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getLivenessCheckPort() { | ||
| return oraclePort; | ||
| } | ||
|
|
||
| @Override | ||
| protected ContainerConfig getContainerConfig() { | ||
| return ContainerConfig.builder() | ||
| .image(getDockerImageName()) | ||
| .exposedPorts("1521", "8080") | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getDockerImageName() { | ||
| return IMAGE + ":" + tag; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "oracle"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDriverClassName() { | ||
| return "oracle.jdbc.OracleDriver"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getJdbcUrl() { | ||
| return "jdbc:oracle:thin:" + getUsername() + "/" + getPassword() + "@//" + dockerHostIpAddress + ":" + oraclePort + "/xe"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getUsername() { | ||
| return "system"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPassword() { | ||
| return "oracle"; | ||
| } | ||
|
|
||
| @Override | ||
| public void waitUntilContainerStarted() { | ||
| super.waitUntilContainerStarted(); | ||
|
|
||
| OracleDataSource dataSource; | ||
|
|
||
| for (int i = 0; i < 600; i++) { | ||
| try { | ||
| dataSource = new OracleDataSource(); | ||
| dataSource.setURL(getJdbcUrl()); | ||
| dataSource.getConnection(); | ||
|
|
||
| return; | ||
| } catch (SQLException e) { | ||
| try { | ||
| Thread.sleep(100L); | ||
| } catch (InterruptedException ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new IllegalStateException("Timed out waiting for database server to come up"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getContainerId() { return containerId; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.rnorth.testcontainers.junit; | ||
|
|
||
| import org.junit.rules.ExternalResource; | ||
| import org.rnorth.testcontainers.containers.OracleContainer; | ||
|
|
||
| /** | ||
| * Created by gusohal on 05/05/15. | ||
| */ | ||
| public class OracleContainerRule extends ExternalResource { | ||
|
|
||
| private final OracleContainer container; | ||
|
|
||
| public OracleContainerRule() { | ||
| container = new OracleContainer(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void before() throws Throwable { | ||
| container.start(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void after() { | ||
| container.stop(); | ||
| } | ||
|
|
||
| public String getJdbcUrl() { | ||
| return container.getJdbcUrl(); | ||
| } | ||
|
|
||
| public String getUsername() { | ||
| return container.getUsername(); | ||
| } | ||
|
|
||
| public String getPassword() { | ||
| return container.getPassword(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.rnorth.testcontainers.containers.OracleContainer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.rnorth.testcontainers.containers; | ||
|
|
||
| import com.zaxxer.hikari.HikariConfig; | ||
| import com.zaxxer.hikari.HikariDataSource; | ||
| import org.apache.commons.dbutils.QueryRunner; | ||
| import org.junit.Test; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public class OracleJDBCDriverTest { | ||
|
|
||
| @Test | ||
| public void testOracleWithNoSpecifiedVersion() throws SQLException { | ||
| performSimpleTest("jdbc:tc:oracle://hostname/databasename"); | ||
| } | ||
|
|
||
|
|
||
| private void performSimpleTest(String jdbcUrl) throws SQLException { | ||
| HikariDataSource dataSource = getDataSource(jdbcUrl, 1); | ||
| new QueryRunner(dataSource).query("SELECT 1 FROM dual", rs -> { | ||
| rs.next(); | ||
| int resultSetInt = rs.getInt(1); | ||
| assertEquals(1, resultSetInt); | ||
| return true; | ||
| }); | ||
| dataSource.close(); | ||
| } | ||
|
|
||
| private HikariDataSource getDataSource(String jdbcUrl, int poolSize) { | ||
| HikariConfig hikariConfig = new HikariConfig(); | ||
| hikariConfig.setJdbcUrl(jdbcUrl); | ||
| hikariConfig.setConnectionTestQuery("SELECT 1 FROM dual"); | ||
| hikariConfig.setMinimumIdle(1); | ||
| hikariConfig.setMaximumPoolSize(poolSize); | ||
|
|
||
| return new HikariDataSource(hikariConfig); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.rnorth.testcontainers.junit; | ||
|
|
||
| import com.zaxxer.hikari.HikariConfig; | ||
| import com.zaxxer.hikari.HikariDataSource; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * Created by gusohal on 04/05/15. | ||
| */ | ||
| public class SimpleOracleTest { | ||
|
|
||
| @Rule | ||
| public OracleContainerRule oracle = new OracleContainerRule(); | ||
|
|
||
| @Test | ||
| public void testSimple() throws SQLException { | ||
| HikariConfig hikariConfig = new HikariConfig(); | ||
| hikariConfig.setJdbcUrl(oracle.getJdbcUrl()); | ||
| hikariConfig.setUsername(oracle.getUsername()); | ||
| hikariConfig.setPassword(oracle.getPassword()); | ||
|
|
||
| HikariDataSource ds = new HikariDataSource(hikariConfig); | ||
| Statement statement = ds.getConnection().createStatement(); | ||
| statement.execute("SELECT 1 FROM dual"); | ||
| ResultSet resultSet = statement.getResultSet(); | ||
|
|
||
| resultSet.next(); | ||
| int resultSetInt = resultSet.getInt(1); | ||
| assertEquals(1, resultSetInt); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -25,6 +25,11 @@ | |
| <name>Richard North</name> | ||
| <email>rich.north@gmail.com</email> | ||
| </developer> | ||
| <developer> | ||
| <id>gusohal</id> | ||
| <name>Gurpreet Sohal</name> | ||
| <email>gurpreet@gurpreetsohal.com</email> | ||
| </developer> | ||
| </developers> | ||
|
|
||
| <dependencies> | ||
| Expand Down Expand Up | @@ -104,6 +109,15 @@ | |
| <module>modules/nginx</module> | ||
| </modules> | ||
|
|
||
| <profiles> | ||
| <profile> | ||
| <id>proprietary-deps</id> | ||
| <modules> | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI've not tested yet, but is this active by default?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityinactive by default
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality👍
Sorry, something went wrong.
All reactions
|
||
| <module>modules/oracle-xe</module> | ||
| </modules> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| <scm> | ||
| <connection>scm:git:https://github.com/rnorth/test-containers.git</connection> | ||
| <developerConnection>scm:git:git@github.com:rnorth/test-containers.git</developerConnection> | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is a very specific version and not the latest either (even in the 11g line). I guess it's OK to use if it's for a specific reason, but if there's not a specific one shouldn't we use the latest drivers that are compatible with the docker image? (I still need to look at what version that actually is!)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.