Skip to content

Commit

Permalink
Added builder for timeouts in JdbcDatabaseContainer (testcontainers#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanHufschmidt committed Jun 13, 2018
1 parent 5cdd8dc commit eab9385
Showing 1 changed file with 27 additions and 2 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 @@ -190,13 +215,13 @@ public void addParameter(String paramName, String value) {
* @return startup time to allow, including image pull time, in seconds
*/
protected int getStartupTimeoutSeconds() {
return 120;
return startupTimeoutSeconds;
}

/**
* @return time to allow for the database to start and establish an initial connection, in seconds
*/
protected int getConnectTimeoutSeconds() {
return 120;
return connectTimeoutSeconds;
}
}

0 comments on commit eab9385

Please sign in to comment.