Skip to content

Commit

Permalink
Added builder for timeouts in JdbcDatabaseContainer (#715) (#748)
Browse files Browse the repository at this point in the history
* Added builder for timeouts in JdbcDatabaseContainer (#715)

* Adjusted Oracle and SQL Server to use other default timeouts (#715)
  • Loading branch information
StefanHufschmidt authored and bsideup committed Jun 13, 2018
1 parent 7936267 commit b4920c6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
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;
}
}

0 comments on commit b4920c6

Please sign in to comment.