|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.kubernetes.fabric8.client.discovery.it; |
18 | 18 |
|
19 | | -import java.time.Duration; |
20 | | -import java.util.Objects; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Map; |
21 | 21 |
|
| 22 | +import org.springframework.cloud.client.ServiceInstance; |
22 | 23 | import org.springframework.cloud.client.discovery.DiscoveryClient; |
23 | | -import reactor.netty.http.client.HttpClient; |
24 | | -import reactor.util.retry.Retry; |
25 | | -import reactor.util.retry.RetryBackoffSpec; |
| 24 | +import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; |
26 | 25 |
|
27 | | -import org.springframework.http.client.reactive.ReactorClientHttpConnector; |
28 | | -import org.springframework.web.reactive.function.client.WebClient; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
29 | 27 |
|
30 | 28 | /** |
31 | 29 | * @author wind57 |
32 | 30 | */ |
33 | | -class TestAssertions { |
| 31 | +final class TestAssertions { |
34 | 32 |
|
35 | | - static void assertPodMetadata(DiscoveryClient discoveryClient) { |
| 33 | + private TestAssertions() { |
36 | 34 |
|
37 | 35 | } |
38 | 36 |
|
39 | | - static WebClient.Builder builder() { |
40 | | - return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create())); |
41 | | - } |
| 37 | + static void assertPodMetadata(DiscoveryClient discoveryClient) { |
| 38 | + |
| 39 | + List<ServiceInstance> serviceInstances = discoveryClient.getInstances("busybox-service"); |
| 40 | + |
| 41 | + DefaultKubernetesServiceInstance withCustomLabel = serviceInstances.stream() |
| 42 | + .map(instance -> (DefaultKubernetesServiceInstance) instance) |
| 43 | + .filter(x -> x.podMetadata().getOrDefault("annotations", Map.of()).isEmpty()) |
| 44 | + .toList() |
| 45 | + .get(0); |
| 46 | + |
| 47 | + Assertions.assertEquals(withCustomLabel.getServiceId(), "busybox-service"); |
| 48 | + Assertions.assertNotNull(withCustomLabel.getInstanceId()); |
| 49 | + Assertions.assertNotNull(withCustomLabel.getHost()); |
| 50 | + Assertions.assertEquals(withCustomLabel.getMetadata(), |
| 51 | + Map.of("k8s_namespace", "default", "type", "ClusterIP", "port.busybox-port", "80")); |
| 52 | + Assertions.assertTrue(withCustomLabel.podMetadata() |
| 53 | + .get("labels") |
| 54 | + .entrySet() |
| 55 | + .stream() |
| 56 | + .anyMatch(x -> x.getKey().equals("custom-label") && x.getValue().equals("custom-label-value"))); |
42 | 57 |
|
43 | | - static RetryBackoffSpec retrySpec() { |
44 | | - return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull); |
| 58 | + DefaultKubernetesServiceInstance withCustomAnnotation = serviceInstances.stream() |
| 59 | + .map(instance -> (DefaultKubernetesServiceInstance) instance) |
| 60 | + .filter(x -> !x.podMetadata().getOrDefault("annotations", Map.of()).isEmpty()) |
| 61 | + .toList() |
| 62 | + .get(0); |
| 63 | + Assertions.assertEquals(withCustomAnnotation.getServiceId(), "busybox-service"); |
| 64 | + Assertions.assertNotNull(withCustomAnnotation.getInstanceId()); |
| 65 | + Assertions.assertNotNull(withCustomAnnotation.getHost()); |
| 66 | + Assertions.assertEquals(withCustomAnnotation.getMetadata(), |
| 67 | + Map.of("k8s_namespace", "default", "type", "ClusterIP", "port.busybox-port", "80")); |
| 68 | + Assertions.assertTrue(withCustomAnnotation.podMetadata() |
| 69 | + .get("annotations") |
| 70 | + .entrySet() |
| 71 | + .stream() |
| 72 | + .anyMatch(x -> x.getKey().equals("custom-annotation") && x.getValue().equals("custom-annotation-value"))); |
45 | 73 | } |
46 | 74 |
|
47 | 75 | } |
0 commit comments