Skip to content

Commit

Permalink
Upgrade dependencies.
Browse files Browse the repository at this point in the history
[resolves #628]
  • Loading branch information
mp911de committed Jan 9, 2024
1 parent 70c32c4 commit debb7e5
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import java.net.URISyntaxException;
Expand Down Expand Up @@ -118,18 +121,14 @@ private void startPrimary(Network network) {
}

private void startStandby(Network network) {
this.standby = new PostgreSQLContainer<>(PostgresqlServerExtension.IMAGE_NAME)
this.standby = new CustomPostgreSQLContainer(PostgresqlServerExtension.IMAGE_NAME)
.withNetwork(network)
.withCopyFileToContainer(getHostPath("setup-standby.sh", 0755), "/setup-standby.sh")
.withCommand("/setup-standby.sh")
.withEnv("PG_REP_USER", "replication")
.withEnv("PG_REP_PASSWORD", "replication_password")
.withEnv("PG_MASTER_HOST", "postgres-primary")
.withEnv("PG_MASTER_PORT", "5432");
this.standby.setWaitStrategy(new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept .* connections.*\\s")
.withTimes(1)
.withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS)));
this.standby.start();
HikariConfig standbyConfig = new HikariConfig();
standbyConfig.setJdbcUrl(this.standby.getJdbcUrl());
Expand All @@ -138,4 +137,16 @@ private void startStandby(Network network) {
this.standbyDataSource = new HikariDataSource(standbyConfig);
}

// setWaitStrategy() doesn't seem to work, only inside constructor
static class CustomPostgreSQLContainer extends PostgreSQLContainer<CustomPostgreSQLContainer> {
public CustomPostgreSQLContainer(String dockerImageName) {
super(DockerImageName.parse(dockerImageName));
this.waitStrategy =
new LogMessageWaitStrategy()
.withRegEx(".*database system is ready to accept .*connections.*\\s")
.withTimes(1)
.withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS));
}
}

}

0 comments on commit debb7e5

Please sign in to comment.