forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitStrategiesTest.java
71 lines (60 loc) · 2.07 KB
/
WaitStrategiesTest.java
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
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.junit.Assert.assertTrue;
public class WaitStrategiesTest {
@Rule
// waitForNetworkListening {
public GenericContainer nginx = new GenericContainer(DockerImageName.parse("nginx:1.9.4"))
.withExposedPorts(80);
// }
@Rule
// waitForSimpleHttp {
public GenericContainer nginxWithHttpWait = new GenericContainer(DockerImageName.parse("nginx:1.9.4"))
.withExposedPorts(80)
.waitingFor(Wait.forHttp("/"));
// }
@Rule
// logMessageWait {
public GenericContainer containerWithLogWait = new GenericContainer(DockerImageName.parse("redis:5.0.3"))
.withExposedPorts(6379)
.waitingFor(
Wait.forLogMessage(".*Ready to accept connections.*\\n", 1)
);
// }
private static final HttpWaitStrategy MULTI_CODE_HTTP_WAIT =
// waitForHttpWithMultipleStatusCodes {
Wait.forHttp("/")
.forStatusCode(200)
.forStatusCode(301)
// }
;
private static final HttpWaitStrategy PREDICATE_HTTP_WAIT =
// waitForHttpWithStatusCodePredicate {
Wait.forHttp("/all")
.forStatusCodeMatching(it -> it >= 200 && it < 300 || it == 401)
// }
;
private static final HttpWaitStrategy TLS_HTTP_WAIT =
// waitForHttpWithTls {
Wait.forHttp("/all")
.usingTls()
// }
;
private static final WaitStrategy HEALTHCHECK_WAIT =
// healthcheckWait {
Wait.forHealthcheck()
// }
;
@Test
public void testContainersAllStarted() {
assertTrue(nginx.isRunning());
assertTrue(nginxWithHttpWait.isRunning());
assertTrue(containerWithLogWait.isRunning());
}
}