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

Change PostgreSQLContainer wait behaviour (fix #317) #327

Merged
merged 4 commits into from
Apr 30, 2017
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 @@ -30,7 +30,7 @@ public byte[] getBytes() {
public String getUtf8String() {

if (bytes == null) {
return null;
return "";
}

return new String(bytes, Charsets.UTF_8);
Expand Down
2 changes: 1 addition & 1 deletion modules/jdbc-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
<version>42.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.testcontainers.containers;

import org.testcontainers.containers.wait.LogMessageWaitStrategy;

import java.time.Duration;

import static java.time.temporal.ChronoUnit.SECONDS;

/**
* @author richardnorth
*/
public class PostgreSQLContainer<SELF extends PostgreSQLContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
public static final String NAME = "postgresql";
public static final String IMAGE = "postgres";
static final String NAME = "postgresql";
static final String IMAGE = "postgres";
public static final Integer POSTGRESQL_PORT = 5432;
private String databaseName = "test";
private String username = "test";
Expand All @@ -17,6 +23,10 @@ public PostgreSQLContainer() {

public PostgreSQLContainer(final String dockerImageName) {
super(dockerImageName);
this.waitStrategy = new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept connections.*\\s")
.withTimes(2)
.withStartupTimeout(Duration.of(60, SECONDS));
}

@Override
Expand Down Expand Up @@ -73,4 +83,9 @@ public SELF withPassword(final String password) {
this.password = password;
return self();
}

@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
}
}