diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a352876..9464bff9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,4 @@ - [Bugfix: Removed unused class for circuit-breaker module](https://github.com/Tencent/spring-cloud-tencent/pull/456) - [Feature: Add disposable metadata transfer support](https://github.com/Tencent/spring-cloud-tencent/pull/458) - [loadBalancer module add unit test.](https://github.com/Tencent/spring-cloud-tencent/pull/468) +- [docs:update configuration metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/473) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisServiceDiscovery.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisServiceDiscovery.java index 771a3c57d..85c79897d 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisServiceDiscovery.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisServiceDiscovery.java @@ -18,6 +18,7 @@ package com.tencent.cloud.polaris.discovery; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -29,6 +30,7 @@ import com.tencent.polaris.api.pojo.ServiceInstances; import com.tencent.polaris.api.rpc.InstancesResponse; import org.springframework.cloud.client.ServiceInstance; +import org.springframework.util.CollectionUtils; /** * Polaris service discovery service. @@ -65,7 +67,10 @@ public class PolarisServiceDiscovery { * @throws PolarisException polarisException */ public List getServices() throws PolarisException { - return polarisDiscoveryHandler.GetServices().getServices().stream().map(ServiceInfo::getService) - .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(polarisDiscoveryHandler.GetServices().getServices())) { + return Collections.emptyList(); + } + return polarisDiscoveryHandler.GetServices().getServices().stream() + .map(ServiceInfo::getService).collect(Collectors.toList()); } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 7743b5f6c..93372d6dc 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -24,6 +24,12 @@ "defaultValue": true, "description": "enable polaris registration or not." }, + { + "name": "spring.cloud.polaris.discovery.heartbeat-interval", + "type": "java.lang.Integer", + "defaultValue": "5000", + "description": "Millis interval of Heart beat. Default: 5000." + }, { "name": "spring.cloud.polaris.discovery.health-check-url", "type": "java.lang.String", diff --git a/spring-cloud-tencent-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-tencent-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 390f49158..575ca9738 100644 --- a/spring-cloud-tencent-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-tencent-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -9,6 +9,11 @@ "name": "spring.cloud.tencent.metadata.transitive", "type": "java.util.List", "description": "Custom transitive metadata key list." + }, + { + "name": "spring.cloud.tencent.metadata.disposable", + "type": "java.util.List", + "description": "Custom disposable metadata key list." } ] } diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 6debc5b87..f389d2b61 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -73,7 +73,7 @@ 1.7.0-2020.0.5-SNAPSHOT - 1.7.1 + 1.7.2 1.2.11 4.5.1 1.12.10 diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml index a3b008536..de8c607b2 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/bootstrap.yml @@ -15,12 +15,14 @@ spring: port: 28081 loadbalancer: configurations: polaris -# tencent: -# rpc-enhancement: -# enabled: true -# ignore-internal-server-error: true -# series: server_error -# statuses: gateway_timeout, bad_gateway, service_unavailable + tencent: + rpc-enhancement: + enabled: true + reporter: + ignore-internal-server-error: true + series: server_error + statuses: gateway_timeout, bad_gateway, service_unavailable + feign: circuitbreaker: enabled: true diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapter.java index 41b9fe154..6ba28617d 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapter.java @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,19 +50,17 @@ import static org.springframework.http.HttpStatus.VARIANT_ALSO_NEGOTIATES; public abstract class AbstractPolarisReporterAdapter { private static final Logger LOG = LoggerFactory.getLogger(AbstractPolarisReporterAdapter.class); - - protected final RpcEnhancementProperties properties; - private static final List HTTP_STATUSES = toList(NOT_IMPLEMENTED, BAD_GATEWAY, SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES, INSUFFICIENT_STORAGE, LOOP_DETECTED, BANDWIDTH_LIMIT_EXCEEDED, NOT_EXTENDED, NETWORK_AUTHENTICATION_REQUIRED); + protected final RpcEnhancementReporterProperties properties; /** - * Constructor With {@link RpcEnhancementProperties} . + * Constructor With {@link RpcEnhancementReporterProperties} . * - * @param properties instance of {@link RpcEnhancementProperties}. + * @param properties instance of {@link RpcEnhancementReporterProperties}. */ - protected AbstractPolarisReporterAdapter(RpcEnhancementProperties properties) { + protected AbstractPolarisReporterAdapter(RpcEnhancementReporterProperties properties) { this.properties = properties; } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java index 4dc25c30b..ab22b6b5c 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java @@ -50,7 +50,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; */ @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(value = "spring.cloud.tencent.rpc-enhancement.enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(RpcEnhancementProperties.class) +@EnableConfigurationProperties(RpcEnhancementReporterProperties.class) @AutoConfigureAfter(PolarisContextAutoConfiguration.class) public class RpcEnhancementAutoConfiguration { @@ -76,7 +76,7 @@ public class RpcEnhancementAutoConfiguration { static class PolarisReporterConfig { @Bean - public SuccessPolarisReporter successPolarisReporter(RpcEnhancementProperties properties) { + public SuccessPolarisReporter successPolarisReporter(RpcEnhancementReporterProperties properties) { return new SuccessPolarisReporter(properties); } @@ -99,15 +99,15 @@ public class RpcEnhancementAutoConfiguration { @Bean public EnhancedRestTemplateReporter polarisRestTemplateResponseErrorHandler( - RpcEnhancementProperties properties, ConsumerAPI consumerAPI, + RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI, @Autowired(required = false) PolarisResponseErrorHandler polarisResponseErrorHandler) { return new EnhancedRestTemplateReporter(properties, consumerAPI, polarisResponseErrorHandler); } @Bean public EnhancedRestTemplateModifier polarisRestTemplateBeanPostProcessor( - EnhancedRestTemplateReporter enhancedRestTemplateReporter) { - return new EnhancedRestTemplateModifier(enhancedRestTemplateReporter); + EnhancedRestTemplateReporter restTemplateResponseErrorHandler) { + return new EnhancedRestTemplateModifier(restTemplateResponseErrorHandler); } } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementProperties.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterProperties.java similarity index 79% rename from spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementProperties.java rename to spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterProperties.java index 612a97fbe..a044f459c 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementProperties.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterProperties.java @@ -29,27 +29,22 @@ import org.springframework.http.HttpStatus; * * @author Elve.Xu 2022-07-08 */ -@ConfigurationProperties("spring.cloud.tencent.rpc-enhancement") -public class RpcEnhancementProperties { +@ConfigurationProperties("spring.cloud.tencent.rpc-enhancement.reporter") +public class RpcEnhancementReporterProperties { /** - * If circuit-breaker enabled. - */ - private boolean enabled = true; - - /** - * Specify the Http status code(s) that needs to be fused. + * Specify the Http status code(s) that needs to be reported as FAILED. */ private List statuses = new ArrayList<>(); /** - * Specify List of HTTP status series. + * Specify List of HTTP status series that needs to be reported as FAILED when status list is empty. */ private List series = toList(HttpStatus.Series.SERVER_ERROR); /** - * Ignore Internal Server Error Http Status Code, - * Only takes effect if the attribute {@link RpcEnhancementProperties#series} is not empty. + * If ignore "Internal Server Error Http Status Code (500)", + * Only takes effect if the attribute {@link RpcEnhancementReporterProperties#series} is not empty. */ private boolean ignoreInternalServerError = true; @@ -81,14 +76,6 @@ public class RpcEnhancementProperties { this.series = series; } - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - public boolean isIgnoreInternalServerError() { return ignoreInternalServerError; } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java index e2bb22b32..d4dc77344 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java @@ -18,7 +18,7 @@ package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter; import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter; -import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignContext; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPlugin; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPluginType; @@ -42,14 +42,13 @@ import org.springframework.http.HttpStatus; public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter implements EnhancedFeignPlugin { private static final Logger LOG = LoggerFactory.getLogger(SuccessPolarisReporter.class); + @Autowired(required = false) + private ConsumerAPI consumerAPI; - public SuccessPolarisReporter(RpcEnhancementProperties properties) { + public SuccessPolarisReporter(RpcEnhancementReporterProperties properties) { super(properties); } - @Autowired(required = false) - private ConsumerAPI consumerAPI; - @Override public String getName() { return SuccessPolarisReporter.class.getName(); diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java index dd841b4b6..b3c8e9a09 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java @@ -26,7 +26,7 @@ import java.util.Objects; import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.util.ReflectionUtils; import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter; -import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.pojo.RetStatus; import com.tencent.polaris.api.pojo.ServiceKey; @@ -55,7 +55,7 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter private final PolarisResponseErrorHandler polarisResponseErrorHandler; - public EnhancedRestTemplateReporter(RpcEnhancementProperties properties, ConsumerAPI consumerAPI, + public EnhancedRestTemplateReporter(RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI, PolarisResponseErrorHandler polarisResponseErrorHandler) { super(properties); this.consumerAPI = consumerAPI; diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 77baec1e6..c76a18566 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1,5 +1,29 @@ { "properties": [ + { + "name": "spring.cloud.tencent.rpc-enhancement.enabled", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "If rpc enhancement enabled." + }, + { + "name": "spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "If ignore \"Internal Server Error Http Status Code (500)\"." + }, + { + "name": "spring.cloud.tencent.rpc-enhancement.reporter.series", + "type": "java.util.List", + "defaultValue": "HttpStatus.Series.SERVER_ERROR", + "description": "Specify List of HTTP status series that needs to be reported as FAILED when status list is empty." + }, + { + "name": "spring.cloud.tencent.rpc-enhancement.reporter.statuses", + "type": "java.util.List", + "defaultValue": "", + "description": "Specify the Http status code(s) that needs to be reported as FAILED." + }, { "name": "spring.cloud.polaris.stat.enabled", "type": "java.lang.Boolean", diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapterTest.java index db205c313..a14655de3 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapterTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/AbstractPolarisReporterAdapterTest.java @@ -17,7 +17,7 @@ package com.tencent.cloud.rpc.enhancement; -import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -32,7 +32,7 @@ public class AbstractPolarisReporterAdapterTest { @Test public void testApplyWithDefaultConfig() { - RpcEnhancementProperties properties = new RpcEnhancementProperties(); + RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties(); // Mock Condition SimplePolarisReporterAdapter adapter = new SimplePolarisReporterAdapter(properties); @@ -44,7 +44,7 @@ public class AbstractPolarisReporterAdapterTest { @Test public void testApplyWithoutIgnoreInternalServerError() { - RpcEnhancementProperties properties = new RpcEnhancementProperties(); + RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties(); // Mock Condition properties.getStatuses().clear(); properties.setIgnoreInternalServerError(false); @@ -59,7 +59,7 @@ public class AbstractPolarisReporterAdapterTest { @Test public void testApplyWithIgnoreInternalServerError() { - RpcEnhancementProperties properties = new RpcEnhancementProperties(); + RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties(); // Mock Condition properties.getStatuses().clear(); properties.setIgnoreInternalServerError(true); @@ -74,7 +74,7 @@ public class AbstractPolarisReporterAdapterTest { @Test public void testApplyWithoutSeries() { - RpcEnhancementProperties properties = new RpcEnhancementProperties(); + RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties(); // Mock Condition properties.getStatuses().clear(); properties.getSeries().clear(); @@ -89,7 +89,7 @@ public class AbstractPolarisReporterAdapterTest { @Test public void testApplyWithSeries() { - RpcEnhancementProperties properties = new RpcEnhancementProperties(); + RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties(); // Mock Condition properties.getStatuses().clear(); properties.getSeries().clear(); @@ -109,7 +109,7 @@ public class AbstractPolarisReporterAdapterTest { */ public static class SimplePolarisReporterAdapter extends AbstractPolarisReporterAdapter { - public SimplePolarisReporterAdapter(RpcEnhancementProperties properties) { + public SimplePolarisReporterAdapter(RpcEnhancementReporterProperties properties) { super(properties); } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java new file mode 100644 index 000000000..48c61233b --- /dev/null +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java @@ -0,0 +1,64 @@ +/* + * 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.rpc.enhancement.config; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.HttpStatus.MOVED_PERMANENTLY; +import static org.springframework.http.HttpStatus.MULTIPLE_CHOICES; +import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR; +import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; + +/** + * Test For {@link RpcEnhancementReporterProperties}. + * + * @author Haotian Zhang + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RpcEnhancementReporterPropertiesTest.TestApplication.class) +@ActiveProfiles("test") +public class RpcEnhancementReporterPropertiesTest { + + @Autowired + private RpcEnhancementReporterProperties rpcEnhancementReporterProperties; + + @Test + public void testDefaultInitialization() { + assertThat(rpcEnhancementReporterProperties).isNotNull(); + assertThat(rpcEnhancementReporterProperties.isIgnoreInternalServerError()).isFalse(); + assertThat(rpcEnhancementReporterProperties.getSeries()).isNotEmpty(); + assertThat(rpcEnhancementReporterProperties.getSeries().get(0)).isEqualTo(CLIENT_ERROR); + assertThat(rpcEnhancementReporterProperties.getSeries().get(1)).isEqualTo(SERVER_ERROR); + assertThat(rpcEnhancementReporterProperties.getStatuses()).isNotEmpty(); + assertThat(rpcEnhancementReporterProperties.getStatuses().get(0)).isEqualTo(MULTIPLE_CHOICES); + assertThat(rpcEnhancementReporterProperties.getStatuses().get(1)).isEqualTo(MOVED_PERMANENTLY); + } + + @SpringBootApplication + protected static class TestApplication { + + } +} diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java index 631155b8f..7d54b6b8c 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java @@ -22,7 +22,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; -import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties; import com.tencent.polaris.api.core.ConsumerAPI; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,7 +49,7 @@ public class EnhancedRestTemplateReporterTest { public void handleError() throws Exception { ConsumerAPI consumerAPI = mock(ConsumerAPI.class); EnhancedRestTemplateReporter enhancedRestTemplateReporter = - new EnhancedRestTemplateReporter(mock(RpcEnhancementProperties.class), consumerAPI, null); + new EnhancedRestTemplateReporter(mock(RpcEnhancementReporterProperties.class), consumerAPI, null); URI uri = mock(URI.class); when(uri.getPath()).thenReturn("/test"); when(uri.getHost()).thenReturn("host"); diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties b/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties index 96d94d0d0..34e566e79 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties +++ b/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties @@ -1,3 +1,8 @@ spring.cloud.polaris.stat.enabled=true spring.cloud.polaris.stat.port=20000 spring.cloud.polaris.stat.path=/xxx +spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error=false +spring.cloud.tencent.rpc-enhancement.reporter.series[0]=CLIENT_ERROR +spring.cloud.tencent.rpc-enhancement.reporter.series[1]=SERVER_ERROR +spring.cloud.tencent.rpc-enhancement.reporter.statuses[0]=MULTIPLE_CHOICES +spring.cloud.tencent.rpc-enhancement.reporter.statuses[1]=MOVED_PERMANENTLY