diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java index 2e833460..89b200af 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java @@ -73,32 +73,6 @@ public class DefaultServiceInstance implements ServiceInstance { this(instanceId, serviceId, host, port, secure, new LinkedHashMap<>()); } - /** - * @param serviceId the id of the service. - * @param host the host where the service instance can be found. - * @param port the port on which the service is running. - * @param secure indicates whether or not the connection needs to be secure. - * @param metadata a map containing metadata. - * @deprecated - use other constructors - */ - @Deprecated - public DefaultServiceInstance(String serviceId, String host, int port, boolean secure, - Map metadata) { - this(null, serviceId, host, port, secure, metadata); - } - - /** - * @param serviceId the id of the service. - * @param host the host where the service instance can be found. - * @param port the port on which the service is running. - * @param secure indicates whether or not the connection needs to be secure. - * @deprecated - use other constructors - */ - @Deprecated - public DefaultServiceInstance(String serviceId, String host, int port, boolean secure) { - this(serviceId, host, port, secure, new LinkedHashMap<>()); - } - public DefaultServiceInstance() { } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClient.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClient.java deleted file mode 100644 index a65d0936..00000000 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClient.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2020 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.client.discovery.noop; - -import java.util.Collections; -import java.util.List; - -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; - -/** - * DiscoveryClient used when no implementations are found on the classpath. - * - * @deprecated Use - * {@link org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient - * instead}. - * @author Dave Syer - */ - -@Deprecated -public class NoopDiscoveryClient implements DiscoveryClient { - - public NoopDiscoveryClient(ServiceInstance instance) { - } - - @Override - public String description() { - return "Spring Cloud No-op DiscoveryClient"; - } - - @Override - public List getInstances(String serviceId) { - return Collections.emptyList(); - } - - @Override - public List getServices() { - return Collections.emptyList(); - } - -} diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java deleted file mode 100644 index f7773b02..00000000 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2012-2020 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.client.discovery.noop; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import javax.annotation.PostConstruct; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.client.DefaultServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.core.env.Environment; - -/** - * @deprecated Use - * {@link org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration - * instead}. - * @author Dave Syer - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnMissingBean(DiscoveryClient.class) -@Deprecated -public class NoopDiscoveryClientAutoConfiguration implements ApplicationListener { - - private final Log log = LogFactory.getLog(NoopDiscoveryClientAutoConfiguration.class); - - @Autowired(required = false) - private ServerProperties server; - - @Autowired - private ApplicationContext context; - - @Autowired - private Environment environment; - - @Autowired(required = false) - private PortFinder portFinder; - - private DefaultServiceInstance serviceInstance; - - @PostConstruct - public void init() { - String host = "localhost"; - try { - host = InetAddress.getLocalHost().getHostName(); - } - catch (UnknownHostException e) { - this.log.warn("Cannot get host info: (" + e.getMessage() + ")"); - } - int port = findPort(); - this.serviceInstance = new DefaultServiceInstance( - this.environment.getProperty("spring.application.name", "application"), host, port, false); - } - - private int findPort() { - int port = 0; - if (this.server != null && this.server.getPort() != null) { - port = this.server.getPort(); - } - if (port != 0 && this.portFinder != null) { - Integer found = this.portFinder.findPort(); - if (found != null) { - port = found; - } - } - else { - // Apparently spring-web is not on the classpath - if (this.log.isDebugEnabled()) { - this.log.debug("Could not locate port in embedded container (spring-web not available)"); - } - } - return port; - } - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - this.context.publishEvent(new InstanceRegisteredEvent<>(this, this.environment)); - } - - @Bean - public DiscoveryClient discoveryClient() { - return new NoopDiscoveryClient(this.serviceInstance); - } - - private interface PortFinder { - - Integer findPort(); - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(name = { "org.springframework.web.context.support.GenericWebApplicationContext", - "org.springframework.boot.context.embedded.EmbeddedWebApplicationContext" }) - protected static class Boot15PortFinderConfiguration { - - @Bean - public PortFinder portFinder(final ApplicationContext context) { - return new PortFinder() { - @Override - public Integer findPort() { - // TODO: support reactive - /* - * if (context instanceof EmbeddedWebApplicationContext) { - * EmbeddedServletContainer container = - * ((EmbeddedWebApplicationContext) context) - * .getEmbeddedServletContainer(); if (container != null) { return - * container.getPort(); } } - */ - return null; - } - }; - } - - } - -} diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java index afcf9a02..035ccab3 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java @@ -24,7 +24,6 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.cloud.client.CommonsClientAutoConfiguration; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration; import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -38,7 +37,7 @@ import org.springframework.core.annotation.Order; * @author Charu Covindane */ @Configuration(proxyBeanMethods = false) -@AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) +@AutoConfigureBefore({ CommonsClientAutoConfiguration.class }) public class SimpleDiscoveryClientAutoConfiguration implements ApplicationListener { private ServerProperties server; diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryProperties.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryProperties.java index 18eba713..b5f9335a 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryProperties.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryProperties.java @@ -16,9 +16,7 @@ package org.springframework.cloud.client.discovery.simple; -import java.net.URI; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -26,7 +24,6 @@ import javax.annotation.PostConstruct; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.client.DefaultServiceInstance; -import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; /** @@ -89,103 +86,4 @@ public class SimpleDiscoveryProperties { local = new DefaultServiceInstance(null, serviceId, host, port, false); } - /** - * Basic implementation of {@link ServiceInstance}. - * - * @deprecated in favor of {@link DefaultServiceInstance} - */ - @Deprecated - public static class SimpleServiceInstance implements ServiceInstance { - - /** - * The URI of the service instance. Will be parsed to extract the scheme, host, - * and port. - */ - private URI uri; - - private String host; - - private int port; - - private boolean secure; - - /** - * Metadata for the service instance. Can be used by discovery clients to modify - * their behaviour per instance, e.g. when load balancing. - */ - private Map metadata = new LinkedHashMap<>(); - - /** - * The unique identifier or name for the service instance. - */ - private String instanceId; - - /** - * The identifier or name for the service. Multiple instances might share the same - * service ID. - */ - private String serviceId; - - public SimpleServiceInstance() { - } - - public SimpleServiceInstance(URI uri) { - setUri(uri); - } - - @Override - public String getInstanceId() { - return this.instanceId; - } - - public void setInstanceId(String id) { - this.instanceId = id; - } - - @Override - public String getServiceId() { - return this.serviceId; - } - - public void setServiceId(String id) { - this.serviceId = id; - } - - @Override - public String getHost() { - return this.host; - } - - @Override - public int getPort() { - return this.port; - } - - @Override - public boolean isSecure() { - return this.secure; - } - - @Override - public URI getUri() { - return this.uri; - } - - public void setUri(URI uri) { - this.uri = uri; - this.host = this.uri.getHost(); - this.port = this.uri.getPort(); - String scheme = this.uri.getScheme(); - if ("https".equals(scheme)) { - this.secure = true; - } - } - - @Override - public Map getMetadata() { - return this.metadata; - } - - } - } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryProperties.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryProperties.java index 72527e8f..35fa5710 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryProperties.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryProperties.java @@ -16,9 +16,7 @@ package org.springframework.cloud.client.discovery.simple.reactive; -import java.net.URI; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -91,101 +89,4 @@ public class SimpleReactiveDiscoveryProperties { } } - /** - * Basic implementation of {@link ServiceInstance}. - */ - @Deprecated - public static class SimpleServiceInstance implements ServiceInstance { - - /** - * The URI of the service instance. Will be parsed to extract the scheme, host, - * and port. - */ - private URI uri; - - private String host; - - private int port; - - private boolean secure; - - /** - * Metadata for the service instance. Can be used by discovery clients to modify - * their behaviour per instance, e.g. when load balancing. - */ - private Map metadata = new LinkedHashMap<>(); - - /** - * The unique identifier or name for the service instance. - */ - private String instanceId; - - /** - * The identifier or name for the service. Multiple instances might share the same - * service ID. - */ - private String serviceId; - - public SimpleServiceInstance() { - } - - public SimpleServiceInstance(URI uri) { - setUri(uri); - } - - @Override - public String getInstanceId() { - return this.instanceId; - } - - public void setInstanceId(String id) { - this.instanceId = id; - } - - @Override - public String getServiceId() { - return this.serviceId; - } - - public void setServiceId(String id) { - this.serviceId = id; - } - - @Override - public String getHost() { - return this.host; - } - - @Override - public int getPort() { - return this.port; - } - - @Override - public boolean isSecure() { - return this.secure; - } - - @Override - public URI getUri() { - return this.uri; - } - - public void setUri(URI uri) { - this.uri = uri; - this.host = this.uri.getHost(); - this.port = this.uri.getPort(); - String scheme = this.uri.getScheme(); - if ("https".equals(scheme)) { - this.secure = true; - } - } - - @Override - public Map getMetadata() { - return this.metadata; - } - - } - } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultResponse.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultResponse.java index 85c74177..d2cf423e 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultResponse.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/DefaultResponse.java @@ -43,11 +43,6 @@ public class DefaultResponse implements Response { return this.serviceInstance; } - @Override - public void onComplete(CompletionContext completionContext) { - // do nothing: deprecated interface method - } - @Override public String toString() { ToStringCreator to = new ToStringCreator(this); diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/EmptyResponse.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/EmptyResponse.java index 36ab015e..1253526d 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/EmptyResponse.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/EmptyResponse.java @@ -33,9 +33,4 @@ public class EmptyResponse implements Response { return null; } - @Override - public void onComplete(CompletionContext completionContext) { - // do nothing: deprecated interface method - } - } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/Response.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/Response.java index e3d75806..a598f133 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/Response.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/Response.java @@ -28,13 +28,4 @@ public interface Response { T getServer(); - /** - * Notification that the request completed. - * @deprecated in favour of - * {@link LoadBalancerLifecycle#onComplete(CompletionContext)} - * @param completionContext - completion context - */ - @Deprecated - void onComplete(CompletionContext completionContext); - } diff --git a/spring-cloud-commons/src/main/resources/META-INF/spring.factories b/spring-cloud-commons/src/main/resources/META-INF/spring.factories index 327d234f..92505625 100644 --- a/spring-cloud-commons/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-commons/src/main/resources/META-INF/spring.factories @@ -4,7 +4,6 @@ org.springframework.cloud.client.CommonsClientAutoConfiguration,\ org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration,\ org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration,\ org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration,\ -org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration,\ org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration,\ org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration,\ org.springframework.cloud.client.hypermedia.CloudHypermediaAutoConfiguration,\ diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/ServiceInstanceListSupplier.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/ServiceInstanceListSupplier.java index c444ddd0..b63df843 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/ServiceInstanceListSupplier.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/ServiceInstanceListSupplier.java @@ -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 instances; - - @Deprecated - public static Builder with(Environment env) { - return new Builder(env); - } - - private FixedServiceInstanceListSupplier(String serviceId, List instances) { - this.serviceId = serviceId; - this.instances = instances; - } - - @Override - public String getServiceId() { - return serviceId; - } - - @Override - public Flux> get() { - return Flux.just(instances); - } - - @Deprecated - public static final class SimpleBuilder { - - private final ArrayList 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 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); - } - - } - - } - } diff --git a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java index e222e476..d59e924d 100644 --- a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java +++ b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java @@ -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(); diff --git a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/LoadBalancerTests.java b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/LoadBalancerTests.java index 8b6cf3c8..ee2cb4b8 100644 --- a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/LoadBalancerTests.java +++ b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/LoadBalancerTests.java @@ -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(); } }