Applied checkstyle and turned it on by default
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -59,19 +59,21 @@ public class LoadBalancerTest {
|
||||
@Test
|
||||
public void roundRobbinLoadbalancerWorks() {
|
||||
ReactiveLoadBalancer<ServiceInstance> reactiveLoadBalancer = this.clientFactory
|
||||
.getInstance("myservice", ReactiveLoadBalancer.class, ServiceInstance.class);
|
||||
.getInstance("myservice", ReactiveLoadBalancer.class,
|
||||
ServiceInstance.class);
|
||||
|
||||
assertThat(reactiveLoadBalancer).isInstanceOf(RoundRobinLoadBalancer.class);
|
||||
assertThat(reactiveLoadBalancer).isInstanceOf(ReactorLoadBalancer.class);
|
||||
ReactorLoadBalancer<ServiceInstance> loadBalancer = (ReactorLoadBalancer<ServiceInstance>) reactiveLoadBalancer;
|
||||
|
||||
//order dependent on seedPosition -1 of RoundRobinLoadBalancer
|
||||
// order dependent on seedPosition -1 of RoundRobinLoadBalancer
|
||||
List<String> hosts = Arrays.asList("a.host", "c.host", "b.host-secure", "a.host");
|
||||
|
||||
assertLoadBalancer(loadBalancer, hosts);
|
||||
}
|
||||
|
||||
private void assertLoadBalancer(ReactorLoadBalancer<ServiceInstance> loadBalancer, List<String> hosts) {
|
||||
private void assertLoadBalancer(ReactorLoadBalancer<ServiceInstance> loadBalancer,
|
||||
List<String> hosts) {
|
||||
for (String host : hosts) {
|
||||
Mono<Response<ServiceInstance>> source = loadBalancer.choose();
|
||||
StepVerifier.create(source).consumeNextWith(response -> {
|
||||
@@ -80,13 +82,13 @@ public class LoadBalancerTest {
|
||||
|
||||
ServiceInstance instance = response.getServer();
|
||||
assertThat(instance).isNotNull();
|
||||
assertThat(instance.getHost())
|
||||
.as("instance host is incorrent %s", host)
|
||||
assertThat(instance.getHost()).as("instance host is incorrent %s", host)
|
||||
.isEqualTo(host);
|
||||
|
||||
if (host.contains("secure")) {
|
||||
assertThat(instance.isSecure()).isTrue();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
assertThat(instance.isSecure()).isFalse();
|
||||
}
|
||||
|
||||
@@ -97,8 +99,10 @@ public class LoadBalancerTest {
|
||||
|
||||
@Test
|
||||
public void emptyHosts() {
|
||||
ResolvableType type = ResolvableType.forClassWithGenerics(ReactorLoadBalancer.class, ServiceInstance.class);
|
||||
ReactorLoadBalancer<ServiceInstance> loadBalancer = this.clientFactory.getInstance("unknownservice", type);
|
||||
ResolvableType type = ResolvableType
|
||||
.forClassWithGenerics(ReactorLoadBalancer.class, ServiceInstance.class);
|
||||
ReactorLoadBalancer<ServiceInstance> loadBalancer = this.clientFactory
|
||||
.getInstance("unknownservice", type);
|
||||
|
||||
assertThat(loadBalancer).isInstanceOf(RoundRobinLoadBalancer.class);
|
||||
|
||||
@@ -113,13 +117,15 @@ public class LoadBalancerTest {
|
||||
public void staticConfigurationWorks() {
|
||||
String serviceId = "test1";
|
||||
RoundRobinLoadBalancer loadBalancer = new RoundRobinLoadBalancer(serviceId,
|
||||
ServiceInstanceSuppliers.toProvider(serviceId, instance(serviceId, "1.host", false),
|
||||
ServiceInstanceSuppliers.toProvider(serviceId,
|
||||
instance(serviceId, "1.host", false),
|
||||
instance(serviceId, "2.host-secure", true)),
|
||||
-1);
|
||||
assertLoadBalancer(loadBalancer, Arrays.asList("1.host", "2.host-secure"));
|
||||
}
|
||||
|
||||
private DefaultServiceInstance instance(String serviceId, String host, boolean secure) {
|
||||
private DefaultServiceInstance instance(String serviceId, String host,
|
||||
boolean secure) {
|
||||
return new DefaultServiceInstance(serviceId, host, 80, secure);
|
||||
}
|
||||
|
||||
@@ -127,18 +133,22 @@ public class LoadBalancerTest {
|
||||
@SpringBootConfiguration
|
||||
@LoadBalancerClients({
|
||||
@LoadBalancerClient(name = "myservice", configuration = MyServiceConfig.class),
|
||||
@LoadBalancerClient(name = "unknownservice", configuration = MyServiceConfig.class),
|
||||
})
|
||||
@LoadBalancerClient(name = "unknownservice", configuration = MyServiceConfig.class), })
|
||||
@EnableCaching
|
||||
protected static class Config { }
|
||||
protected static class Config {
|
||||
|
||||
}
|
||||
|
||||
protected static class MyServiceConfig {
|
||||
|
||||
@Bean
|
||||
public RoundRobinLoadBalancer roundRobinContextLoadBalancer(LoadBalancerClientFactory clientFactory, Environment env) {
|
||||
public RoundRobinLoadBalancer roundRobinContextLoadBalancer(
|
||||
LoadBalancerClientFactory clientFactory, Environment env) {
|
||||
String serviceId = clientFactory.getName(env);
|
||||
return new RoundRobinLoadBalancer(serviceId,
|
||||
clientFactory.getLazyProvider(serviceId, ServiceInstanceSupplier.class),
|
||||
-1);
|
||||
return new RoundRobinLoadBalancer(serviceId, clientFactory
|
||||
.getLazyProvider(serviceId, ServiceInstanceSupplier.class), -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,32 +5,23 @@ spring:
|
||||
simple:
|
||||
instances:
|
||||
myservice:
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://a.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://c.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: https://b.host-secure
|
||||
- service-id: myservice
|
||||
uri: http://a.host
|
||||
- service-id: myservice
|
||||
uri: http://c.host
|
||||
- service-id: myservice
|
||||
uri: https://b.host-secure
|
||||
anotherservice:
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://d.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://f.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: https://e.host
|
||||
- service-id: myservice
|
||||
uri: http://d.host
|
||||
- service-id: myservice
|
||||
uri: http://f.host
|
||||
- service-id: myservice
|
||||
uri: https://e.host
|
||||
thirdservice:
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://g.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: http://h.host
|
||||
-
|
||||
service-id: myservice
|
||||
uri: https://i.host
|
||||
- service-id: myservice
|
||||
uri: http://g.host
|
||||
- service-id: myservice
|
||||
uri: http://h.host
|
||||
- service-id: myservice
|
||||
uri: https://i.host
|
||||
|
||||
Reference in New Issue
Block a user