|
1 | 1 | package org.testcontainers.containers; |
2 | 2 |
|
3 | | -import com.github.dockerjava.api.model.Frame; |
4 | 3 | import lombok.Getter; |
5 | 4 | import lombok.NonNull; |
6 | 5 | import lombok.SneakyThrows; |
7 | 6 | import lombok.ToString; |
8 | 7 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; |
9 | | -import org.rnorth.ducttape.TimeoutException; |
10 | | -import org.rnorth.ducttape.unreliables.Unreliables; |
11 | | -import org.testcontainers.containers.output.FrameConsumerResultCallback; |
| 8 | +import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; |
12 | 9 | import org.testcontainers.utility.TestcontainersConfiguration; |
13 | 10 |
|
14 | | -import java.io.Closeable; |
15 | 11 | import java.io.File; |
16 | 12 | import java.io.InputStream; |
17 | 13 | import java.nio.file.Files; |
18 | 14 | import java.nio.file.StandardCopyOption; |
| 15 | +import java.time.Duration; |
19 | 16 | import java.util.Base64; |
20 | | -import java.util.concurrent.CountDownLatch; |
21 | | -import java.util.concurrent.TimeUnit; |
| 17 | + |
| 18 | +import static java.time.temporal.ChronoUnit.SECONDS; |
22 | 19 |
|
23 | 20 | /** |
24 | 21 | * 'Sidekick container' with the sole purpose of recording the VNC screen output from another container. |
@@ -59,39 +56,9 @@ public VncRecordingContainer(@NonNull Network network, @NonNull String targetNet |
59 | 56 |
|
60 | 57 | this.targetNetworkAlias = targetNetworkAlias; |
61 | 58 | withNetwork(network); |
62 | | - |
63 | | - waitingFor(new AbstractWaitStrategy() { |
64 | | - |
65 | | - @Override |
66 | | - protected void waitUntilReady() { |
67 | | - try { |
68 | | - Unreliables.retryUntilTrue((int) startupTimeout.toMillis(), TimeUnit.MILLISECONDS, () -> { |
69 | | - CountDownLatch latch = new CountDownLatch(1); |
70 | | - |
71 | | - FrameConsumerResultCallback callback = new FrameConsumerResultCallback() { |
72 | | - @Override |
73 | | - public void onNext(Frame frame) { |
74 | | - if (frame != null && new String(frame.getPayload()).contains("Connected")) { |
75 | | - latch.countDown(); |
76 | | - } |
77 | | - } |
78 | | - }; |
79 | | - |
80 | | - try ( |
81 | | - Closeable __ = dockerClient.logContainerCmd(getContainerId()) |
82 | | - .withFollowStream(true) |
83 | | - .withSince(0) |
84 | | - .withStdErr(true) |
85 | | - .exec(callback) |
86 | | - ) { |
87 | | - return latch.await(1, TimeUnit.SECONDS); |
88 | | - } |
89 | | - }); |
90 | | - } catch (TimeoutException e) { |
91 | | - throw new ContainerLaunchException("Timed out waiting for log output", e); |
92 | | - } |
93 | | - } |
94 | | - }); |
| 59 | + waitingFor(new LogMessageWaitStrategy() |
| 60 | + .withRegEx(".*Connected.*") |
| 61 | + .withStartupTimeout(Duration.of(15, SECONDS))); |
95 | 62 | } |
96 | 63 |
|
97 | 64 | public VncRecordingContainer withVncPassword(@NonNull String vncPassword) { |
|
0 commit comments