Skip to content

Commit

Permalink
Use fixed tag names for JDBC URLs when none specified
Browse files Browse the repository at this point in the history
(equivalent to current 'latest')
  • Loading branch information
rnorth committed Apr 28, 2018
1 parent e01fc58 commit bd0265f
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class JDBCDriverTest {
public static Iterable<Object[]> data() {
return asList(
new Object[][]{
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
{"jdbc:tc:mysql://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useSSL=false", false, false, false},
{"jdbc:tc:postgresql:9.6.8://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true},
{"jdbc:tc:mariadb:10.1.16://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Base class for classes that can provide a JDBC container.
*/
public abstract class JdbcDatabaseContainerProvider {

public abstract boolean supports(String databaseType);

public abstract JdbcDatabaseContainer newInstance(String tag);
public abstract JdbcDatabaseContainer newInstance(Optional<String> tag);

This comment has been minimized.

Copy link
@bsideup

bsideup Apr 28, 2018

Member

This will break the API compatibility :(

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@ public synchronized Connection connect(String url, final Properties info) throws
throw new IllegalArgumentException("JDBC URL matches jdbc:tc: prefix but the database or tag name could not be identified");
}
String databaseType = urlMatcher.group(1);
String tag = urlMatcher.group(3);
if (tag == null) {
tag = "latest";
LOGGER.warn("No version tag set in JDBC URL. `latest` will be used now, but " +
"this will stop working in a future version. Please update the JDBC URL to " +
"include a tag.");
}
Optional<String> tag = Optional.ofNullable(urlMatcher.group(3));

queryString = urlMatcher.group(4);
if (queryString == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ public class MariaDBContainer<SELF extends MariaDBContainer<SELF>> extends JdbcD

public static final String NAME = "mariadb";
public static final String IMAGE = "mariadb";
public static final String DEFAULT_TAG = "10.3.6";

private static final Integer MARIADB_PORT = 3306;
private static final String MARIADB_USER = "test";
private static final String MARIADB_PASSWORD = "test";
private static final String MARIADB_DATABASE = "test";
private static final String MY_CNF_CONFIG_OVERRIDE_PARAM_NAME = "TC_MY_CNF";

public MariaDBContainer() {
super(IMAGE + ":10.3.6");
super(IMAGE + ":" + DEFAULT_TAG);
}

public MariaDBContainer(String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Factory for MariaDB org.testcontainers.containers.
*/
Expand All @@ -10,7 +12,7 @@ public boolean supports(String databaseType) {
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
return new MariaDBContainer(MariaDBContainer.IMAGE + ":" + tag);
public JdbcDatabaseContainer newInstance(Optional<String> tag) {
return new MariaDBContainer(MariaDBContainer.IMAGE + ":" + tag.orElse(MariaDBContainer.DEFAULT_TAG));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
* @author Stefan Hufschmidt
*/
public class MSSQLServerContainer<SELF extends MSSQLServerContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
static final String NAME = "mssqlserver";
static final String IMAGE = "microsoft/mssql-server-linux";
public static final String NAME = "mssqlserver";
public static final String IMAGE = "microsoft/mssql-server-linux";
public static final String DEFAULT_TAG = "2017-CU6";

public static final Integer MS_SQL_SERVER_PORT = 1433;
private String username = "SA";
private String password = "A_Str0ng_Required_Password";

public MSSQLServerContainer() {
this(IMAGE + ":2017-CU6");
this(IMAGE + ":" + DEFAULT_TAG);
}

public MSSQLServerContainer(final String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Factory for MS SQL Server containers.
*/
Expand All @@ -10,7 +12,7 @@ public boolean supports(String databaseType) {
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
return new MSSQLServerContainer(MSSQLServerContainer.IMAGE + ":" + tag);
public JdbcDatabaseContainer newInstance(Optional<String> tag) {
return new MSSQLServerContainer(MSSQLServerContainer.IMAGE + ":" + tag.orElse(MSSQLServerContainer.DEFAULT_TAG));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatab

public static final String NAME = "mysql";
public static final String IMAGE = "mysql";
public static final String DEFAULT_TAG = "5.7.22";

private static final String MY_CNF_CONFIG_OVERRIDE_PARAM_NAME = "TC_MY_CNF";
public static final Integer MYSQL_PORT = 3306;
private String databaseName = "test";
private String username = "test";
private String password = "test";

public MySQLContainer() {
super(IMAGE + ":5.7.22");
super(IMAGE + ":" + DEFAULT_TAG);
}

public MySQLContainer(String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Factory for MySQL containers.
*/
Expand All @@ -10,7 +12,7 @@ public boolean supports(String databaseType) {
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
return new MySQLContainer(MySQLContainer.IMAGE + ":" + tag);
public JdbcDatabaseContainer newInstance(Optional<String> tag) {
return new MySQLContainer(MySQLContainer.IMAGE + ":" + tag.orElse(MySQLContainer.DEFAULT_TAG));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Factory for Oracle containers.
*/
Expand All @@ -10,9 +12,9 @@ public boolean supports(String databaseType) {
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
public JdbcDatabaseContainer newInstance(Optional<String> tag) {

if (!tag.equalsIgnoreCase("latest")) {
if (!tag.isPresent()) {
throw new UnsupportedOperationException("Oracle database tag should be set in the configured image name");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
* @author richardnorth
*/
public class PostgreSQLContainer<SELF extends PostgreSQLContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
static final String NAME = "postgresql";
static final String IMAGE = "postgres";
public static final String NAME = "postgresql";
public static final String IMAGE = "postgres";
public static final String DEFAULT_TAG = "9.6.8";

public static final Integer POSTGRESQL_PORT = 5432;
private String databaseName = "test";
private String username = "test";
private String password = "test";

public PostgreSQLContainer() {
this(IMAGE + ":9.6.8");
this(IMAGE + ":" + DEFAULT_TAG);
}

public PostgreSQLContainer(final String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.Optional;

/**
* Factory for PostgreSQL containers.
*/
Expand All @@ -10,7 +12,7 @@ public boolean supports(String databaseType) {
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
return new PostgreSQLContainer(PostgreSQLContainer.IMAGE + ":" + tag);
public JdbcDatabaseContainer newInstance(Optional<String> tag) {
return new PostgreSQLContainer(PostgreSQLContainer.IMAGE + ":" + tag.orElse(PostgreSQLContainer.DEFAULT_TAG));
}
}

0 comments on commit bd0265f

Please sign in to comment.