- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.testcontainers.containers.wait.strategy.WaitStrategyTarget
类的一些代码示例,展示了WaitStrategyTarget
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WaitStrategyTarget
类的具体详情如下:
包路径:org.testcontainers.containers.wait.strategy.WaitStrategyTarget
类名称:WaitStrategyTarget
暂无
代码示例来源:origin: testcontainers/testcontainers-java
@Override
protected void waitUntilReady() {
WaitingConsumer waitingConsumer = new WaitingConsumer();
LogUtils.followOutput(DockerClientFactory.instance().client(), waitStrategyTarget.getContainerId(), waitingConsumer);
Predicate<OutputFrame> waitPredicate = outputFrame ->
// (?s) enables line terminator matching (equivalent to Pattern.DOTALL)
outputFrame.getUtf8String().matches("(?s)" + regEx);
try {
waitingConsumer.waitUntil(waitPredicate, startupTimeout.getSeconds(), TimeUnit.SECONDS, times);
} catch (TimeoutException e) {
throw new ContainerLaunchException("Timed out waiting for log output matching '" + regEx + "'");
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Override
protected void waitUntilReady() {
final Set<Integer> externalLivenessCheckPorts = getLivenessCheckPorts();
if (externalLivenessCheckPorts.isEmpty()) {
log.debug("Liveness check ports of {} is empty. Not waiting.", waitStrategyTarget.getContainerInfo().getName());
return;
}
@SuppressWarnings("unchecked")
List<Integer> exposedPorts = waitStrategyTarget.getExposedPorts();
final Set<Integer> internalPorts = getInternalPorts(externalLivenessCheckPorts, exposedPorts);
Callable<Boolean> internalCheck = new InternalCommandPortListeningCheck(waitStrategyTarget, internalPorts);
Callable<Boolean> externalCheck = new ExternalPortListeningCheck(waitStrategyTarget, externalLivenessCheckPorts);
try {
Unreliables.retryUntilTrue((int) startupTimeout.getSeconds(), TimeUnit.SECONDS,
() -> getRateLimiter().getWhenReady(() -> internalCheck.call() && externalCheck.call()));
} catch (TimeoutException e) {
throw new ContainerLaunchException("Timed out waiting for container port to open (" +
waitStrategyTarget.getContainerIpAddress() +
" ports: " +
externalLivenessCheckPorts +
" should be listening)");
}
}
代码示例来源:origin: testcontainers/testcontainers-java
/**
* @return the ports on which to check if the container is ready
*/
default Set<Integer> getLivenessCheckPortNumbers() {
final Set<Integer> result = getExposedPorts().stream()
.map(this::getMappedPort).distinct().collect(Collectors.toSet());
result.addAll(getBoundPortNumbers());
return result;
}
}
代码示例来源:origin: Playtika/testcontainers-spring-boot
@Override
protected boolean isReady() {
String containerId = waitStrategyTarget.getContainerId();
log.debug("Check Aerospike container {} status", containerId);
InspectContainerResponse containerInfo = waitStrategyTarget.getContainerInfo();
if (containerInfo == null) {
log.debug("Aerospike container[{}] doesn't contain info. Abnormal situation, should not happen.", containerId);
return false;
}
int port = getMappedPort(containerInfo.getNetworkSettings(), properties.port);
String host = DockerClientFactory.instance().dockerHostIpAddress();
//TODO: Remove dependency to client https://www.aerospike.com/docs/tools/asmonitor/common_tasks.html
try (AerospikeClient client = new AerospikeClient(host, port)) {
return client.isConnected();
} catch (AerospikeException.Connection e) {
log.debug("Aerospike container: {} not yet started. {}", containerId, e.getMessage());
}
return false;
}
代码示例来源:origin: testcontainers/testcontainers-java
private void tryPort(Integer internalPort) {
String[][] commands = {
{"/bin/sh", "-c", format("cat /proc/net/tcp{,6} | awk '{print $2}' | grep -i :%x && echo %s", internalPort, SUCCESS_MARKER)},
{"/bin/sh", "-c", format("nc -vz -w 1 localhost %d && echo %s", internalPort, SUCCESS_MARKER)},
{"/bin/bash", "-c", format("</dev/tcp/localhost/%d && echo %s", internalPort, SUCCESS_MARKER)}
};
for (String[] command : commands) {
try {
if (ExecInContainerPattern.execInContainer(waitStrategyTarget.getContainerInfo(), command).getStdout().contains(SUCCESS_MARKER)) {
return;
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
throw new IllegalStateException("Socket not listening yet: " + internalPort);
}
}
代码示例来源:origin: testcontainers/testcontainers-java
/**
* Build the URI on which to check if the container is ready.
*
* @param livenessCheckPort the liveness port
* @return the liveness URI
*/
private URI buildLivenessUri(int livenessCheckPort) {
final String scheme = (tlsEnabled ? "https" : "http") + "://";
final String host = waitStrategyTarget.getContainerIpAddress();
final String portSuffix;
if ((tlsEnabled && 443 == livenessCheckPort) || (!tlsEnabled && 80 == livenessCheckPort)) {
portSuffix = "";
} else {
portSuffix = ":" + String.valueOf(livenessCheckPort);
}
return URI.create(scheme + host + portSuffix + path);
}
代码示例来源:origin: testcontainers/testcontainers-java
/**
* @return the ports on which to check if the container is ready
*/
protected Set<Integer> getLivenessCheckPorts() {
return waitStrategyTarget.getLivenessCheckPortNumbers();
}
代码示例来源:origin: testcontainers/testcontainers-java
private Set<Integer> getInternalPorts(Set<Integer> externalLivenessCheckPorts, List<Integer> exposedPorts) {
return exposedPorts.stream()
.filter(it -> externalLivenessCheckPorts.contains(waitStrategyTarget.getMappedPort(it)))
.collect(Collectors.toSet());
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Override
protected void waitUntilReady() {
final String containerName = waitStrategyTarget.getContainerInfo().getName();
代码示例来源:origin: testcontainers/testcontainers-java
@Before
public void setUp() throws Exception {
listeningSocket1 = new ServerSocket(0);
listeningSocket2 = new ServerSocket(0);
nonListeningSocket = new ServerSocket(0);
nonListeningSocket.close();
mockContainer = mock(WaitStrategyTarget.class);
when(mockContainer.getContainerIpAddress()).thenReturn("127.0.0.1");
}
代码示例来源:origin: testcontainers/testcontainers-java
/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@NonNull
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
final Set<Integer> result = WaitStrategyTarget.super.getLivenessCheckPortNumbers();
// for backwards compatibility
if (this.getLivenessCheckPort() != null) {
result.add(this.getLivenessCheckPort());
}
return result;
}
代码示例来源:origin: org.testcontainers/testcontainers
private Set<Integer> getInternalPorts(Set<Integer> externalLivenessCheckPorts, List<Integer> exposedPorts) {
return exposedPorts.stream().filter(it -> externalLivenessCheckPorts.contains(waitStrategyTarget.getMappedPort(it))).collect(Collectors.toSet());
}
}
代码示例来源:origin: Playtika/testcontainers-spring-boot
@Override
protected void waitUntilReady() {
long seconds = startupTimeout.getSeconds();
try {
Unreliables.retryUntilTrue((int) seconds, TimeUnit.SECONDS,
() -> getRateLimiter().getWhenReady(this::isReady));
} catch (TimeoutException e) {
throw new ContainerLaunchException(
format("[%s] notifies that container[%s] is not ready after [%d] seconds, container cannot be started.",
getContainerType(), waitStrategyTarget.getContainerId(), seconds));
}
}
代码示例来源:origin: org.testcontainers/testcontainers
@Override
protected void waitUntilReady() {
final Set<Integer> externalLivenessCheckPorts = getLivenessCheckPorts();
if (externalLivenessCheckPorts.isEmpty()) {
log.debug("Liveness check ports of {} is empty. Not waiting.", waitStrategyTarget.getContainerInfo().getName());
return;
}
@SuppressWarnings("unchecked")
List<Integer> exposedPorts = waitStrategyTarget.getExposedPorts();
final Set<Integer> internalPorts = getInternalPorts(externalLivenessCheckPorts, exposedPorts);
Callable<Boolean> internalCheck = new InternalCommandPortListeningCheck(waitStrategyTarget, internalPorts);
Callable<Boolean> externalCheck = new ExternalPortListeningCheck(waitStrategyTarget, externalLivenessCheckPorts);
try {
Unreliables.retryUntilTrue((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> getRateLimiter().getWhenReady(() -> internalCheck.call() && externalCheck.call()));
} catch (TimeoutException e) {
throw new ContainerLaunchException("Timed out waiting for container port to open (" + waitStrategyTarget.getContainerIpAddress() + " ports: " + externalLivenessCheckPorts + " should be listening)");
}
}
代码示例来源:origin: org.testcontainers/testcontainers
private void tryPort(Integer internalPort) {
String[][] commands = {{"/bin/sh", "-c", format("cat /proc/net/tcp{,6} | awk \'{print $2}\' | grep -i :%x && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/sh", "-c", format("nc -vz -w 1 localhost %d && echo %s", internalPort, SUCCESS_MARKER)}, {"/bin/bash", "-c", format("</dev/tcp/localhost/%d && echo %s", internalPort, SUCCESS_MARKER)}};
for (String[] command : commands) {
try {
if (ExecInContainerPattern.execInContainer(waitStrategyTarget.getContainerInfo(), command).getStdout().contains(SUCCESS_MARKER)) {
return;
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
throw new IllegalStateException("Socket not listening yet: " + internalPort);
}
代码示例来源:origin: org.testcontainers/testcontainers
/**
* @return the ports on which to check if the container is ready
*/
default Set<Integer> getLivenessCheckPortNumbers() {
final Set<Integer> result = getExposedPorts().stream()
.map(this::getMappedPort).distinct().collect(Collectors.toSet());
result.addAll(getBoundPortNumbers());
return result;
}
}
代码示例来源:origin: org.testcontainers/testcontainers
/**
* Build the URI on which to check if the container is ready.
*
* @param livenessCheckPort the liveness port
* @return the liveness URI
*/
private URI buildLivenessUri(int livenessCheckPort) {
final String scheme = (tlsEnabled ? "https" : "http") + "://";
final String host = waitStrategyTarget.getContainerIpAddress();
final String portSuffix;
if ((tlsEnabled && 443 == livenessCheckPort) || (!tlsEnabled && 80 == livenessCheckPort)) {
portSuffix = "";
} else {
portSuffix = ":" + String.valueOf(livenessCheckPort);
}
return URI.create(scheme + host + portSuffix + path);
}
代码示例来源:origin: org.testcontainers/testcontainers
/**
* @return the ports on which to check if the container is ready
*/
protected Set<Integer> getLivenessCheckPorts() {
return waitStrategyTarget.getLivenessCheckPortNumbers();
}
代码示例来源:origin: Playtika/testcontainers-spring-boot
protected boolean isReady() {
String commandName = getContainerType();
String containerId = waitStrategyTarget.getContainerId();
log.debug("{} execution of command {} for container id: {} ", commandName, containerId);
ExecCmdResult healthCheckCmdResult =
ContainerUtils.execCmd(DockerClientFactory.instance().client(), containerId, getCheckCommand());
log.debug("{} executed with exitCode: {}, output: {}",
commandName, healthCheckCmdResult.getExitCode(), healthCheckCmdResult.getOutput());
if (healthCheckCmdResult.getExitCode() != 0) {
log.debug("{} executed with exitCode !=0, considering status as unknown", commandName);
return false;
}
log.debug("{} command executed, considering container {} successfully started", commandName, containerId);
return true;
}
}
代码示例来源:origin: org.testcontainers/testcontainers
@Override
protected void waitUntilReady() {
final String containerName = waitStrategyTarget.getContainerInfo().getName();
final Integer livenessCheckPort = livenessPort.map(waitStrategyTarget::getMappedPort).orElseGet(() -> {
final Set<Integer> livenessCheckPorts = getLivenessCheckPorts();
我在一次采访中遇到过这个问题。 线程中wait和wait on time有什么区别? 我知道 wait 方法 导致当前线程等待,直到另一个线程调用此对象的 notify() 方法或 notifyAll
我在这里得到了一个 java 代码片段,这让我想知道调用 wait() 和 this.wait() 之间的区别是什么。 假设您有一个类,该类具有获取资源的方法并且是同步的。通常,如果资源不可用,我会在
我知道如何使用 wait_event 在 Linux 内核队列中等待以及如何唤醒它们。 现在我需要弄清楚如何同时在多个队列中等待。我需要多路复用多个事件源,基本上以类似于 poll 或 select
c系统编程中wait(null)和wait(&status)有什么区别? 指针状态的内容是什么? 最佳答案 如果您调用 wait(NULL) ( wait(2) ),您只会等待任何子进程终止。使用 w
设想: 用户单击 View 上的按钮 这会调用 ViewModel 上的命令 DoProcessing 考虑到 View 和 ViewModel 的职责,Wait 光标是如何以及在哪里设置的? 为了清
我在使用 Selenium 的代码中看到了 FluentWait 和 WebDriverWait。 FluentWait 使用轮询技术,即它将在每个固定时间间隔轮询特定的 WebElement。我想知
我编写了以下代码,其中 start 方法应该等待,直到 stop 方法通知它。但是在执行过程中,尽管我已指定它等待,但启动方法下面的日志行会被打印。下图是我的start方法实现如下。 private
我有以下连接到 SignalR Hub 的代码 private static async Task StartListening() { try {
我对线程中的 wait() 方法如何工作感到很困惑。假设我写: public class test3 { public static void main(String args[]){
在使用 Java 线程原语构造线程安全有界队列时 - 这两种构造之间有什么区别 创建显式锁定对象。 使用列表作为锁并等待它。 示例 1 private final Object lock = new
故事: 在 Java selenium 语言绑定(bind)中有一个 FluentWait class ,这允许严格控制如何检查预期条件: Each FluentWait instance defin
wait-die 和 wound-wait 算法有什么区别? 这两种死锁预防技术似乎都在做同样的事情:回滚旧进程。 两者有什么区别? 请提供一个合适的例子来对比这两种算法。 最佳答案 Wait-Die
在 Java 线程转储中,您可以看到堆栈跟踪中提到的锁。 似乎有三种信息: 1: - locked (a java.io.BufferedInputStream) 2: - waiting to l
以下代码运行大约需要 20 秒。然而,取消注释 do! 后只用了不到一秒的时间。为什么会有这么大的差异? 更新:使用ag.Add时需要9秒。我已经更新了代码。 open FSharpx.Control
我在 ASP.NET WebForms 网站上有一个服务器端点击事件。在这种情况下,我调用一个方法,该方法又调用其异步合作伙伴方法,在调用中添加 .Wait()。 此方法然后向下几个级别(即,调用另一
有 3 种状态的线程处于 Activity 状态但既不运行也不可运行:- sleep 已阻止 正在等待 当线程执行 sleep() 方法时,它会在其参数指定的时间段(比如几毫秒)内从运行状态进入休眠状
考虑以下代码 public class ThreadTest1 { private static final long startTime = System.currentTimeMillis();
我有一个使用线程的 Java 应用程序,它使用多个 Lock 对象实例来同步对公共(public)资源的访问。 现在,作为性能测量的一部分,我想测量每个线程在每个锁中花费的时间。到目前为止,我已经尝试
我写了下面这段代码: let first_row = rows_stream.take(1).wait(); 并收到以下错误(当我真正想要访问该元素时): found struct `futures:
我使用了两个命令来等待设备启动:adb 等待设备和 adb 等待设备。两者似乎都在等待设备启动,我发现它们的行为没有任何区别。他们的行为有什么不同吗? 添加更多关于我所做的信息: 所以这就是我所做的,
我是一名优秀的程序员,十分优秀!