Browse Source

Only registerManagement if registration is non-null.

fixes https://github.com/spring-cloud/spring-cloud-zookeeper/issues/122
pull/208/head
Spencer Gibb 8 years ago
parent
commit
a4169d451e
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 10
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java
  2. 1
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/RetryLoadBalancerInterceptorTest.java
  3. 30
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistrationTests.java

10
spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistration.java

@ -41,7 +41,10 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> ex @@ -41,7 +41,10 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> ex
*/
@Override
protected void registerManagement() {
this.serviceRegistry.register(getManagementRegistration());
R registration = getManagementRegistration();
if (registration != null) {
this.serviceRegistry.register(registration);
}
}
/**
@ -57,7 +60,10 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> ex @@ -57,7 +60,10 @@ public abstract class AbstractAutoServiceRegistration<R extends Registration> ex
*/
@Override
protected void deregisterManagement() {
this.serviceRegistry.deregister(getManagementRegistration());
R registration = getManagementRegistration();
if (registration != null) {
this.serviceRegistry.deregister(registration);
}
}
@Override

1
spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/RetryLoadBalancerInterceptorTest.java

@ -16,7 +16,6 @@ import org.springframework.mock.http.client.MockClientHttpResponse; @@ -16,7 +16,6 @@ import org.springframework.mock.http.client.MockClientHttpResponse;
import org.springframework.retry.policy.NeverRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import static org.bouncycastle.crypto.tls.ConnectionEnd.client;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.any;

30
spring-cloud-commons/src/test/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistrationTests.java

@ -5,8 +5,9 @@ import java.util.concurrent.atomic.AtomicInteger; @@ -5,8 +5,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -31,10 +32,10 @@ public class AbstractAutoServiceRegistrationTests { @@ -31,10 +32,10 @@ public class AbstractAutoServiceRegistrationTests {
@Autowired
private TestAutoServiceRegistration autoRegistration;
@Value("${local.server.port}")
@LocalServerPort
private int port;
@Value("${local.management.port}")
@LocalManagementPort
private int managementPort;
@Test
@ -65,18 +66,35 @@ public class AbstractAutoServiceRegistrationTests { @@ -65,18 +66,35 @@ public class AbstractAutoServiceRegistrationTests {
}
}
public static class TestMgmtRegistration extends TestRegistration {
@Override
public String getServiceId() {
return "testMgmtRegistration2";
}
}
public static class TestServiceRegistry implements ServiceRegistry<TestRegistration> {
private boolean registered = false;
private boolean deregistered = false;
@Override
public void register(TestRegistration registration) {
this.registered = true;
if (registration == null) {
throw new NullPointerException();
}
if (!(registration instanceof TestMgmtRegistration)) {
this.registered = true;
}
}
@Override
public void deregister(TestRegistration registration) {
this.deregistered = true;
if (registration == null) {
throw new NullPointerException();
}
if (!(registration instanceof TestMgmtRegistration)) {
this.deregistered = true;
}
}
@Override
@ -131,7 +149,7 @@ public class AbstractAutoServiceRegistrationTests { @@ -131,7 +149,7 @@ public class AbstractAutoServiceRegistrationTests {
@Override
protected TestRegistration getRegistration() {
return null;
return new TestRegistration();
}
@Override

Loading…
Cancel
Save