/** * Waits for the given status code. * * @param statusCode the expected status code * @return this */ public HttpWaitStrategy forStatusCode(int statusCode) { delegateStrategy.forStatusCode(statusCode); return this; }
/** * Expects that the WaitStrategy returns successfully after receiving an HTTP 401 response from the container. * This 401 response is checked with with many status codes using {@link HttpWaitStrategy#forStatusCode(int)} * and a lambda using {@link HttpWaitStrategy#forStatusCodeMatching(Predicate)} */ @Test public void testWaitUntilReadyWithManyStatusCodesAndLambda() { waitUntilReadyAndSucceed(startContainerWithCommand(createShellCommand("401 UNAUTHORIZED", GOOD_RESPONSE_BODY), createHttpWaitStrategy(ready) .forStatusCode(300) .forStatusCode(500) .forStatusCodeMatching(it -> it == 401) )); }
@NotNull private HttpWaitStrategy createNodeWaitStrategy() { return new HttpWaitStrategy() .forPath("/pools/default/") .withBasicCredentials(clusterUsername, clusterPassword) .forStatusCode(HTTP_OK) .forResponsePredicate(response -> { try { return Optional.of(MAPPER.readTree(response)) .map(n -> n.at("/nodes/0/status")) .map(JsonNode::asText) .map("healthy"::equals) .orElse(false); } catch (IOException e) { logger().error("Unable to parse response {}", response); return false; } }); }
/** * Expects that the WaitStrategy throws a {@link RetryCountExceededException} after not receiving any of the * error code defined with {@link HttpWaitStrategy#forStatusCode(int)} * and {@link HttpWaitStrategy#forStatusCodeMatching(Predicate)} */ @Test public void testWaitUntilReadyWithTimeoutAndWithManyStatusCodesAndLambda() { waitUntilReadyAndTimeout(startContainerWithCommand(createShellCommand("401 UNAUTHORIZED", GOOD_RESPONSE_BODY), createHttpWaitStrategy(ready) .forStatusCode(300) .forStatusCodeMatching(it -> it == 500) )); }
/** * Expects that the WaitStrategy returns successfully after receiving an HTTP 401 response from the container. * This 401 response is checked with many status codes using {@link HttpWaitStrategy#forStatusCode(int)} */ @Test public void testWaitUntilReadyWithManyStatusCodes() { waitUntilReadyAndSucceed(startContainerWithCommand(createShellCommand("401 UNAUTHORIZED", GOOD_RESPONSE_BODY), createHttpWaitStrategy(ready) .forStatusCode(300) .forStatusCode(401) .forStatusCode(500) )); }
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 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)); }
/** * Waits for the given status code. * * @param statusCode the expected status code * @return this */ public HttpWaitStrategy forStatusCode(int statusCode) { delegateStrategy.forStatusCode(statusCode); return this; }
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 static GenericContainer<?> createTestContainer(final int testPort) { return new GenericContainer<>("localstack/localstack:latest") .withEnv("DEBUG", "1") .waitingFor(new HttpWaitStrategy().forStatusCode(200).forPort(testPort)); }
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) ) ); }