Browse Source

Remove deprecated DiscoveryClient.getLocalServiceInstance()

pull/284/head
Spencer Gibb 7 years ago
parent
commit
89170d127d
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 8
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java
  2. 19
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClient.java
  3. 8
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClient.java
  4. 5
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClient.java
  5. 5
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientAutoConfigurationTests.java
  6. 21
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientTests.java
  7. 8
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientPropertiesMappingTests.java

8
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java

@ -33,14 +33,6 @@ public interface DiscoveryClient {
*/ */
String description(); String description();
/**
* @deprecated use the {@link org.springframework.cloud.client.serviceregistry.Registration} bean instead
*
* @return ServiceInstance with information used to register the local service
*/
@Deprecated
ServiceInstance getLocalServiceInstance();
/** /**
* Get all ServiceInstances associated with a particular serviceId * Get all ServiceInstances associated with a particular serviceId
* @param serviceId the serviceId to query * @param serviceId the serviceId to query

19
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClient.java

@ -1,13 +1,13 @@
package org.springframework.cloud.client.discovery.composite; package org.springframework.cloud.client.discovery.composite;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
/** /**
* A {@link DiscoveryClient} composed of other Discovery Client's and will delegate the * A {@link DiscoveryClient} composed of other Discovery Client's and will delegate the
* calls to each of them in order * calls to each of them in order
@ -27,19 +27,6 @@ public class CompositeDiscoveryClient implements DiscoveryClient {
return "Composite Discovery Client"; return "Composite Discovery Client";
} }
@Override
public ServiceInstance getLocalServiceInstance() {
if (this.discoveryClients != null) {
for (DiscoveryClient discoveryClient : discoveryClients) {
ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance();
if (serviceInstance != null) {
return serviceInstance;
}
}
}
return null;
}
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
if (this.discoveryClients != null) { if (this.discoveryClients != null) {

8
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClient.java

@ -33,10 +33,7 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
@Deprecated @Deprecated
public class NoopDiscoveryClient implements DiscoveryClient { public class NoopDiscoveryClient implements DiscoveryClient {
private final ServiceInstance instance;
public NoopDiscoveryClient(ServiceInstance instance) { public NoopDiscoveryClient(ServiceInstance instance) {
this.instance = instance;
} }
@Override @Override
@ -44,11 +41,6 @@ public class NoopDiscoveryClient implements DiscoveryClient {
return "Spring Cloud No-op DiscoveryClient"; return "Spring Cloud No-op DiscoveryClient";
} }
@Override
public ServiceInstance getLocalServiceInstance() {
return this.instance;
}
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
return Collections.emptyList(); return Collections.emptyList();

5
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClient.java

@ -26,11 +26,6 @@ public class SimpleDiscoveryClient implements DiscoveryClient {
return "Simple Discovery Client"; return "Simple Discovery Client";
} }
@Override
public ServiceInstance getLocalServiceInstance() {
return this.simpleDiscoveryProperties.getLocal();
}
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
List<ServiceInstance> serviceInstances = new ArrayList<>(); List<ServiceInstance> serviceInstances = new ArrayList<>();

5
spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientAutoConfigurationTests.java

@ -59,11 +59,6 @@ public class CompositeDiscoveryClientAutoConfigurationTests {
return "A custom discovery client"; return "A custom discovery client";
} }
@Override
public ServiceInstance getLocalServiceInstance() {
return null;
}
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
return null; return null;

21
spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientTests.java

@ -1,5 +1,10 @@
package org.springframework.cloud.client.discovery.composite; package org.springframework.cloud.client.discovery.composite;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,11 +18,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
@ -72,12 +72,6 @@ public class CompositeDiscoveryClientTests {
assertThat(this.discoveryClient.getInstances("unknown")).hasSize(0); assertThat(this.discoveryClient.getInstances("unknown")).hasSize(0);
} }
@Test
public void localServiceInstanceShouldReturnTheFirstMatch() {
assertThat(this.discoveryClient.getLocalServiceInstance().getServiceId()).isEqualTo("service0");
}
@EnableAutoConfiguration @EnableAutoConfiguration
@Configuration @Configuration
public static class Config { public static class Config {
@ -91,11 +85,6 @@ public class CompositeDiscoveryClientTests {
return "A custom discovery client"; return "A custom discovery client";
} }
@Override
public ServiceInstance getLocalServiceInstance() {
return null;
}
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
if (serviceId.equals("custom")) { if (serviceId.equals("custom")) {

8
spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientPropertiesMappingTests.java

@ -82,14 +82,6 @@ public class SimpleDiscoveryClientPropertiesMappingTests {
assertThat(this.discoveryClient.getInstances("nonexistent")).isEmpty(); assertThat(this.discoveryClient.getInstances("nonexistent")).isEmpty();
} }
@Test
public void testGetLocalInstance() {
assertThat(this.discoveryClient.getLocalServiceInstance().getServiceId())
.isEqualTo("service0");
assertThat(this.discoveryClient.getLocalServiceInstance().getPort())
.isEqualTo(8080);
}
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
public static class SampleConfig { public static class SampleConfig {

Loading…
Cancel
Save