Skip to content
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

Added builder for timeouts in JdbcDatabaseContainer (#715) #748

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<S
.withConstantThroughput()
.build();

private int startupTimeoutSeconds = 120;
private int connectTimeoutSeconds = 120;

public JdbcDatabaseContainer(@NonNull final String dockerImageName) {
super(dockerImageName);
}
Expand Down Expand Up @@ -86,6 +89,28 @@ public SELF withDatabaseName(String dbName) {

}

/**
* Set startup time to allow, including image pull time, in seconds.
*
* @param startupTimeoutSeconds startup time to allow, including image pull time, in seconds
* @return self
*/
public SELF withStartupTimeoutSeconds(int startupTimeoutSeconds) {
this.startupTimeoutSeconds = startupTimeoutSeconds;
return self();
}

/**
* Set time to allow for the database to start and establish an initial connection, in seconds.
*
* @param connectTimeoutSeconds time to allow for the database to start and establish an initial connection in seconds
* @return self
*/
public SELF withConnectTimeoutSeconds(int connectTimeoutSeconds) {
this.connectTimeoutSeconds = connectTimeoutSeconds;
return self();
}

@Override
protected void waitUntilContainerStarted() {
// Repeatedly try and open a connection to the DB and execute a test query
Expand Down Expand Up @@ -188,15 +213,19 @@ public void addParameter(String paramName, String value) {

/**
* @return startup time to allow, including image pull time, in seconds
* @deprecated should not be overridden anymore, use {@link #withStartupTimeoutSeconds(int)} in constructor instead
*/
@Deprecated
protected int getStartupTimeoutSeconds() {
return 120;
return startupTimeoutSeconds;
}

/**
* @return time to allow for the database to start and establish an initial connection, in seconds
* @deprecated should not be overridden anymore, use {@link #withConnectTimeoutSeconds(int)} in constructor instead
*/
@Deprecated
protected int getConnectTimeoutSeconds() {
return 120;
return connectTimeoutSeconds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ public class MSSQLServerContainer<SELF extends MSSQLServerContainer<SELF>> exten
private String username = "SA";
private String password = "A_Str0ng_Required_Password";

private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240;
private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 240;

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

public MSSQLServerContainer(final String dockerImageName) {
super(dockerImageName);
withStartupTimeoutSeconds(DEFAULT_STARTUP_TIMEOUT_SECONDS);
withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class OracleContainer extends JdbcDatabaseContainer {
private static final int ORACLE_PORT = 1521;
private static final int APEX_HTTP_PORT = 8080;

private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240;
private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120;

private static String resolveImageName() {
String image = TestcontainersConfiguration.getInstance()
.getProperties().getProperty("oracle.container.image");
Expand All @@ -27,15 +30,19 @@ private static String resolveImageName() {
}

public OracleContainer() {
super(resolveImageName());
this(resolveImageName());
}

public OracleContainer(String dockerImageName) {
super(dockerImageName);
withStartupTimeoutSeconds(DEFAULT_STARTUP_TIMEOUT_SECONDS);
withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS);
}

public OracleContainer(Future<String> dockerImageName) {
super(dockerImageName);
withStartupTimeoutSeconds(DEFAULT_STARTUP_TIMEOUT_SECONDS);
withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS);
}

@Override
Expand All @@ -45,7 +52,6 @@ protected Integer getLivenessCheckPort() {

@Override
protected void configure() {

addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT);
}

Expand Down Expand Up @@ -87,9 +93,4 @@ public Integer getWebPort() {
public String getTestQueryString() {
return "SELECT 1 FROM DUAL";
}

@Override
protected int getStartupTimeoutSeconds() {
return 240;
}
}