Skip to content

Commit b8b6d2b

Browse files
committed
Fixed wait strategy
1 parent 8ffc8c1 commit b8b6d2b

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

embedded-db2/src/main/java/com/playtika/testcontainer/db2/EmbeddedDb2BootstrapConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Db2Container db2(ConfigurableEnvironment environment,
7373
if (StringUtils.hasLength(startupLogCheckRegex)) {
7474
WaitStrategy waitStrategy = new LogMessageWaitStrategy()
7575
.withRegEx(startupLogCheckRegex);
76-
db2Container.setWaitStrategy(waitStrategy);
76+
db2Container.waitingFor(waitStrategy);
7777
}
7878

7979
if (properties.isAcceptLicence()) {

embedded-mssqlserver/src/main/java/com/playtika/testcontainer/mssqlserver/EmbeddedMSSQLServerBootstrapConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public EmbeddedMSSQLServerContainer mssqlserver(ConfigurableEnvironment environm
7272
if (StringUtils.hasLength(startupLogCheckRegex)) {
7373
WaitStrategy waitStrategy = new LogMessageWaitStrategy()
7474
.withRegEx(startupLogCheckRegex);
75-
mssqlServerContainer.setWaitStrategy(waitStrategy);
75+
mssqlServerContainer.waitingFor(waitStrategy);
7676
}
7777

7878
if (properties.isAcceptLicence()) {

embedded-postgresql/src/main/java/com/playtika/testcontainer/postgresql/EmbeddedPostgreSQLBootstrapConfiguration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
import org.testcontainers.containers.PostgreSQLContainer;
1919
import org.testcontainers.containers.ToxiproxyContainer;
2020
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
21+
import org.testcontainers.containers.wait.strategy.ShellStrategy;
2122
import org.testcontainers.containers.wait.strategy.WaitStrategy;
2223

24+
import java.time.Duration;
25+
import java.time.temporal.ChronoUnit;
2326
import java.util.LinkedHashMap;
2427
import java.util.Map;
2528
import java.util.Optional;
2629

2730
import static com.playtika.testcontainer.common.utils.ContainerUtils.configureCommonsAndStart;
2831
import static com.playtika.testcontainer.postgresql.PostgreSQLProperties.BEAN_NAME_EMBEDDED_POSTGRESQL;
32+
import static java.lang.String.format;
2933

3034
@Slf4j
3135
@Configuration
@@ -71,11 +75,15 @@ public PostgreSQLContainer postgresql(ConfigurableEnvironment environment,
7175

7276
network.ifPresent(postgresql::withNetwork);
7377

78+
postgresql.waitingFor(new ShellStrategy()
79+
.withCommand(format("pg_isready -U %s -d %s", properties.getUser(), properties.getDatabase()))
80+
.withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS)));
81+
7482
String startupLogCheckRegex = properties.getStartupLogCheckRegex();
7583
if (StringUtils.hasLength(startupLogCheckRegex)) {
7684
WaitStrategy waitStrategy = new LogMessageWaitStrategy()
7785
.withRegEx(startupLogCheckRegex);
78-
postgresql.setWaitStrategy(waitStrategy);
86+
postgresql.waitingFor(waitStrategy);
7987
}
8088

8189
postgresql = (PostgreSQLContainer) configureCommonsAndStart(postgresql, properties, log);

embedded-selenium/src/main/java/com/playtika/testcontainer/selenium/EmbeddedSeleniumBootstrapConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public BrowserWebDriverContainer selenium(ConfigurableEnvironment environment,
8888
? new BrowserWebDriverContainer<>(ContainerUtils.getDockerImageName(properties))
8989
: new BrowserWebDriverContainer<>();
9090

91-
container.setWaitStrategy(getWaitStrategy());
91+
container.waitingFor(getWaitStrategy());
9292
container.withCapabilities(capabilities);
9393
container.withRecordingFileFactory(getRecordingFileFactory());
9494
container.withNetworkAliases(SELENIUM_NETWORK_ALIAS);

embedded-spicedb/src/test/java/com/playtika/testcontainer/spicedb/EmbeddedSpiceDbBootstrapConfigurationTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ void shouldConnect() throws InterruptedException {
6060
.setSchema(schema)
6161
.build();
6262

63-
SchemaServiceOuterClass.WriteSchemaResponse response;
64-
try {
65-
response = schemaService.writeSchema(request);
66-
response.getWrittenAt().getToken();
67-
} catch (Exception e) {
68-
log.error(e.getMessage(), e);
69-
}
63+
SchemaServiceOuterClass.WriteSchemaResponse response = schemaService.writeSchema(request);
64+
65+
assertThat(response.getWrittenAt().getToken()).isNotEmpty();
7066
}
7167

7268
@Test

0 commit comments

Comments
 (0)