/** * 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(); }
public InfluxDBContainer(final String version) { super(IMAGE_NAME + ":" + version); waitStrategy = new WaitAllStrategy() .withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204)) .withStrategy(Wait.forListeningPort()); }
public LocalStackContainer(String version) { super("localstack/localstack:" + version); withFileSystemBind("//var/run/docker.sock", "/var/run/docker.sock"); waitingFor(Wait.forLogMessage(".*Ready\\.\n", 1)); }
@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"))); }
/** * Convenience method to return the default WaitStrategy. * * @return a WaitStrategy */ public static WaitStrategy defaultWaitStrategy() { return forListeningPort(); }
public SELF withExposedService(String serviceName, int servicePort) { return withExposedService(serviceName, servicePort, Wait.defaultWaitStrategy()); }
@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); } }
@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); } }
return withExposedService(serviceName, servicePort, Wait.defaultWaitStrategy());
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)); }
public InfluxDBContainer(final String version) { super(IMAGE_NAME + ":" + version); waitStrategy = new WaitAllStrategy() .withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204)) .withStrategy(Wait.forListeningPort()); }
/** * Convenience method to return the default WaitStrategy. * * @return a WaitStrategy */ public static WaitStrategy defaultWaitStrategy() { return forListeningPort(); }
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; }
@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"))); }
/** * 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(); }
@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; }
public TikaContainer() { tika = new SwarmGenericContainer(Images.TIKA) .withExposedPorts(DEFAULT_TIKA_PORT) .waitingFor(Wait.forHttp("/tika").withRateLimiter(RateLimiters.TWENTIES_PER_SECOND)) .withStartupTimeout(Duration.ofSeconds(30)); }
@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()); }
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); }
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) ) ); }