Remove deprecations.

This commit is contained in:
Olga Maciaszek-Sharma
2020-12-10 12:31:45 +01:00
parent 8739f8c233
commit 8969d5d1e1
13 changed files with 15 additions and 575 deletions

View File

@@ -16,18 +16,13 @@
package org.springframework.cloud.loadbalancer.core;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import reactor.core.publisher.Flux;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.core.env.Environment;
import static org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory.PROPERTY_NAME;
/**
* A {@link Supplier} of lists of {@link ServiceInstance} objects.
@@ -47,112 +42,4 @@ public interface ServiceInstanceListSupplier extends Supplier<Flux<List<ServiceI
return new ServiceInstanceListSupplierBuilder();
}
static FixedServiceInstanceListSupplier.Builder fixed(Environment environment) {
return new FixedServiceInstanceListSupplier.Builder(environment);
}
static FixedServiceInstanceListSupplier.SimpleBuilder fixed(String serviceId) {
return new FixedServiceInstanceListSupplier.SimpleBuilder(serviceId);
}
class FixedServiceInstanceListSupplier implements ServiceInstanceListSupplier {
private final String serviceId;
private List<ServiceInstance> instances;
@Deprecated
public static Builder with(Environment env) {
return new Builder(env);
}
private FixedServiceInstanceListSupplier(String serviceId, List<ServiceInstance> instances) {
this.serviceId = serviceId;
this.instances = instances;
}
@Override
public String getServiceId() {
return serviceId;
}
@Override
public Flux<List<ServiceInstance>> get() {
return Flux.just(instances);
}
@Deprecated
public static final class SimpleBuilder {
private final ArrayList<ServiceInstance> instances = new ArrayList<>();
private final String serviceId;
private SimpleBuilder(String serviceId) {
this.serviceId = serviceId;
}
public SimpleBuilder instance(ServiceInstance instance) {
instances.add(instance);
return this;
}
public SimpleBuilder instance(int port) {
return instance("localhost", port);
}
public SimpleBuilder instance(String host, int port) {
DefaultServiceInstance instance = new DefaultServiceInstance(instanceId(serviceId, host, port),
serviceId, host, port, false);
return instance(instance);
}
private String instanceId(String serviceId, String host, int port) {
return serviceId + ":" + host + ":" + port;
}
public FixedServiceInstanceListSupplier build() {
return new FixedServiceInstanceListSupplier(serviceId, instances);
}
}
@Deprecated
public static final class Builder {
private final Environment env;
private final ArrayList<ServiceInstance> instances = new ArrayList<>();
private Builder(Environment env) {
this.env = env;
}
public Builder instance(ServiceInstance instance) {
instances.add(instance);
return this;
}
public Builder instance(int port, String serviceId) {
return instance("localhost", port, serviceId);
}
public Builder instance(String host, int port, String serviceId) {
DefaultServiceInstance instance = new DefaultServiceInstance(instanceId(serviceId, host, port),
serviceId, host, port, false);
return instance(instance);
}
private String instanceId(String serviceId, String host, int port) {
return serviceId + ":" + host + ":" + port;
}
public FixedServiceInstanceListSupplier build() {
return new FixedServiceInstanceListSupplier(env.getProperty(PROPERTY_NAME), instances);
}
}
}
}

View File

@@ -41,6 +41,7 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerProperties;
import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.bind.annotation.GetMapping;
@@ -91,11 +92,12 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldCheckInstanceWithProvidedHealthCheckPath() {
String serviceId = "ignored-service";
healthCheck.getPath().put("ignored-service", "/health");
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();
@@ -105,10 +107,11 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldCheckInstanceWithDefaultHealthCheckPath() {
String serviceId = "ignored-service";
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();
@@ -118,11 +121,12 @@ class HealthCheckServiceInstanceListSupplierTests {
@SuppressWarnings("ConstantConditions")
@Test
void shouldReturnFalseIfEndpointNotFound() {
healthCheck.getPath().put("ignored-service", "/test");
String serviceId = "ignored-service";
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", serviceId, "127.0.0.1", port,
false);
healthCheck.getPath().put(serviceId, "/test");
listSupplier = new HealthCheckServiceInstanceListSupplier(
ServiceInstanceListSupplier.fixed("ignored-service").build(), healthCheck, webClient);
ServiceInstance serviceInstance = new DefaultServiceInstance("ignored-service-1", "ignored-service",
"127.0.0.1", port, false);
ServiceInstanceListSuppliers.from(serviceId, serviceInstance), healthCheck, webClient);
boolean alive = listSupplier.isAlive(serviceInstance).block();

View File

@@ -34,7 +34,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.CompletionContext;
import org.springframework.cloud.client.loadbalancer.DefaultRequest;
import org.springframework.cloud.client.loadbalancer.DefaultRequestContext;
import org.springframework.cloud.client.loadbalancer.DefaultResponse;
@@ -99,8 +98,6 @@ public class LoadBalancerTests {
else {
then(instance.isSecure()).isFalse();
}
response.onComplete(new CompletionContext(CompletionContext.Status.SUCCESS));
}).verifyComplete();
}
}