How to use buildLivenessUri method of org.testcontainers.containers.wait.strategy.HttpWaitStrategy class

Best Testcontainers-java code snippet using org.testcontainers.containers.wait.strategy.HttpWaitStrategy.buildLivenessUri

Source:HttpWaitStrategy.java Github

copy

Full Screen

...116 @Override117 protected void waitUntilReady() {118 final String containerName = waitStrategyTarget.getContainerInfo().getName();119 final int livenessCheckPort = waitStrategyTarget.getMappedPort(port);120 final String uri = buildLivenessUri(livenessCheckPort).toString();121 log.info("{}: Waiting for {} seconds for URL: {}", containerName, startupTimeout.getSeconds(), uri);122 // try to connect to the URL123 try {124 retryUntilSuccess((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> {125 getRateLimiter().doWhenReady(() -> {126 try {127 final HttpURLConnection connection = (HttpURLConnection) new URL(uri).openConnection();128 // authenticate129 if (!Strings.isNullOrEmpty(username)) {130 connection.setRequestProperty(HEADER_AUTHORIZATION, buildAuthString(username, password));131 connection.setUseCaches(false);132 }133 connection.setRequestMethod("GET");134 connection.connect();135 if (statusCode != connection.getResponseCode()) {136 throw new RuntimeException(String.format("HTTP response code was: %s",137 connection.getResponseCode()));138 }139 if (responsePredicate != null) {140 String responseBody = getResponseBody(connection);141 if (!responsePredicate.test(responseBody)) {142 throw new RuntimeException(String.format("Response: %s did not match predicate",143 responseBody));144 }145 }146 } catch (IOException e) {147 throw new RuntimeException(e);148 }149 });150 return true;151 });152 } catch (TimeoutException e) {153 throw new ContainerLaunchException(String.format(154 "Timed out waiting for URL to be accessible (%s should return HTTP %s)", uri, statusCode));155 }156 }157 /**158 * Build the URI on which to check if the container is ready.159 *160 * @param livenessCheckPort the liveness port161 * @return the liveness URI162 */163 private URI buildLivenessUri(int livenessCheckPort) {164 final String scheme = (tlsEnabled ? "https" : "http") + "://";165 final String host = waitStrategyTarget.getContainerIpAddress();166 final String portSuffix;167 if ((tlsEnabled && 443 == livenessCheckPort) || (!tlsEnabled && 80 == livenessCheckPort)) {168 portSuffix = "";169 } else {170 portSuffix = ":" + String.valueOf(livenessCheckPort);171 }172 return URI.create(scheme + host + portSuffix + path);173 }174 /**175 * @param username the username176 * @param password the password177 * @return a basic authentication string for the given credentials...

Full Screen

Full Screen

buildLivenessUri

Using AI Code Generation

copy

Full Screen

1String livenessUri = buildLivenessUri();2String readinessUri = buildReadinessUri();3String livenessUri = buildLivenessUri();4String readinessUri = buildReadinessUri();5String livenessUri = buildLivenessUri();6String readinessUri = buildReadinessUri();7String livenessUri = buildLivenessUri();8String readinessUri = buildReadinessUri();9String livenessUri = buildLivenessUri();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful