Skip to content

Commit

Permalink
Fixes testcontainers#543 JdbcDatabaseContainer now accepts Future as …
Browse files Browse the repository at this point in the history
…image name
  • Loading branch information
iNikem committed Feb 13, 2018
1 parent b7e7d52 commit 668665b
Showing 1 changed file with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import java.util.concurrent.Future;
import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import org.rnorth.ducttape.ratelimits.RateLimiter;
import org.rnorth.ducttape.ratelimits.RateLimiterBuilder;
Expand Down Expand Up @@ -31,7 +33,11 @@ public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<S
.withConstantThroughput()
.build();

public JdbcDatabaseContainer(String dockerImageName) {
public JdbcDatabaseContainer(@NonNull Future<String> image) {
super(image);
}

public JdbcDatabaseContainer(@NonNull String dockerImageName) {
super(dockerImageName);
}

Expand All @@ -45,6 +51,13 @@ public JdbcDatabaseContainer(String dockerImageName) {
*/
public abstract String getJdbcUrl();

/**
* @return the database name
*/
public String getDatabaseName() {
throw new UnsupportedOperationException();
}

/**
* @return the standard database username that should be used for connections
*/
Expand All @@ -64,7 +77,7 @@ public SELF withUsername(String username) {
throw new UnsupportedOperationException();
}

public SELF withPassword(String password){
public SELF withPassword(String password) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -120,16 +133,17 @@ public Driver getJdbcDriverInstance() {
/**
* Creates a connection to the underlying containerized database instance.
*
* @param queryString any special query string parameters that should be appended to the JDBC connection URL. The
* '?' character must be included
* @param queryString
* query string parameters that should be appended to the JDBC connection URL.
* The '?' character must be included
* @return a Connection
* @throws SQLException if there is a repeated failure to create the connection
*/
public Connection createConnection(String queryString) throws SQLException {
final Properties info = new Properties();
info.put("user", this.getUsername());
info.put("password", this.getPassword());
final String url = this.getJdbcUrl() + queryString;
final String url = constructUrlForConnection(queryString);

final Driver jdbcDriverInstance = getJdbcDriverInstance();

Expand All @@ -140,6 +154,20 @@ public Connection createConnection(String queryString) throws SQLException {
}
}

/**
* Template method for constructing the JDBC URL to be used for creating {@link Connection}s.
* This should be overridden if the JDBC URL and query string concatenation or URL string
* construction needs to be different to normal.
*
* @param queryString
* query string parameters that should be appended to the JDBC connection URL.
* The '?' character must be included
* @return a full JDBC URL including queryString
*/
protected String constructUrlForConnection(String queryString) {
return getJdbcUrl() + queryString;
}

protected void optionallyMapResourceParameterAsVolume(@NotNull String paramName, @NotNull String pathNameInContainer, @NotNull String defaultResource) {
String resourceName = parameters.getOrDefault(paramName, defaultResource);

Expand All @@ -149,9 +177,6 @@ protected void optionallyMapResourceParameterAsVolume(@NotNull String paramName,
}
}

@Override
protected abstract Integer getLivenessCheckPort();

public void setParameters(Map<String, String> parameters) {
this.parameters = parameters;
}
Expand Down

0 comments on commit 668665b

Please sign in to comment.