forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitStrategiesTest.java
More file actions
78 lines (64 loc) · 2.29 KB
/
WaitStrategiesTest.java
File metadata and controls
78 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package generic;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.utility.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;
public class WaitStrategiesTest {
@Rule
// waitForNetworkListening {
public GenericContainer nginx = new GenericContainer(DockerImageName.parse("nginx:1.27.0-alpine3.19-slim")) //
.withExposedPorts(80);
// }
@Rule
// waitForSimpleHttp {
public GenericContainer nginxWithHttpWait = new GenericContainer(
DockerImageName.parse("nginx:1.27.0-alpine3.19-slim")
)
.withExposedPorts(80)
.waitingFor(Wait.forHttp("/"));
// }
@Rule
// logMessageWait {
public GenericContainer containerWithLogWait = new GenericContainer(DockerImageName.parse("redis:6-alpine"))
.withExposedPorts(6379)
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1));
// }
private static final HttpWaitStrategy MULTI_CODE_HTTP_WAIT =
// spotless:off
// waitForHttpWithMultipleStatusCodes {
Wait.forHttp("/")
.forStatusCode(200)
.forStatusCode(301);
// }
// spotless:on
private static final HttpWaitStrategy PREDICATE_HTTP_WAIT =
// spotless:off
// waitForHttpWithStatusCodePredicate {
Wait.forHttp("/all")
.forStatusCodeMatching(it -> it >= 200 && it < 300 || it == 401);
// }
// spotless:on
private static final HttpWaitStrategy TLS_HTTP_WAIT =
// spotless:off
// waitForHttpWithTls {
Wait.forHttp("/all")
.usingTls();
// }
// spotless:on
private static final WaitStrategy HEALTHCHECK_WAIT =
// spotless:off
// healthcheckWait {
Wait.forHealthcheck();
// }
// spotless:on
@Test
public void testContainersAllStarted() {
assertThat(nginx.isRunning()).isTrue();
assertThat(nginxWithHttpWait.isRunning()).isTrue();
assertThat(containerWithLogWait.isRunning()).isTrue();
}
}