Skip to content

Commit 8e57d07

Browse files
authored
Merge branch 'master' into master
2 parents 47c39e7 + 69b3bc2 commit 8e57d07

File tree

35 files changed

+218
-93
lines changed

35 files changed

+218
-93
lines changed

.envrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
pull_request: {}
55
push: { branches: [ master ] }
66

7+
env:
8+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
9+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
10+
711
jobs:
812
find_gradle_jobs:
913
runs-on: ubuntu-18.04

core/build.gradle

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55

66
dependencies {
77
// https://github.com/melix/japicmp-gradle-plugin/issues/36
8-
classpath 'com.google.guava:guava:28.2-jre'
8+
classpath 'com.google.guava:guava:29.0-jre'
99
}
1010
}
1111

@@ -110,13 +110,13 @@ if (!org.gradle.internal.os.OperatingSystem.current().isWindows()) {
110110
}
111111

112112
dependencies {
113-
baseline 'org.testcontainers:testcontainers:1.14.0', {
113+
baseline 'org.testcontainers:testcontainers:1.14.1', {
114114
exclude group: "*", module: "*"
115115
}
116116

117117
compile 'junit:junit:4.12'
118118
compile 'org.slf4j:slf4j-api:1.7.30'
119-
compile 'org.jetbrains:annotations:17.0.0'
119+
compile 'org.jetbrains:annotations:19.0.0'
120120
compile 'org.apache.commons:commons-compress:1.20'
121121
compile ('org.rnorth.duct-tape:duct-tape:1.0.8') {
122122
exclude(group: 'org.jetbrains', module: 'annotations')
@@ -133,7 +133,7 @@ dependencies {
133133

134134
compile "net.java.dev.jna:jna-platform:5.5.0"
135135

136-
shaded ('org.scala-sbt.ipcsocket:ipcsocket:1.0.0') {
136+
shaded ('org.scala-sbt.ipcsocket:ipcsocket:1.0.1') {
137137
exclude(group: "net.java.dev.jna")
138138
}
139139

@@ -146,7 +146,7 @@ dependencies {
146146

147147
shaded "org.yaml:snakeyaml:1.25"
148148

149-
shaded 'com.squareup.okhttp3:okhttp:3.14.6'
149+
shaded 'com.squareup.okhttp3:okhttp:3.14.8'
150150

151151
shaded 'org.glassfish.main.external:trilead-ssh2-repackaged:4.1.2'
152152

@@ -155,21 +155,22 @@ dependencies {
155155
}
156156

157157
testCompile 'org.apache.httpcomponents:httpclient:4.5.9'
158-
testCompile 'redis.clients:jedis:3.2.0'
159-
testCompile 'com.rabbitmq:amqp-client:5.8.0'
160-
testCompile 'org.mongodb:mongo-java-driver:3.12.3'
158+
testCompile 'redis.clients:jedis:3.3.0'
159+
testCompile 'com.rabbitmq:amqp-client:5.9.0'
160+
testCompile 'org.mongodb:mongo-java-driver:3.12.4'
161+
161162
testCompile ('org.mockito:mockito-core:3.3.3') {
162163
exclude(module: 'hamcrest-core')
163164
}
164165
// Synthetic JAR used for MountableFileTest and DirectoryTarResourceTest
165166
testCompile files('testlib/repo/fakejar/fakejar/0/fakejar-0.jar')
166167

167-
testCompile 'org.assertj:assertj-core:3.15.0'
168+
testCompile 'org.assertj:assertj-core:3.16.0'
168169
testCompile project(':test-support')
169170

170171
jarFileTestCompileOnly "org.projectlombok:lombok:${lombok.version}"
171172
jarFileTestAnnotationProcessor "org.projectlombok:lombok:${lombok.version}"
172173
jarFileTestCompile 'junit:junit:4.12'
173-
jarFileTestCompile 'org.assertj:assertj-core:3.14.0'
174+
jarFileTestCompile 'org.assertj:assertj-core:3.16.0'
174175
jarFileTestCompile 'org.ow2.asm:asm-debug-all:5.2'
175176
}

core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.common.base.Splitter;
77
import com.google.common.base.Strings;
88
import com.google.common.collect.Maps;
9+
import com.google.common.collect.Sets;
910
import com.google.common.util.concurrent.Uninterruptibles;
1011
import lombok.NonNull;
1112
import lombok.extern.slf4j.Slf4j;
@@ -216,6 +217,20 @@ private void createServices() {
216217

217218
private void waitUntilServiceStarted() {
218219
listChildContainers().forEach(this::createServiceInstance);
220+
221+
Set<String> servicesToWaitFor = waitStrategyMap.keySet();
222+
Set<String> instantiatedServices = serviceInstanceMap.keySet();
223+
Sets.SetView<String> missingServiceInstances =
224+
Sets.difference(servicesToWaitFor, instantiatedServices);
225+
226+
if (!missingServiceInstances.isEmpty()) {
227+
throw new IllegalStateException(
228+
"Services named " + missingServiceInstances + " " +
229+
"do not exist, but wait conditions have been defined " +
230+
"for them. This might mean that you misspelled " +
231+
"the service name when defining the wait condition.");
232+
}
233+
219234
serviceInstanceMap.forEach(this::waitUntilServiceStarted);
220235
}
221236

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ protected void doStart() {
307307
Instant startedAt = Instant.now();
308308

309309
logger().debug("Starting container: {}", getDockerImageName());
310-
logger().debug("Trying to start container: {}", getDockerImageName());
311310

312311
AtomicInteger attempt = new AtomicInteger(0);
313312
Unreliables.retryUntilSuccess(startupAttempts, () -> {

core/src/test/java/org/testcontainers/junit/DockerComposeWaitStrategyTest.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
package org.testcontainers.junit;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.catchThrowable;
5+
6+
import java.io.File;
7+
import java.time.Duration;
8+
import org.junit.After;
9+
import org.junit.Before;
310
import org.junit.Test;
411
import org.junit.runner.Description;
12+
import org.mockito.Mockito;
513
import org.rnorth.visibleassertions.VisibleAssertions;
614
import org.testcontainers.containers.DockerComposeContainer;
715
import org.testcontainers.containers.wait.strategy.Wait;
8-
9-
import java.io.File;
10-
import java.time.Duration;
16+
import org.testcontainers.containers.wait.strategy.WaitStrategy;
1117

1218
public class DockerComposeWaitStrategyTest {
1319

1420
private static final int REDIS_PORT = 6379;
1521

22+
private DockerComposeContainer<?> environment;
23+
24+
@Before
25+
public final void setUp() {
26+
environment = new DockerComposeContainer<>(
27+
new File("src/test/resources/compose-test.yml"));
28+
}
29+
30+
@After
31+
public final void cleanUp() {
32+
environment.stop();
33+
}
34+
1635
@Test
1736
public void testWaitOnListeningPort() {
18-
final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
37+
environment
1938
.withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort());
2039

2140
try {
@@ -28,7 +47,7 @@ public void testWaitOnListeningPort() {
2847

2948
@Test
3049
public void testWaitOnMultipleStrategiesPassing() {
31-
final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
50+
environment
3251
.withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort())
3352
.withExposedService("db_1", 3306, Wait.forLogMessage(".*ready for connections.*\\s", 1))
3453
.withTailChildContainers(true);
@@ -43,7 +62,7 @@ public void testWaitOnMultipleStrategiesPassing() {
4362

4463
@Test
4564
public void testWaitingFails() {
46-
final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
65+
environment
4766
.withExposedService("redis_1", REDIS_PORT, Wait.forHttp("/test").withStartupTimeout(Duration.ofSeconds(10)));
4867
VisibleAssertions.assertThrows("waiting on an invalid http path times out",
4968
RuntimeException.class,
@@ -52,7 +71,7 @@ public void testWaitingFails() {
5271

5372
@Test
5473
public void testWaitOnOneOfMultipleStrategiesFailing() {
55-
final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
74+
environment
5675
.withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(10)))
5776
.waitingFor("db_1", Wait.forLogMessage(".*test test test.*\\s", 1).withStartupTimeout(Duration.ofSeconds(10)))
5877
.withTailChildContainers(true);
@@ -62,4 +81,26 @@ public void testWaitOnOneOfMultipleStrategiesFailing() {
6281
() -> environment.starting(Description.createTestDescription(Object.class, "name")));
6382
}
6483

84+
@Test
85+
public void testWaitingForNonexistentServices() {
86+
String existentServiceName = "db_1";
87+
String nonexistentServiceName1 = "some_nonexistent_service_1";
88+
String nonexistentServiceName2 = "some_nonexistent_service_2";
89+
WaitStrategy someWaitStrategy = Mockito.mock(WaitStrategy.class);
90+
91+
environment
92+
.waitingFor(existentServiceName, someWaitStrategy)
93+
.waitingFor(nonexistentServiceName1, someWaitStrategy)
94+
.waitingFor(nonexistentServiceName2, someWaitStrategy);
95+
96+
Throwable thrownWhenRequestedToWaitForNonexistentService =
97+
catchThrowable(environment::start);
98+
99+
assertThat(thrownWhenRequestedToWaitForNonexistentService)
100+
.isInstanceOf(IllegalStateException.class)
101+
.hasMessageContaining(
102+
nonexistentServiceName1,
103+
nonexistentServiceName2)
104+
.hasMessageNotContaining(existentServiceName);
105+
}
65106
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
redis:
22
image: redis
33
db:
4-
image: orchardup/mysql
4+
image: mysql:5.7.22
55
environment:
6-
MYSQL_DATABASE: wordpress
6+
MYSQL_RANDOM_ROOT_PASSWORD: "true"

docs/modules/elasticsearch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ container.stop();
3636
```
3737

3838
Note that if you are still using the [TransportClient](https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.3/transport-client.html)
39-
(not recommended as deprecated), the default cluster name is set to `docker-cluster` so you need to change `cluster.name` setting
39+
(not recommended as it is deprecated), the default cluster name is set to `docker-cluster` so you need to change `cluster.name` setting
4040
or set `client.transport.ignore_cluster_name` to `true`.
4141

4242
## Choose your Elasticsearch license

docs/modules/kafka.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ new KafkaContainer().withExternalZookeeper("localhost:2181")
4242

4343
If your test needs to run some other Docker container which needs access to the Kafka, do the following:
4444

45-
* Run you other container on the same network as Kafka container. E.g. as following:
45+
* Run your other container on the same network as Kafka container, e.g.:
4646
```java
4747
new GenericContainer("myImage").withNetwork(kafka.getNetwork())
4848
```

docs/modules/toxiproxy.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ We do this as follows:
2929
[Starting proxying connections to a target container](../../modules/toxiproxy/src/test/java/org/testcontainers/containers/ToxiproxyTest.java) inside_block:obtainProxyObject
3030
<!--/codeinclude-->
3131

32-
Then, to establish a connection via Toxiproxy, we obtain **Toxiproxy's** proxy host IP and port:
32+
To establish a connection from the test code (on the host machine) to the target container via Toxiproxy, we obtain **Toxiproxy's** proxy host IP and port:
3333

3434
<!--codeinclude-->
35-
[Obtaining proxied host and port](../../modules/toxiproxy/src/test/java/org/testcontainers/containers/ToxiproxyTest.java) inside_block:obtainProxiedHostAndPort
35+
[Obtaining proxied host and port for connections from the host machine](../../modules/toxiproxy/src/test/java/org/testcontainers/containers/ToxiproxyTest.java) inside_block:obtainProxiedHostAndPortForHostMachine
3636
<!--/codeinclude-->
3737

38-
Code under test, or other containers, should connect to this proxied host IP and port.
38+
Code under test should connect to this proxied host IP and port.
39+
40+
To establish a connection from a different container on the same network to the target container via Toxiproxy, we use **Toxiproxy's** network alias and original port:
41+
42+
<!--codeinclude-->
43+
[Obtaining proxied host and port for connections from a different container](../../modules/toxiproxy/src/test/java/org/testcontainers/containers/ToxiproxyTest.java) inside_block:obtainProxiedHostAndPortForDifferentContainer
44+
<!--/codeinclude-->
45+
46+
Other containers should connect to this proxied host and port.
3947

4048
Having done this, it is possible to trigger failure conditions ('Toxics') through the `proxy.toxics()` object:
4149

@@ -82,4 +90,3 @@ testCompile "org.testcontainers:toxiproxy:{{latest_version}}"
8290
This module was inspired by a [hotels.com blog post](https://medium.com/hotels-com-technology/i-dont-know-about-resilience-testing-and-so-can-you-b3c59d80012d).
8391

8492
[toxiproxy-java](https://github.com/trekawek/toxiproxy-java) is used to help control failure conditions.
85-

0 commit comments

Comments
 (0)