fix:add deregister judgment. (#1076)

pull/1078/head
Haotian Zhang 1 year ago committed by GitHub
parent 663f3395c9
commit cc8d72cf14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,3 +22,4 @@
- [fix:fix SCG report wrong service bug when using IP routing.](https://github.com/Tencent/spring-cloud-tencent/pull/1064)
- [fix:fix gray release examples bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1067)
- [fix:fix router label feign interceptor order.](https://github.com/Tencent/spring-cloud-tencent/pull/1070)
- [fix:add deregister judgment.](https://github.com/Tencent/spring-cloud-tencent/pull/1076)

@ -88,6 +88,22 @@ public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistrat
}
@Override
protected void deregister() {
if (!this.registration.isRegisterEnabled()) {
return;
}
super.deregister();
}
@Override
protected void deregisterManagement() {
if (!this.registration.isRegisterEnabled()) {
return;
}
super.deregisterManagement();
}
@Override
protected Object getConfiguration() {
return this.polarisDiscoveryProperties;

@ -71,6 +71,7 @@ public class PolarisAutoServiceRegistrationTest {
@BeforeEach
void setUp() {
doNothing().when(serviceRegistry).register(nullable(PolarisRegistration.class));
doNothing().when(serviceRegistry).deregister(nullable(PolarisRegistration.class));
polarisAutoServiceRegistration =
new PolarisAutoServiceRegistration(serviceRegistry, autoServiceRegistrationProperties, registration,
@ -111,6 +112,32 @@ public class PolarisAutoServiceRegistrationTest {
}).doesNotThrowAnyException();
}
@Test
public void testDeregister() {
doReturn(false).when(registration).isRegisterEnabled();
assertThatCode(() -> {
polarisAutoServiceRegistration.registerManagement();
}).doesNotThrowAnyException();
doReturn(true).when(registration).isRegisterEnabled();
assertThatCode(() -> {
polarisAutoServiceRegistration.deregister();
}).doesNotThrowAnyException();
}
@Test
public void testDeregisterManagement() {
doReturn(false).when(registration).isRegisterEnabled();
assertThatCode(() -> {
polarisAutoServiceRegistration.registerManagement();
}).doesNotThrowAnyException();
doReturn(true).when(registration).isRegisterEnabled();
assertThatCode(() -> {
polarisAutoServiceRegistration.deregisterManagement();
}).doesNotThrowAnyException();
}
@Test
public void testGetAppName() {
doReturn("application").when(environment).getProperty(anyString(), anyString());

Loading…
Cancel
Save