Add test for 1286 (#1305)

This commit is contained in:
erabii
2023-04-18 02:33:45 +03:00
committed by GitHub
parent 49a0106eb4
commit 2a27ffcc78
3 changed files with 41 additions and 27 deletions

View File

@@ -38,6 +38,7 @@ import reactor.netty.http.client.HttpClient;
import reactor.util.retry.Retry;
import reactor.util.retry.RetryBackoffSpec;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
@@ -133,6 +134,17 @@ class KubernetesClientDiscoveryClientIT {
Assertions.assertEquals(busyBoxServiceInstances.size(), 2);
// enforces this :
// https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1286
WebClient clientForNonExistentService = builder().baseUrl("http://localhost/service-instances/non-existent")
.build();
List<ServiceInstance> resultForNonExistentService = clientForNonExistentService.method(HttpMethod.GET)
.retrieve().bodyToMono(new ParameterizedTypeReference<List<ServiceInstance>>() {
}).retryWhen(retrySpec()).block();
Assertions.assertEquals(resultForNonExistentService.size(), 0);
// clean-up
util.busybox(NAMESPACE, Phase.DELETE);
manifests(false, null, Phase.DELETE);
@@ -169,6 +181,17 @@ class KubernetesClientDiscoveryClientIT {
Assertions.assertTrue(servicesResult.contains("busybox-service"));
Assertions.assertTrue(servicesResult.contains("service-wiremock"));
// enforces this :
// https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1286
WebClient clientForNonExistentService = builder().baseUrl("http://localhost/service-instances/non-existent")
.build();
List<ServiceInstance> resultForNonExistentService = clientForNonExistentService.method(HttpMethod.GET)
.retrieve().bodyToMono(new ParameterizedTypeReference<List<ServiceInstance>>() {
}).retryWhen(retrySpec()).block();
Assertions.assertEquals(resultForNonExistentService.size(), 0);
manifests(true, null, Phase.DELETE);
util.wiremock(NAMESPACE_A, "/wiremock", Phase.DELETE);
util.busybox(NAMESPACE_B, Phase.DELETE);
@@ -220,6 +243,17 @@ class KubernetesClientDiscoveryClientIT {
DefaultKubernetesServiceInstance serviceInstance = wiremockInNamespaceA.get(0);
Assertions.assertEquals(serviceInstance.getNamespace(), "a");
// enforces this :
// https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1286
WebClient clientForNonExistentService = builder().baseUrl("http://localhost/service-instances/non-existent")
.build();
List<ServiceInstance> resultForNonExistentService = clientForNonExistentService.method(HttpMethod.GET)
.retrieve().bodyToMono(new ParameterizedTypeReference<List<ServiceInstance>>() {
}).retryWhen(retrySpec()).block();
Assertions.assertEquals(resultForNonExistentService.size(), 0);
manifests(false, NAMESPACE_A, Phase.DELETE);
util.wiremock(NAMESPACE_A, "/wiremock", Phase.DELETE);
util.wiremock(NAMESPACE_B, "/wiremock", Phase.DELETE);

View File

@@ -53,45 +53,25 @@
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-extended</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-httpclient5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>k3s</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -455,7 +455,7 @@ public final class Util {
private void waitForDeployment(String namespace, V1Deployment deployment) {
String deploymentName = deploymentName(deployment);
await().pollInterval(Duration.ofSeconds(1)).atMost(900, TimeUnit.SECONDS)
await().pollDelay(Duration.ofSeconds(5)).pollInterval(Duration.ofSeconds(5)).atMost(900, TimeUnit.SECONDS)
.until(() -> isDeploymentReady(deploymentName, namespace));
}