Skip to content

Commit aff0112

Browse files
author
Anastasiia Smirnova
committed
Update testcontainers to 1.15.0-rc2 (fix for a breaking change that appeared in Docker for Mac v2.4.0.0 testcontainers/testcontainers-java#3159)
1 parent 6455696 commit aff0112

File tree

6 files changed

+71
-133
lines changed

6 files changed

+71
-133
lines changed

embedded-kafka/src/main/java/com/playtika/test/kafka/KafkaTopicsConfigurer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323
*/
2424
package com.playtika.test.kafka;
2525

26-
import com.playtika.test.common.utils.ContainerUtils;
2726
import com.playtika.test.kafka.properties.KafkaConfigurationProperties;
2827
import com.playtika.test.kafka.properties.ZookeeperConfigurationProperties;
2928
import lombok.Getter;
3029
import lombok.RequiredArgsConstructor;
3130
import lombok.extern.slf4j.Slf4j;
31+
import org.testcontainers.containers.Container;
3232
import org.testcontainers.containers.GenericContainer;
3333

3434
import javax.annotation.PostConstruct;
3535
import java.util.Collection;
3636

37+
import static com.playtika.test.common.utils.ContainerUtils.executeInContainer;
38+
3739
@Slf4j
3840
@RequiredArgsConstructor
3941
@Getter
@@ -60,9 +62,8 @@ public void createTopics(Collection<String> topics) {
6062

6163
private void createTopic(String topic) {
6264
String[] createTopicCmd = getCreateTopicCmd(topic, zookeeperProperties.getZookeeperConnect());
63-
ContainerUtils.ExecCmdResult output = ContainerUtils.execCmd(this.kafka.getDockerClient(), this.kafka.getContainerId(), createTopicCmd);
64-
log.debug("Topic={} creation cmd='{}' exitCode={} : {}",
65-
topic, createTopicCmd, output.getExitCode(), output.getOutput());
65+
Container.ExecResult execResult = executeInContainer(this.kafka, createTopicCmd);
66+
log.debug("Topic={} creation cmd='{}' execResult={}", topic, createTopicCmd, execResult);
6667
}
6768

6869
private void restrictTopics(String username, Collection<String> topics) {
@@ -71,11 +72,11 @@ private void restrictTopics(String username, Collection<String> topics) {
7172
for (String topic : topics) {
7273
String[] topicConsumerACLsCmd = getTopicConsumerACLCmd(username, topic, zookeeperProperties.getZookeeperConnect());
7374
String[] topicProducerACLsCmd = getTopicProducerACLCmd(username, topic, zookeeperProperties.getZookeeperConnect());
74-
ContainerUtils.ExecCmdResult topicConsumerACLsOutput = ContainerUtils.execCmd(this.kafka.getDockerClient(), this.kafka.getContainerId(), topicConsumerACLsCmd);
75-
ContainerUtils.ExecCmdResult topicProducerACLsOutput = ContainerUtils.execCmd(this.kafka.getDockerClient(), this.kafka.getContainerId(), topicProducerACLsCmd);
76-
log.debug("Topic={} consumer ACLs cmd='{}' exitCode={} : {}, producer ACLs cmd='{}' exitCode={} : {}",
77-
topic, topicConsumerACLsCmd, topicConsumerACLsOutput.getExitCode(), topicConsumerACLsOutput.getOutput(),
78-
topicProducerACLsCmd, topicProducerACLsOutput.getExitCode(), topicProducerACLsOutput.getOutput());
75+
Container.ExecResult topicConsumerACLsOutput = executeInContainer(this.kafka, topicConsumerACLsCmd);
76+
Container.ExecResult topicProducerACLsOutput = executeInContainer(this.kafka, topicProducerACLsCmd);
77+
log.debug("Topic={} consumer ACLs cmd='{}' execResult={}, producer ACLs cmd='{}' execResult={}",
78+
topic, topicConsumerACLsCmd, topicConsumerACLsOutput,
79+
topicProducerACLsCmd, topicProducerACLsOutput.getExitCode());
7980
}
8081
log.info("Created ACLs for Kafka topics: {}", topics);
8182
}

embedded-keycloak/src/test/java/com/playtika/test/keycloak/util/RealmInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.playtika.test.keycloak.util;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
35
import lombok.Getter;
46
import lombok.Setter;
57
import lombok.ToString;
6-
import org.testcontainers.shaded.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7-
import org.testcontainers.shaded.com.fasterxml.jackson.annotation.JsonProperty;
88

99
@ToString
1010
@Getter

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
6262
<java.version>1.8</java.version>
6363

64-
<testcontainers.version>1.14.3</testcontainers.version>
64+
<testcontainers.version>1.15.0-rc2</testcontainers.version>
6565
<spring.cloud.version>Hoxton.SR8</spring.cloud.version>
6666

6767
<equalsverifier.version>3.4.2</equalsverifier.version>

testcontainers-common/src/main/java/com/playtika/test/common/checks/AbstractCommandWaitStrategy.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2018 Playtika
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in all
14-
* copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
* SOFTWARE.
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Playtika
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
2323
*/
2424
package com.playtika.test.common.checks;
2525

26-
import com.playtika.test.common.utils.ContainerUtils;
2726
import lombok.extern.slf4j.Slf4j;
28-
import org.testcontainers.DockerClientFactory;
27+
import org.testcontainers.containers.Container;
2928

30-
import static com.playtika.test.common.utils.ContainerUtils.ExecCmdResult;
29+
import java.util.Arrays;
30+
31+
import static com.playtika.test.common.utils.ContainerUtils.executeInContainer;
3132

3233
@Slf4j
3334
public abstract class AbstractCommandWaitStrategy extends AbstractRetryingWaitStrategy {
@@ -36,14 +37,14 @@ public abstract class AbstractCommandWaitStrategy extends AbstractRetryingWaitSt
3637

3738
protected boolean isReady() {
3839
String commandName = getContainerType();
40+
3941
String containerId = waitStrategyTarget.getContainerId();
40-
log.debug("{} execution of command {} for container id: {} ", commandName, containerId);
42+
String[] checkCommand = getCheckCommand();
43+
log.debug("{} execution of command {} for container id: {} ", commandName, Arrays.toString(checkCommand), containerId);
4144

42-
ExecCmdResult healthCheckCmdResult =
43-
ContainerUtils.execCmd(DockerClientFactory.instance().client(), containerId, getCheckCommand());
45+
Container.ExecResult healthCheckCmdResult = executeInContainer(waitStrategyTarget, checkCommand);
4446

45-
log.debug("{} executed with exitCode: {}, output: {}",
46-
commandName, healthCheckCmdResult.getExitCode(), healthCheckCmdResult.getOutput());
47+
log.debug("{} executed with result: {}", commandName, healthCheckCmdResult);
4748

4849
if (healthCheckCmdResult.getExitCode() != 0) {
4950
log.debug("{} executed with exitCode !=0, considering status as unknown", commandName);
Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2018 Playtika
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in all
14-
* copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
* SOFTWARE.
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Playtika
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
2323
*/
2424
package com.playtika.test.common.utils;
2525

26-
import com.github.dockerjava.api.DockerClient;
27-
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
28-
import com.github.dockerjava.core.command.ExecStartResultCallback;
29-
import lombok.Value;
3026
import lombok.experimental.UtilityClass;
3127
import lombok.extern.slf4j.Slf4j;
3228
import org.slf4j.Logger;
29+
import org.testcontainers.containers.Container;
30+
import org.testcontainers.containers.ContainerState;
3331
import org.testcontainers.containers.GenericContainer;
3432
import org.testcontainers.containers.output.OutputFrame;
3533

36-
import java.io.ByteArrayOutputStream;
3734
import java.io.IOException;
3835
import java.net.ServerSocket;
39-
import java.nio.charset.StandardCharsets;
4036
import java.time.Duration;
4137
import java.time.Instant;
4238
import java.util.Arrays;
@@ -58,8 +54,7 @@ public long startAndLogTime(GenericContainer container) {
5854

5955
if (startupTime < 10L) {
6056
log.info("{} startup time is {} seconds", container.getDockerImageName(), startupTime);
61-
} else
62-
if (startupTime < 20L) {
57+
} else if (startupTime < 20L) {
6358
log.warn("{} startup time is {} seconds", container.getDockerImageName(), startupTime);
6459
} else {
6560
log.error("{} startup time is {} seconds", container.getDockerImageName(), startupTime);
@@ -92,36 +87,12 @@ public static Consumer<OutputFrame> containerLogsConsumer(Logger log) {
9287
};
9388
}
9489

95-
public static ExecCmdResult execCmd(DockerClient dockerClient, String containerId, String[] command) {
96-
ExecCreateCmdResponse cmd = dockerClient.execCreateCmd(containerId)
97-
.withAttachStdout(true)
98-
.withAttachStderr(true)
99-
.withCmd(command)
100-
.exec();
101-
102-
String cmdStdout;
103-
String cmdStderr;
104-
105-
try (ByteArrayOutputStream stdout = new ByteArrayOutputStream();
106-
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
107-
ExecStartResultCallback cmdCallback = new ExecStartResultCallback(stdout, stderr)) {
108-
dockerClient.execStartCmd(cmd.getId()).exec(cmdCallback).awaitCompletion();
109-
cmdStdout = stdout.toString(StandardCharsets.UTF_8.name());
110-
cmdStderr = stderr.toString(StandardCharsets.UTF_8.name());
90+
public static Container.ExecResult executeInContainer(ContainerState container, String[] command) {
91+
try {
92+
return container.execInContainer(command);
11193
} catch (Exception e) {
112-
String format = String.format("Exception was thrown when executing: %s, for container: %s ", Arrays.toString(command), containerId);
94+
String format = String.format("Exception was thrown when executing: %s, for container: %s ", Arrays.toString(command), container.getContainerId());
11395
throw new IllegalStateException(format, e);
11496
}
115-
116-
int exitCode = dockerClient.inspectExecCmd(cmd.getId()).exec().getExitCode();
117-
String output = cmdStdout.isEmpty() ? cmdStderr : cmdStdout;
118-
return new ExecCmdResult(exitCode, output);
11997
}
120-
121-
@Value
122-
public static class ExecCmdResult {
123-
int exitCode;
124-
String output;
125-
}
126-
12798
}

testcontainers-common/src/test/java/com/playtika/test/common/utils/ExecCmdResultTest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)