Skip to content

Commit

Permalink
Change PostgreSQLContainer wait behaviour (fix #317) (#327)
Browse files Browse the repository at this point in the history
* Update to latest postgres jdbc driver to make error logs visible

* Change PostgreSQLContainer to use WaitingConsumer for waiting instead of SQL query (#317)

Fix #317

* Make OutputFrame return empty String if containing no bytes

* Change PostgreSQLContainer to use LogMessageWaitStrategy (#317)

Fix #317
  • Loading branch information
kiview authored and rnorth committed Apr 30, 2017
1 parent f8fdccb commit 36613b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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);
}
}

0 comments on commit 36613b8

Please sign in to comment.