org.testcontainers.containers.wait.strategy.Wait.forLogMessage()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.testcontainers.containers.wait.strategy.Wait.forLogMessage()方法的一些代码示例,展示了Wait.forLogMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wait.forLogMessage()方法的具体详情如下:
包路径:org.testcontainers.containers.wait.strategy.Wait
类名称:Wait
方法名:forLogMessage

Wait.forLogMessage介绍

[英]Convenience method to return a WaitStrategy for log messages.
[中]为日志消息返回WaitStrategy的便捷方法。

代码示例

代码示例来源:origin: testcontainers/testcontainers-java

public LocalStackContainer(String version) {
  super("localstack/localstack:" + version);
  withFileSystemBind("//var/run/docker.sock", "/var/run/docker.sock");
  waitingFor(Wait.forLogMessage(".*Ready\\.\n", 1));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testWaitOnOneOfMultipleStrategiesFailing() {
  final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
    .withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(10)))
    .waitingFor("db_1", Wait.forLogMessage(".*test test test.*\\s", 1).withStartupTimeout(Duration.ofSeconds(10)))
    .withTailChildContainers(true);
  VisibleAssertions.assertThrows("waiting on one failing strategy to time out",
    RuntimeException.class,
    () -> environment.starting(Description.createTestDescription(Object.class, "name")));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testWaitOnMultipleStrategiesPassing() {
  final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
    .withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort())
    .withExposedService("db_1", 3306, Wait.forLogMessage(".*ready for connections.*\\s", 1))
    .withTailChildContainers(true);
  try {
    environment.starting(Description.createTestDescription(Object.class, "name"));
    VisibleAssertions.pass("Docker compose should start after waiting for listening port");
  } catch (RuntimeException e) {
    VisibleAssertions.fail("Docker compose should start after waiting for listening port with failed with: " + e);
  }
}

代码示例来源:origin: mysql-time-machine/replicator

private GenericContainer<?> getContainer(String image, int port, Network network, String logWaitRegex, int logWaitTimes, boolean matchExposedPort) {
  GenericContainer<?> container = new GenericContainer<>(image)
      .withExposedPorts(port)
      .waitingFor(
          Wait.forLogMessage(logWaitRegex, logWaitTimes).withStartupTimeout(Duration.ofMinutes(5L))
      );
  if (network != null) {
    container.withNetwork(network);
  }
  if(matchExposedPort) {
    container.withCreateContainerCmdModifier(
        command -> command.withPortBindings(PortBinding.parse(String.format("%d:%d", port, port)))
    );
  }
  return container;
}

相关文章

微信公众号

最新文章

更多