-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend from an AbstractLogMessageWaitStrategy
- Loading branch information
Showing
3 changed files
with
78 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...main/java/org/testcontainers/containers/wait/strategy/AbstractLogMessageWaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.testcontainers.containers.wait.strategy; | ||
|
||
import com.github.dockerjava.api.command.LogContainerCmd; | ||
import lombok.SneakyThrows; | ||
import org.testcontainers.containers.ContainerLaunchException; | ||
import org.testcontainers.containers.output.FrameConsumerResultCallback; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
import org.testcontainers.containers.output.WaitingConsumer; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.function.Predicate; | ||
|
||
public abstract class AbstractLogMessageWaitStrategy extends AbstractWaitStrategy { | ||
|
||
protected int times = 1; | ||
|
||
@Override | ||
@SneakyThrows(IOException.class) | ||
protected void waitUntilReady() { | ||
WaitingConsumer waitingConsumer = new WaitingConsumer(); | ||
|
||
LogContainerCmd cmd = waitStrategyTarget | ||
.getDockerClient() | ||
.logContainerCmd(waitStrategyTarget.getContainerId()) | ||
.withFollowStream(true) | ||
.withSince(0) | ||
.withStdOut(true) | ||
.withStdErr(true); | ||
|
||
try (FrameConsumerResultCallback callback = new FrameConsumerResultCallback()) { | ||
callback.addConsumer(OutputFrame.OutputType.STDOUT, waitingConsumer); | ||
callback.addConsumer(OutputFrame.OutputType.STDERR, waitingConsumer); | ||
|
||
cmd.exec(callback); | ||
|
||
try { | ||
waitingConsumer.waitUntil(waitPredicate(), startupTimeout.getSeconds(), TimeUnit.SECONDS, times); | ||
} catch (TimeoutException e) { | ||
throw new ContainerLaunchException(timeoutErrorMessage()); | ||
} | ||
} | ||
} | ||
|
||
protected abstract Predicate<OutputFrame> waitPredicate(); | ||
protected abstract String timeoutErrorMessage(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters