FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add Oracle XE database container support by swissarmykirpan · Pull Request #3 · testcontainers/testcontainers-java · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .DatabaseContainer  (1) .java  (5) .xml  (2) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
Expand Up @@ -23,7 +23,7 @@
*/
public class ContainerDatabaseDriver implements Driver {

public static final Pattern URL_MATCHING_PATTERN = Pattern.compile("jdbc:tc:(mysql|postgresql)(:([^:]+))?://[^\\?]+(\\?.*)?");
public static final Pattern URL_MATCHING_PATTERN = Pattern.compile("jdbc:tc:(mysql|postgresql|oracle)(:([^:]+))?://[^\\?]+(\\?.*)?");
public static final Pattern INITSCRIPT_MATCHING_PATTERN = Pattern.compile(".*([\\?&]?)TC_INITSCRIPT=([^\\?&]+).*");
public static final Pattern INITFUNCTION_MATCHING_PATTERN = Pattern.compile(".*([\\?&]?)TC_INITFUNCTION=" +
"((\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*\\.)*\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)" +
Expand Down
53 changes: 53 additions & 0 deletions modules/oracle-xe/pom.xml
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,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>

Copy link
Copy Markdown
Member

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 Quality

This 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!)

<scope>provided</scope>
</dependency>
</dependencies>

Copy link
Copy Markdown
Member

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 Quality

I 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)

Copy link
Copy Markdown
Member Author

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 Quality

Added



</project>
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,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; }
}
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,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();
}
}
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 @@
org.rnorth.testcontainers.containers.OracleContainer
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,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);
}
}
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,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);
}
}
14 changes: 14 additions & 0 deletions pom.xml
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
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>

Copy link
Copy Markdown
Member

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 Quality

I've not tested yet, but is this active by default?

Copy link
Copy Markdown
Member Author

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 Quality

inactive by default

Copy link
Copy Markdown
Member

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 Quality

👍

<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