org.testcontainers.containers.wait.strategy.Wait类的使用及代码示例

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

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

Wait介绍

[英]Convenience class with logic for building common WaitStrategy instances.
[中]带有逻辑的便利类,用于构建公共WaitStrategy实例。

代码示例

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

/**
 * Convenience method to return a WaitStrategy for an HTTPS endpoint.
 *
 * @param path the path to check
 * @return the WaitStrategy
 * @see HttpWaitStrategy
 */
public static HttpWaitStrategy forHttps(String path) {
  return forHttp(path)
      .usingTls();
}

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

public InfluxDBContainer(final String version) {
  super(IMAGE_NAME + ":" + version);
  waitStrategy = new WaitAllStrategy()
    .withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204))
    .withStrategy(Wait.forListeningPort());
}

代码示例来源: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

/**
 * Convenience method to return the default WaitStrategy.
 *
 * @return a WaitStrategy
 */
public static WaitStrategy defaultWaitStrategy() {
  return forListeningPort();
}

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

public SELF withExposedService(String serviceName, int servicePort) {
  return withExposedService(serviceName, servicePort, Wait.defaultWaitStrategy());
}

代码示例来源: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: testcontainers/testcontainers-java

@Test
public void testWaitOnListeningPort() {
  final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
    .withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort());
  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: org.testcontainers/testcontainers

return withExposedService(serviceName, servicePort, Wait.defaultWaitStrategy());

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

public PulsarContainer(String pulsarVersion) {
  super(TestcontainersConfiguration.getInstance().getPulsarImage() + ":" + pulsarVersion);
  withExposedPorts(BROKER_PORT, BROKER_HTTP_PORT);
  withCommand("/pulsar/bin/pulsar", "standalone", "--no-functions-worker", "-nss");
  waitingFor(Wait.forHttp(METRICS_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT));
}

代码示例来源:origin: org.testcontainers/influxdb

public InfluxDBContainer(final String version) {
  super(IMAGE_NAME + ":" + version);
  waitStrategy = new WaitAllStrategy()
    .withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204))
    .withStrategy(Wait.forListeningPort());
}

代码示例来源:origin: org.testcontainers/testcontainers

/**
 * Convenience method to return the default WaitStrategy.
 *
 * @return a WaitStrategy
 */
public static WaitStrategy defaultWaitStrategy() {
  return forListeningPort();
}

代码示例来源: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;
}

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

@Test
public void testWaitingFails() {
  final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
    .withExposedService("redis_1", REDIS_PORT, Wait.forHttp("/test").withStartupTimeout(Duration.ofSeconds(10)));
  VisibleAssertions.assertThrows("waiting on an invalid http path times out",
    RuntimeException.class,
    () -> environment.starting(Description.createTestDescription(Object.class, "name")));
}

代码示例来源:origin: org.testcontainers/testcontainers

/**
 * Convenience method to return a WaitStrategy for an HTTPS endpoint.
 *
 * @param path the path to check
 * @return the WaitStrategy
 * @see HttpWaitStrategy
 */
public static HttpWaitStrategy forHttps(String path) {
  return forHttp(path)
      .usingTls();
}

代码示例来源:origin: hakdogan/ElasticSearch

@Profile("test")
@Bean(destroyMethod = "stop")
public FixedHostPortGenericContainer getFixedHostPortGenericContainer(){
  String url = String.join(":", props.getElastic().getImageUrl(), props.getElastic().getVersion());
  FixedHostPortGenericContainer fixed = new FixedHostPortGenericContainer(url);
  fixed.withFixedExposedPort(props.getClients().getHttpPort(), props.getClients().getContainerPort());
  fixed.waitingFor(Wait.forHttp("/"));
  fixed.start();
  return fixed;
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-tika

public TikaContainer() {
  tika = new SwarmGenericContainer(Images.TIKA)
      .withExposedPorts(DEFAULT_TIKA_PORT)
      .waitingFor(Wait.forHttp("/tika").withRateLimiter(RateLimiters.TWENTIES_PER_SECOND))
      .withStartupTimeout(Duration.ofSeconds(30));
}

代码示例来源:origin: bozaro/git-as-svn

@BeforeClass
void before() throws Exception {
 SvnTestHelper.skipTestIfDockerUnavailable();
 String gitlabVersion = System.getenv("GITLAB_VERSION");
 if (gitlabVersion == null) {
  if (System.getenv("TRAVIS") != null)
   throw new SkipException("Only run gitlab tests on Travis when explicitly asked");
  gitlabVersion = "latest";
 }
 final int gitlabPort = 80;
 gitlab = new GenericContainer<>("gitlab/gitlab-ce:" + gitlabVersion)
   .withEnv("GITLAB_ROOT_PASSWORD", rootPassword)
   .withExposedPorts(gitlabPort)
   .waitingFor(Wait.forHttp("/users/sign_in")
     .withStartupTimeout(Duration.of(10, ChronoUnit.MINUTES)));
 gitlab.start();
 gitlabUrl = "http://" + gitlab.getContainerIpAddress() + ":" + gitlab.getMappedPort(gitlabPort);
 rootToken = createToken(root, rootPassword, true);
 final GitlabAPI rootAPI = GitLabContext.connect(gitlabUrl, rootToken);
 final GitlabUser gitlabUser = rootAPI.createUser(new CreateUserRequest(user, user, "git-as-svn@localhost").setPassword(userPassword));
 Assert.assertNotNull(gitlabUser);
 final GitlabGroup group = rootAPI.createGroup(new CreateGroupRequest("testGroup").setVisibility(GitlabVisibility.PUBLIC), null);
 Assert.assertNotNull(group);
 Assert.assertNotNull(rootAPI.addGroupMember(group.getId(), gitlabUser.getId(), GitlabAccessLevel.Developer));
 gitlabProject = createGitlabProject(rootAPI, group, "test", GitlabVisibility.INTERNAL, Collections.singleton("git-as-svn"));
 gitlabPublicProject = createGitlabProject(rootAPI, group, "publik", GitlabVisibility.PUBLIC, Collections.emptySet());
}

代码示例来源:origin: org.apache.james/apache-james-backends-rabbitmq

private WaitStrategy waitStrategy() {
  return new WaitAllStrategy()
    .withStrategy(Wait.forHttp("").forPort(DEFAULT_RABBITMQ_ADMIN_PORT)
      .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND)
      .withStartupTimeout(TEN_MINUTES_TIMEOUT))
    .withStrategy(new RabbitMQWaitStrategy(this, TEN_MINUTES_TIMEOUT))
    .withStartupTimeout(TEN_MINUTES_TIMEOUT);
}

代码示例来源:origin: org.apache.james/blob-objectstorage

public DockerSwiftContainer() {
  this.swiftContainer = new GenericContainer<>(SWIFT_DOCKER_IMAGE);
  this.swiftContainer
    .withExposedPorts(KEYSTONE_ADMIN_PORT)
    .withExposedPorts(SWIFT_PORT)
    .withLogConsumer(DockerSwiftContainer::displayDockerLog)
    .waitingFor(
      new WaitAllStrategy()
        .withStrategy(
          forHttp("/v3")
            .forPort(KEYSTONE_ADMIN_PORT)
            .forStatusCode(200)
            .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND)
        ).withStrategy(
        forHttp("/info")
          .forPort(SWIFT_PORT)
          .forStatusCode(200)
          .withRateLimiter(RateLimiters.TWENTIES_PER_SECOND)
      )
    );
}

相关文章

微信公众号

最新文章

更多