Skip to content

Commit a556beb

Browse files
committed
Add documentation for DependsOn
1 parent d1b13d7 commit a556beb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package generic;
2+
3+
import org.junit.Rule;
4+
import org.junit.Test;
5+
import org.testcontainers.containers.GenericContainer;
6+
import org.testcontainers.utility.DockerImageName;
7+
8+
import static org.junit.Assert.assertTrue;
9+
10+
public class DependsOnTest {
11+
12+
@Rule
13+
// dependsOn {
14+
public GenericContainer<?> redis = new GenericContainer<>("redis:3.0.2")
15+
.withExposedPorts(6379);
16+
17+
public GenericContainer<?> nginx = new GenericContainer<>(DockerImageName.parse("nginx:1.9.4"))
18+
.dependsOn(redis)
19+
.withExposedPorts(80);
20+
// }
21+
22+
@Test
23+
public void testContainersAllStarted() {
24+
assertTrue(redis.isRunning());
25+
assertTrue(nginx.isRunning());
26+
}
27+
}

docs/features/startup_and_waits.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Waiting for containers to start or be ready
22

3+
## Depending on another container
4+
5+
When using multiple containers, it is possible that one container that you are starting relies on the other to be started before it should be started itself. An example of this might be a database that needs to be started before your application container can link to it. You can tell a container that it depends on another container by using the `dependsOn` method:
6+
7+
<!--codeinclude-->
8+
[Depending on another container](../examples/junit4/generic/src/test/java/generic/DependsOnTest.java) inside_block:dependsOn
9+
<!--/codeinclude-->
10+
311
!!! info "Wait strategies vs Startup strategies"
412

513
**Wait strategy:** is the container in a state that is useful for testing. This is generally approximated as 'can we talk to this container over the network'. However, there are quite a few variations and nuances.

0 commit comments

Comments
 (0)