Handling 503 in kafka test
package org.springframework.cloud.kubernetes.configuration.watcher;
+import java.io.IOException;
import java.time.Duration;
import io.kubernetes.client.openapi.ApiClient;
@@ -37,6 +38,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.kubernetes.integration.tests.commons.K8SUtils;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -130,6 +133,26 @@ public class ActuatorRefreshKafkaIT {
.build();
api.createNamespacedConfigMap(NAMESPACE, configMap, null, null, null);
RestTemplate rest = new RestTemplateBuilder().build();
+ rest.setErrorHandler(new ResponseErrorHandler() {
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ log.warn("Received response status code: " + clientHttpResponse.getRawStatusCode());
+ if (clientHttpResponse.getRawStatusCode() == 503) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+ });
+
+ // Sometimes the NGINX ingress takes a bit to catch up and realize the service is
+ // available and we get a 503, we just need to wait a bit
+ await().timeout(Duration.ofSeconds(60))
+ .until(() -> rest.getForEntity("http://localhost:80/it", String.class).getStatusCode().is2xxSuccessful());
// Wait a bit before we verify
await().pollInterval(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(90)).until(() -> {
Boolean value = rest.getForObject("http://localhost:80/it", Boolean.class);
