-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor loadbalancer it test (14) (#1443)
- Loading branch information
Showing
5 changed files
with
238 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
...src/test/resources/spring-cloud-kubernetes-client-loadbalancer-service-it-deployment.yaml
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...framework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2013-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.kubernetes.discoveryclient.it; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import reactor.netty.http.client.HttpClient; | ||
import reactor.util.retry.Retry; | ||
import reactor.util.retry.RetryBackoffSpec; | ||
|
||
import org.springframework.boot.test.json.BasicJsonTester; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
/** | ||
* @author mbialkowski1 | ||
*/ | ||
final class DiscoveryClientFilterNamespaceDelegate { | ||
|
||
private static final BasicJsonTester BASIC_JSON_TESTER = new BasicJsonTester( | ||
DiscoveryClientFilterNamespaceDelegate.class); | ||
|
||
static void testNamespaceDiscoveryClient() { | ||
testLoadBalancer(); | ||
testHealth(); | ||
} | ||
|
||
private static void testLoadBalancer() { | ||
|
||
WebClient.Builder builder = builder(); | ||
WebClient serviceClient = builder.baseUrl("http://localhost:80/discoveryclient-it/services").build(); | ||
String result = serviceClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()) | ||
.block(); | ||
|
||
Assertions.assertThat(BASIC_JSON_TESTER.from(result)).extractingJsonPathArrayValue("$") | ||
.contains("service-wiremock"); | ||
|
||
// ServiceInstance | ||
WebClient serviceInstanceClient = builder | ||
.baseUrl("http://localhost:80/discoveryclient-it/service/service-wiremock").build(); | ||
String serviceInstances = serviceInstanceClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class) | ||
.retryWhen(retrySpec()).block(); | ||
|
||
Assertions.assertThat(BASIC_JSON_TESTER.from(serviceInstances)).extractingJsonPathStringValue("$.[0].serviceId") | ||
.isEqualTo("service-wiremock"); | ||
|
||
Assertions.assertThat(BASIC_JSON_TESTER.from(serviceInstances)).extractingJsonPathStringValue("$.[0].namespace") | ||
.isEqualTo("left"); | ||
} | ||
|
||
private static void testHealth() { | ||
WebClient.Builder builder = builder(); | ||
WebClient serviceClient = builder.baseUrl("http://localhost:80/discoveryclient-it/actuator/health").build(); | ||
|
||
String health = serviceClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()) | ||
.block(); | ||
|
||
Assertions.assertThat(BASIC_JSON_TESTER.from(health)) | ||
.extractingJsonPathStringValue("$.components.discoveryComposite.status").isEqualTo("UP"); | ||
} | ||
|
||
private static WebClient.Builder builder() { | ||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create())); | ||
} | ||
|
||
private static RetryBackoffSpec retrySpec() { | ||
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull); | ||
} | ||
|
||
} |
Oops, something went wrong.