Skip to content

Commit ec38be1

Browse files
authored
refactor k8s discovery module in integration tests (1) (#1865)
* started work Signed-off-by: wind57 <[email protected]> * refactor Signed-off-by: wind57 <[email protected]> --------- Signed-off-by: wind57 <[email protected]>
1 parent 9518285 commit ec38be1

22 files changed

+745
-2383
lines changed

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/TestAssertions.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -150,49 +150,6 @@ static void assertBlockingConfiguration(CapturedOutput output, int port) {
150150

151151
}
152152

153-
/**
154-
* Both blocking and reactive are enabled.
155-
*/
156-
static void testDefaultConfiguration(CapturedOutput output, int port) {
157-
158-
waitForLogStatement(output, "Will publish InstanceRegisteredEvent from blocking implementation");
159-
waitForLogStatement(output, "Will publish InstanceRegisteredEvent from reactive implementation");
160-
waitForLogStatement(output, "publishing InstanceRegisteredEvent");
161-
waitForLogStatement(output, "Discovery Client has been initialized");
162-
163-
WebClient healthClient = builder().baseUrl("http://localhost:" + port + "/actuator/health").build();
164-
165-
String healthResult = healthClient.method(HttpMethod.GET)
166-
.retrieve()
167-
.bodyToMono(String.class)
168-
.retryWhen(retrySpec())
169-
.block();
170-
171-
assertThat(BASIC_JSON_TESTER.from(healthResult))
172-
.extractingJsonPathStringValue("$.components.discoveryComposite.status")
173-
.isEqualTo("UP");
174-
175-
assertThat(BASIC_JSON_TESTER.from(healthResult))
176-
.extractingJsonPathStringValue("$.components.discoveryComposite.components.discoveryClient.status")
177-
.isEqualTo("UP");
178-
179-
assertThat(BASIC_JSON_TESTER.from(healthResult))
180-
.extractingJsonPathArrayValue("$.components.discoveryComposite.components.discoveryClient.details.services")
181-
.containsExactlyInAnyOrder("kubernetes", "busybox-service");
182-
183-
assertThat(BASIC_JSON_TESTER.from(healthResult))
184-
.extractingJsonPathStringValue("$.components.reactiveDiscoveryClients.status")
185-
.isEqualTo("UP");
186-
187-
assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
188-
"$.components.reactiveDiscoveryClients.components.['Fabric8 Kubernetes Reactive Discovery Client'].status")
189-
.isEqualTo("UP");
190-
191-
assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathArrayValue(
192-
"$.components.reactiveDiscoveryClients.components.['Fabric8 Kubernetes Reactive Discovery Client'].details.services")
193-
.containsExactlyInAnyOrder("kubernetes", "busybox-service");
194-
}
195-
196153
/**
197154
* Reactive is enabled, blocking is disabled. As such,
198155
* KubernetesInformerDiscoveryClientAutoConfiguration::indicatorInitializer will post

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/pom.xml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
<artifactId>spring-cloud-kubernetes-k8s-client-discovery</artifactId>
1313

14+
<properties>
15+
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
16+
<spring-boot.build-image.skip>true</spring-boot.build-image.skip>
17+
</properties>
18+
1419
<dependencies>
1520
<dependency>
1621
<groupId>org.springframework.cloud</groupId>
@@ -41,17 +46,5 @@
4146
</dependency>
4247

4348
</dependencies>
44-
<build>
45-
<resources>
46-
<resource>
47-
<directory>../src/main/resources</directory>
48-
<filtering>true</filtering>
49-
</resource>
50-
<resource>
51-
<directory>src/main/resources</directory>
52-
<filtering>true</filtering>
53-
</resource>
54-
</resources>
55-
</build>
5649

5750
</project>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2023 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
* @author wind57
2424
*/
2525
@SpringBootApplication
26-
public class DiscoveryApp {
26+
class DiscoveryApp {
2727

2828
public static void main(String[] args) {
2929
SpringApplication.run(DiscoveryApp.class, args);

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryApplicationListener.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryController.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/ReactiveDiscoveryController.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.k8s.client.discovery;
18+
19+
import java.util.Set;
20+
21+
import io.kubernetes.client.openapi.ApiClient;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.boot.test.context.TestConfiguration;
29+
import org.springframework.boot.test.system.CapturedOutput;
30+
import org.springframework.boot.test.web.server.LocalManagementPort;
31+
import org.springframework.cloud.client.discovery.DiscoveryClient;
32+
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
33+
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
34+
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Primary;
37+
import org.springframework.test.context.TestPropertySource;
38+
39+
import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertBlockingConfiguration;
40+
import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertPodMetadata;
41+
42+
/**
43+
* @author wind57
44+
*/
45+
@SpringBootTest(classes = { DiscoveryApp.class, KubernetesClientBlockingIT.TestConfig.class },
46+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47+
@TestPropertySource(
48+
properties = { "spring.cloud.discovery.reactive.enabled=false", "spring.cloud.discovery.blocking.enabled=true",
49+
"logging.level.org.springframework.cloud.kubernetes.commons.discovery=debug",
50+
"logging.level.org.springframework.cloud.client.discovery.health=debug",
51+
"logging.level.org.springframework.cloud.kubernetes.client.discovery=debug" })
52+
class KubernetesClientBlockingIT extends KubernetesClientDiscoveryBase {
53+
54+
@LocalManagementPort
55+
private int port;
56+
57+
@Autowired
58+
private DiscoveryClient discoveryClient;
59+
60+
@BeforeEach
61+
void beforeEach() {
62+
Images.loadWiremock(K3S);
63+
util.wiremock(NAMESPACE, "/", Phase.CREATE);
64+
}
65+
66+
@AfterEach
67+
void afterEach() {
68+
util.wiremock(NAMESPACE, "/", Phase.DELETE);
69+
}
70+
71+
/**
72+
* <pre>
73+
*
74+
* Reactive is disabled, only blocking is active. As such,
75+
* We assert for logs and call '/health' endpoint to see that blocking discovery
76+
* client was initialized.
77+
*
78+
* </pre>
79+
*/
80+
@Test
81+
void test(CapturedOutput output) {
82+
assertBlockingConfiguration(output, port);
83+
assertPodMetadata(discoveryClient);
84+
}
85+
86+
@TestConfiguration
87+
static class TestConfig {
88+
89+
@Bean
90+
@Primary
91+
ApiClient client() {
92+
return apiClient();
93+
}
94+
95+
@Bean
96+
@Primary
97+
KubernetesDiscoveryProperties kubernetesDiscoveryProperties() {
98+
return discoveryProperties(false, Set.of(NAMESPACE), null);
99+
}
100+
101+
}
102+
103+
}

0 commit comments

Comments
 (0)