Skip to content

Commit 34b8d7e

Browse files
srempferStefan Rempferrnorthbsideup
authored
Using LogMessageWaitStrategy for VncRecordingContainer (#2063) (#2547)
Co-authored-by: Stefan Rempfer <[email protected]> Co-authored-by: Richard North <[email protected]> Co-authored-by: Sergei Egorov <[email protected]>
1 parent c6e0cd9 commit 34b8d7e

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

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

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

3-
import com.github.dockerjava.api.model.Frame;
43
import lombok.Getter;
54
import lombok.NonNull;
65
import lombok.SneakyThrows;
76
import lombok.ToString;
87
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;
129
import org.testcontainers.utility.TestcontainersConfiguration;
1310

14-
import java.io.Closeable;
1511
import java.io.File;
1612
import java.io.InputStream;
1713
import java.nio.file.Files;
1814
import java.nio.file.StandardCopyOption;
15+
import java.time.Duration;
1916
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;
2219

2320
/**
2421
* '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
5956

6057
this.targetNetworkAlias = targetNetworkAlias;
6158
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)));
9562
}
9663

9764
public VncRecordingContainer withVncPassword(@NonNull String vncPassword) {

0 commit comments

Comments
 (0)