Only registerManagement if registration is non-null.
fixes https://github.com/spring-cloud/spring-cloud-zookeeper/issues/122
This commit is contained in:
@@ -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
|
||||
*/
|
||||
@Override
|
||||
protected void deregisterManagement() {
|
||||
this.serviceRegistry.deregister(getManagementRegistration());
|
||||
R registration = getManagementRegistration();
|
||||
if (registration != null) {
|
||||
this.serviceRegistry.deregister(registration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
@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 {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@Override
|
||||
protected TestRegistration getRegistration() {
|
||||
return null;
|
||||
return new TestRegistration();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user