pull/1458/head
shedfreewu 11 months ago
parent e710eae4ab
commit aa11401883

@ -171,10 +171,10 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-checkstyle-plugin</artifactId>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

@ -20,7 +20,6 @@ package com.tencent.cloud.metadata.core;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -55,7 +54,7 @@ public class DecodeTransferMetadataReactiveFilterTest {
@BeforeEach
public void setUp() {
this.metadataReactiveFilter = new DecodeTransferMetadataReactiveFilter(new PolarisContextProperties());
this.metadataReactiveFilter = new DecodeTransferMetadataReactiveFilter();
}
@Test

@ -20,6 +20,7 @@ package com.tencent.cloud.polaris.router.config;
import com.tencent.cloud.polaris.router.RouterConfigModifier;
import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties;
import com.tencent.cloud.polaris.router.config.properties.PolarisNamespaceRouterProperties;
import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties;
import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties;
@ -35,7 +36,8 @@ import org.springframework.context.annotation.Import;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnPolarisRouterEnabled
@Import({PolarisNearByRouterProperties.class, PolarisMetadataRouterProperties.class, PolarisRuleBasedRouterProperties.class})
@Import({PolarisNearByRouterProperties.class, PolarisMetadataRouterProperties.class, PolarisRuleBasedRouterProperties.class,
PolarisNamespaceRouterProperties.class})
public class RouterConfigModifierAutoConfiguration {
@Bean

@ -31,8 +31,6 @@ public class PolarisNearByRouterProperties {
private String matchLevel;
private String matchLevel;
public boolean isEnabled() {
return enabled;
}

@ -1,36 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.router.config.properties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* RouterBootstrapAutoConfiguration.
*
* @author sean yu
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@Import(RouterConfigModifierAutoConfiguration.class)
public class RouterBootstrapAutoConfiguration {
}

@ -1,46 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.router.config.properties;
import com.tencent.cloud.polaris.router.RouterConfigModifier;
import com.tencent.cloud.polaris.router.config.ConditionalOnPolarisRouterEnabled;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* RouterConfigModifierAutoConfiguration.
*
* @author sean yu
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnPolarisRouterEnabled
@Import({PolarisNearByRouterProperties.class, PolarisMetadataRouterProperties.class, PolarisRuleBasedRouterProperties.class,
PolarisNamespaceRouterProperties.class})
public class RouterConfigModifierAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public RouterConfigModifier routerConfigModifier(PolarisNearByRouterProperties polarisNearByRouterProperties) {
return new RouterConfigModifier(polarisNearByRouterProperties);
}
}

@ -18,12 +18,6 @@
"defaultValue": "ZONE",
"description": "the match level for nearby router, options can be REGION/ZONE/CAMPUS."
},
{
"name": "spring.cloud.polaris.router.nearby-router.matchLevel",
"type": "java.lang.String",
"defaultValue": "zone",
"description": "the match level for nearby router, options can be region/zone/campus."
},
{
"name": "spring.cloud.polaris.router.rule-router.enabled",
"type": "java.lang.Boolean",

@ -1,5 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.router.config.properties.RouterConfigModifierAutoConfiguration,\
com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration,\
com.tencent.cloud.polaris.router.config.RouterAutoConfiguration,\
com.tencent.cloud.polaris.router.config.FeignAutoConfiguration,\
com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration

@ -61,7 +61,7 @@ public class RouterBootstrapAutoConfigurationTest {
routerConfigModifier.modify((ConfigurationImpl) configuration);
NearbyRouterConfig nearbyRouterConfig = configuration.getConsumer().getServiceRouter().getPluginConfig(
ServiceRouterConfig.DEFAULT_ROUTER_NEARBY, NearbyRouterConfig.class);
Assertions.assertEquals("campus", nearbyRouterConfig.getMatchLevel().name());
Assertions.assertEquals("CAMPUS", nearbyRouterConfig.getMatchLevel().name());
});
}
}

@ -18,11 +18,10 @@
package com.tencent.cloud.plugin.discovery.adapter.transformer;
import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.netflix.loadbalancer.Server;
import com.tencent.cloud.polaris.loadbalancer.transformer.InstanceTransformer;
import com.tencent.polaris.api.pojo.DefaultInstance;
import org.apache.commons.lang.StringUtils;
import org.springframework.cloud.client.ServiceInstance;
/**
* NacosInstanceTransformer.
@ -32,20 +31,12 @@ import org.springframework.cloud.client.ServiceInstance;
public class NacosInstanceTransformer implements InstanceTransformer {
@Override
public void transformCustom(DefaultInstance instance, ServiceInstance serviceInstance) {
if ("com.alibaba.cloud.nacos.NacosServiceInstance".equals(serviceInstance.getClass().getName())) {
String nacosWeight = serviceInstance.getMetadata().get("nacos.weight");
instance.setWeight(
StringUtils.isBlank(nacosWeight) ? 100 : (int) Double.parseDouble(nacosWeight) * 100
);
String nacosHealthy = serviceInstance.getMetadata().get("nacos.healthy");
instance.setHealthy(
!StringUtils.isBlank(nacosHealthy) && Boolean.parseBoolean(nacosHealthy)
);
String nacosInstanceId = serviceInstance.getMetadata().get("nacos.instanceId");
instance.setId(nacosInstanceId);
public void transformCustom(DefaultInstance instance, Server server) {
if ("com.alibaba.cloud.nacos.ribbon.NacosServer".equals(server.getClass().getName())) {
NacosServer nacosServer = (NacosServer) server;
instance.setWeight((int) (nacosServer.getInstance().getWeight() * 100));
instance.setHealthy(nacosServer.getInstance().isHealthy());
instance.setMetadata(nacosServer.getMetadata());
}
}
}

@ -18,12 +18,10 @@
package com.tencent.cloud.plugin.discovery.adapter.config;
import java.util.HashMap;
import com.alibaba.cloud.nacos.NacosServiceInstance;
import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.plugin.discovery.adapter.transformer.NacosInstanceTransformer;
import com.tencent.polaris.api.pojo.Instance;
import com.tencent.polaris.api.pojo.DefaultInstance;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
@ -53,13 +51,14 @@ public class NacosInstanceTransformerTest {
@Test
public void test() {
NacosInstanceTransformer nacosInstanceTransformer = new NacosInstanceTransformer();
NacosServiceInstance nacosServiceInstance = new NacosServiceInstance();
nacosServiceInstance.setMetadata(new HashMap<String, String>() {{
put("nacos.weight", "0.01");
put("nacos.healthy", "true");
put("nacos.instanceId", "xxx");
}});
Instance instance = nacosInstanceTransformer.transform(nacosServiceInstance);
com.alibaba.nacos.api.naming.pojo.Instance nacosInstance = new com.alibaba.nacos.api.naming.pojo.Instance();
nacosInstance.setHealthy(true);
NacosServer nacosServer = new NacosServer(nacosInstance);
DefaultInstance instance = new DefaultInstance();
nacosInstanceTransformer.transformCustom(instance, nacosServer);
assertThat(instance.isHealthy()).isEqualTo(true);
}

@ -1,95 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.lossless;
import java.util.HashMap;
import java.util.Map;
import com.tencent.cloud.common.util.OkHttpUtil;
import com.tencent.cloud.plugin.lossless.config.LosslessProperties;
import com.tencent.cloud.rpc.enhancement.transformer.RegistrationTransformer;
import com.tencent.polaris.api.plugin.lossless.InstanceProperties;
import com.tencent.polaris.api.plugin.lossless.LosslessActionProvider;
import com.tencent.polaris.api.pojo.BaseInstance;
import com.tencent.polaris.api.utils.StringUtils;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.http.HttpHeaders;
/**
* LosslessActionProvider for Spring Cloud.
*
* @author Shedfree Wu
*/
public class SpringCloudLosslessActionProvider implements LosslessActionProvider {
private ServiceRegistry<Registration> serviceRegistry;
private LosslessProperties losslessProperties;
private Runnable originalRegisterAction;
private Registration registration;
public SpringCloudLosslessActionProvider(ServiceRegistry<Registration> serviceRegistry, Registration registration,
LosslessProperties losslessProperties, Runnable originalRegisterAction) {
this.serviceRegistry = serviceRegistry;
this.registration = registration;
this.losslessProperties = losslessProperties;
this.originalRegisterAction = originalRegisterAction;
}
@Override
public String getName() {
return "spring-cloud";
}
@Override
public void doRegister(InstanceProperties instanceProperties) {
// use lambda to do original register
originalRegisterAction.run();
}
@Override
public void doDeregister() {
serviceRegistry.deregister(registration);
}
/**
* Check whether health check is enable.
* @return true: register after passing doHealthCheck, false: register after delayRegisterInterval.
*/
@Override
public boolean isEnableHealthCheck() {
return StringUtils.isNotBlank(losslessProperties.getHealthCheckPath());
}
@Override
public boolean doHealthCheck() {
Map<String, String> headers = new HashMap<>(1);
headers.put(HttpHeaders.USER_AGENT, "polaris");
return OkHttpUtil.checkUrl("localhost", registration.getPort(),
losslessProperties.getHealthCheckPath(), headers);
}
public static BaseInstance getBaseInstance(Registration registration, RegistrationTransformer registrationTransformer) {
return registrationTransformer.transform(registration);
}
}

@ -1,91 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.lossless;
import com.tencent.cloud.plugin.lossless.config.LosslessConfigModifier;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.polaris.api.config.provider.LosslessConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link LosslessConfigModifier}.
*
* @author Shedfree Wu
*/
public class LosslessConfigModifierTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(TestApplication.class))
.withPropertyValues("spring.cloud.nacos.discovery.enabled=false")
.withPropertyValues("spring.cloud.polaris.enabled=true")
.withPropertyValues("spring.cloud.polaris.lossless.enabled=true")
.withPropertyValues("spring.cloud.polaris.lossless.port=20000")
.withPropertyValues("spring.cloud.polaris.lossless.healthCheckPath=/xxx")
.withPropertyValues("spring.cloud.polaris.lossless.delayRegisterInterval=10")
.withPropertyValues("spring.cloud.polaris.lossless.healthCheckInterval=5")
.withPropertyValues("spring.application.name=test")
.withPropertyValues("spring.cloud.gateway.enabled=false");
private final ApplicationContextRunner disabledContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(TestApplication.class))
.withPropertyValues("spring.cloud.nacos.discovery.enabled=false")
.withPropertyValues("spring.cloud.polaris.enabled=true")
.withPropertyValues("spring.cloud.polaris.lossless.enabled=false")
.withPropertyValues("spring.application.name=test")
.withPropertyValues("spring.cloud.gateway.enabled=false");
@BeforeEach
void setUp() {
PolarisSDKContextManager.innerDestroy();
}
@Test
void testModify() {
contextRunner.run(context -> {
PolarisSDKContextManager polarisSDKContextManager = context.getBean(PolarisSDKContextManager.class);
LosslessConfig losslessConfig = polarisSDKContextManager.getSDKContext().
getConfig().getProvider().getLossless();
assertThat(losslessConfig.getHost()).isEqualTo("0.0.0.0");
assertThat(losslessConfig.getPort()).isEqualTo(20000);
assertThat(losslessConfig.getDelayRegisterInterval()).isEqualTo(10);
assertThat(losslessConfig.getHealthCheckInterval()).isEqualTo(5);
});
}
@Test
void testDisabled() {
disabledContextRunner.run(context -> {
PolarisSDKContextManager polarisSDKContextManager = context.getBean(PolarisSDKContextManager.class);
LosslessConfig losslessConfig = polarisSDKContextManager.getSDKContext().
getConfig().getProvider().getLossless();
assertThat(losslessConfig.isEnable()).isFalse();
});
}
@SpringBootApplication
protected static class TestApplication {
}
}

@ -1,191 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.plugin.lossless;
import java.util.Collections;
import com.tencent.cloud.common.util.OkHttpUtil;
import com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration;
import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClientConfiguration;
import com.tencent.cloud.polaris.registry.PolarisRegistration;
import com.tencent.cloud.polaris.registry.PolarisServiceRegistry;
import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.test.mock.discovery.NamingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationUtils;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
/**
* Test for {@link LosslessRegistryAspect}.
*
* @author Shedfree Wu
*/
public class LosslessRegistryAspectTest {
private static String NAMESPACE_TEST = "Test";
private static String SERVICE_PROVIDER = "java_provider_test";
private static String HOST = "127.0.0.1";
private static int APPLICATION_PORT = 19091;
private static int LOSSLESS_PORT_1 = 28083;
private static NamingServer namingServer;
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
LosslessAutoConfiguration.class,
LosslessPropertiesBootstrapConfiguration.class,
PolarisContextAutoConfiguration.class,
PolarisPropertiesConfiguration.class,
PolarisDiscoveryClientConfiguration.class,
PolarisDiscoveryAutoConfiguration.class))
.withPropertyValues("spring.cloud.nacos.discovery.enabled=false")
.withPropertyValues("spring.cloud.polaris.lossless.delayRegisterInterval=5000")
.withPropertyValues("spring.cloud.polaris.lossless.healthCheckPath=")
.withPropertyValues("spring.cloud.polaris.lossless.port=" + LOSSLESS_PORT_1)
.withPropertyValues("spring.application.name=" + SERVICE_PROVIDER)
.withPropertyValues("server.port=" + APPLICATION_PORT)
.withPropertyValues("spring.cloud.polaris.localIpAddress=" + HOST)
.withPropertyValues("spring.cloud.polaris.localPort=" + APPLICATION_PORT)
.withPropertyValues("spring.cloud.polaris.address=grpc://127.0.0.1:10081")
.withPropertyValues("spring.cloud.polaris.discovery.namespace=" + NAMESPACE_TEST)
.withPropertyValues("spring.cloud.polaris.discovery.token=xxxxxx");
private final WebApplicationContextRunner contextRunner2 = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
LosslessAutoConfiguration.class,
LosslessPropertiesBootstrapConfiguration.class,
PolarisContextAutoConfiguration.class,
PolarisPropertiesConfiguration.class,
PolarisDiscoveryClientConfiguration.class,
PolarisDiscoveryAutoConfiguration.class))
.withPropertyValues("spring.cloud.nacos.discovery.enabled=false")
.withPropertyValues("spring.cloud.polaris.lossless.healthCheckInterval=1000")
.withPropertyValues("spring.cloud.polaris.lossless.healthCheckPath=/test")
.withPropertyValues("spring.cloud.polaris.lossless.port=28082")
.withPropertyValues("spring.application.name=" + SERVICE_PROVIDER)
.withPropertyValues("server.port=" + APPLICATION_PORT)
.withPropertyValues("spring.cloud.polaris.localIpAddress=" + HOST)
.withPropertyValues("spring.cloud.polaris.localPort=" + APPLICATION_PORT)
.withPropertyValues("spring.cloud.polaris.address=grpc://127.0.0.1:10081")
.withPropertyValues("spring.cloud.polaris.discovery.namespace=" + NAMESPACE_TEST)
.withPropertyValues("spring.cloud.polaris.discovery.token=xxxxxx");
@BeforeAll
static void beforeAll() throws Exception {
namingServer = NamingServer.startNamingServer(10081);
// add service
namingServer.getNamingService().addService(new ServiceKey(NAMESPACE_TEST, SERVICE_PROVIDER));
}
@AfterAll
static void afterAll() {
if (null != namingServer) {
namingServer.terminate();
}
}
@BeforeEach
void setUp() {
PolarisSDKContextManager.innerDestroy();
}
@Test
public void testRegister() {
this.contextRunner.run(context -> {
AbstractAutoServiceRegistration autoServiceRegistration = context.getBean(AbstractAutoServiceRegistration.class);
assertThatCode(() -> {
AutoServiceRegistrationUtils.register(autoServiceRegistration);
}).doesNotThrowAnyException();
Thread.sleep(1000);
// before register online status is false
assertThatCode(() -> {
assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/online", Collections.EMPTY_MAP)).isFalse();
}).doesNotThrowAnyException();
// delay register after 5s
Thread.sleep(10000);
PolarisServiceRegistry registry = context.getBean(PolarisServiceRegistry.class);
PolarisRegistration registration = context.getBean(PolarisRegistration.class);
assertThatCode(() -> {
assertThat(registry.getStatus(registration)).isEqualTo("DOWN");
}).doesNotThrowAnyException();
assertThatCode(() -> {
assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/online", Collections.EMPTY_MAP)).isTrue();
}).doesNotThrowAnyException();
assertThatCode(() -> {
assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/offline", Collections.EMPTY_MAP)).isTrue();
}).doesNotThrowAnyException();
assertThatCode(() -> {
AutoServiceRegistrationUtils.deRegister(autoServiceRegistration);
}).doesNotThrowAnyException();
assertThatCode(() -> {
assertThat(registry.getStatus(registration)).isEqualTo("DOWN");
}).doesNotThrowAnyException();
});
}
@Test
public void testRegister2() {
this.contextRunner2.run(context -> {
AbstractAutoServiceRegistration autoServiceRegistration = context.getBean(AbstractAutoServiceRegistration.class);
assertThatCode(() -> {
AutoServiceRegistrationUtils.register(autoServiceRegistration);
}).doesNotThrowAnyException();
Thread.sleep(2000);
assertThatCode(() -> {
AutoServiceRegistrationUtils.deRegister(autoServiceRegistration);
}).doesNotThrowAnyException();
});
}
@Configuration
@EnableAutoConfiguration
static class PolarisPropertiesConfiguration {
}
}

@ -1,29 +0,0 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.serviceregistry;
public class AutoServiceRegistrationUtils {
public static void register(AbstractAutoServiceRegistration autoServiceRegistration) {
autoServiceRegistration.register();
}
public static void deRegister(AbstractAutoServiceRegistration autoServiceRegistration) {
autoServiceRegistration.deregister();
}
}
Loading…
Cancel
Save