diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml
index c0ef90771..cc452e861 100644
--- a/.github/workflows/codecov.yml
+++ b/.github/workflows/codecov.yml
@@ -5,12 +5,17 @@ name: Codecov
on:
push:
- branches: [ main ]
+ branches:
+ - main
+ - 2021.0
+ - 2020.0
+ - greenwich
pull_request:
- branches: [ main ]
-
-permissions:
- contents: write
+ branches:
+ - main
+ - 2021.0
+ - 2020.0
+ - greenwich
jobs:
build:
diff --git a/.github/workflows/junit_test.yml b/.github/workflows/junit_test.yml
index 57cfae035..165255247 100644
--- a/.github/workflows/junit_test.yml
+++ b/.github/workflows/junit_test.yml
@@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
java: [ 8, 11, 17 ]
- os: [ 'windows-latest', 'macos-latest', 'ubuntu-latest' ]
+ os: [ 'windows-latest', 'ubuntu-latest' ]
runs-on: ${{ matrix.os }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 51fd829ce..248abe7d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,8 +21,12 @@
- [Fix the current limiting effect is that other requests cannot be processed when queuing at a constant speed](https://github.com/Tencent/spring-cloud-tencent/pull/316)
- [Fix config file format misspell](https://github.com/Tencent/spring-cloud-tencent/pull/319)
- [UT: improve test coverage for load balancer unit test](https://github.com/Tencent/spring-cloud-tencent/pull/325)
-- [Feature: Optimize polaris load balancer test code format](https://github.com/Tencent/spring-cloud-tencent/pull/333)
+- [optimize polaris load balancer test code format](https://github.com/Tencent/spring-cloud-tencent/pull/333)
- [feat:Add GitHub action of codecov.yml.](https://github.com/Tencent/spring-cloud-tencent/pull/328)
- [Feature: add spring cloud tencent logo](https://github.com/Tencent/spring-cloud-tencent/pull/329)
- [Feature: Optimize static metadata manager](https://github.com/Tencent/spring-cloud-tencent/pull/327)
- [Feature: optimization refreshScope](https://github.com/Tencent/spring-cloud-tencent/pull/326)
+- [test:update junit of metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/340)
+- [Optimize code style & unit test case](https://github.com/Tencent/spring-cloud-tencent/pull/336)
+- [rm code: Condition 'null != interceptors' is always 'true' ](https://github.com/Tencent/spring-cloud-tencent/pull/342)
+- [fix: shutdown thread pool before the container closes](https://github.com/Tencent/spring-cloud-tencent/pull/353)
diff --git a/doc/logo/1280x640-transparent.png b/doc/logo/1280x640-transparent.png
new file mode 100644
index 000000000..9e722651c
Binary files /dev/null and b/doc/logo/1280x640-transparent.png differ
diff --git a/doc/logo/1280x640-transparent.svg b/doc/logo/1280x640-transparent.svg
new file mode 100644
index 000000000..ed57761db
--- /dev/null
+++ b/doc/logo/1280x640-transparent.svg
@@ -0,0 +1,17 @@
+
+
\ No newline at end of file
diff --git a/doc/logo/1280x640-white.png b/doc/logo/1280x640-white.png
new file mode 100644
index 000000000..21181cfda
Binary files /dev/null and b/doc/logo/1280x640-white.png differ
diff --git a/doc/logo/1280x640-white.svg b/doc/logo/1280x640-white.svg
new file mode 100644
index 000000000..e09dba3f9
--- /dev/null
+++ b/doc/logo/1280x640-white.svg
@@ -0,0 +1,17 @@
+
+
\ No newline at end of file
diff --git a/doc/logo/640x640-transparent.png b/doc/logo/640x640-transparent.png
new file mode 100644
index 000000000..67e0c3f4f
Binary files /dev/null and b/doc/logo/640x640-transparent.png differ
diff --git a/doc/logo/640x640-transparent.svg b/doc/logo/640x640-transparent.svg
new file mode 100644
index 000000000..bb45e2cd1
--- /dev/null
+++ b/doc/logo/640x640-transparent.svg
@@ -0,0 +1,17 @@
+
+
\ No newline at end of file
diff --git a/doc/logo/640x640-white.png b/doc/logo/640x640-white.png
new file mode 100644
index 000000000..b4cfaab59
Binary files /dev/null and b/doc/logo/640x640-white.png differ
diff --git a/doc/logo/640x640-white.svg b/doc/logo/640x640-white.svg
new file mode 100644
index 000000000..f5870166a
--- /dev/null
+++ b/doc/logo/640x640-white.svg
@@ -0,0 +1,17 @@
+
+
\ No newline at end of file
diff --git a/doc/logo/logo.png b/doc/logo/logo.png
deleted file mode 100644
index 56598b4fc..000000000
Binary files a/doc/logo/logo.png and /dev/null differ
diff --git a/doc/logo/rectangle-transparent.png b/doc/logo/rectangle-transparent.png
new file mode 100644
index 000000000..772332df2
Binary files /dev/null and b/doc/logo/rectangle-transparent.png differ
diff --git a/doc/logo/rectangle-transparent.svg b/doc/logo/rectangle-transparent.svg
new file mode 100644
index 000000000..c4c34ccc3
--- /dev/null
+++ b/doc/logo/rectangle-transparent.svg
@@ -0,0 +1,15 @@
+
+
\ No newline at end of file
diff --git a/doc/logo/rectangle-white.png b/doc/logo/rectangle-white.png
new file mode 100644
index 000000000..46a1c77d9
Binary files /dev/null and b/doc/logo/rectangle-white.png differ
diff --git a/doc/logo/rectangle-white.svg b/doc/logo/rectangle-white.svg
new file mode 100644
index 000000000..5bc74ffb7
--- /dev/null
+++ b/doc/logo/rectangle-white.svg
@@ -0,0 +1,16 @@
+
+
\ No newline at end of file
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
index 589875875..9f7514ae6 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
@@ -168,8 +168,7 @@ public class MetadataTransferAutoConfiguration {
List interceptors = restTemplate
.getInterceptors();
// Avoid setting interceptor repeatedly.
- if (null != interceptors && !interceptors
- .contains(encodeTransferMedataRestTemplateInterceptor)) {
+ if (!interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
interceptors.add(encodeTransferMedataRestTemplateInterceptor);
restTemplate.setInterceptors(interceptors);
}
@@ -207,10 +206,8 @@ public class MetadataTransferAutoConfiguration {
List interceptors = restTemplate
.getInterceptors();
// Avoid setting interceptor repeatedly.
- if (null != interceptors && !interceptors
- .contains(encodeTransferMedataRestTemplateInterceptor)) {
- interceptors
- .add(this.encodeTransferMedataRestTemplateInterceptor);
+ if (!interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
+ interceptors.add(this.encodeTransferMedataRestTemplateInterceptor);
restTemplate.setInterceptors(interceptors);
}
}
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolver.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolver.java
index b8645efb2..01be55f2b 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolver.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolver.java
@@ -32,8 +32,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.server.ServerWebExchange;
/**
- * resolve custom transitive metadata from request.
- *@author lepdou 2022-05-20
+ * Resolve custom transitive metadata from request.
+ * @author lepdou 2022-05-20
*/
public class CustomTransitiveMetadataResolver {
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/CustomTransitiveMetadataResolverTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolverTest.java
similarity index 94%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/CustomTransitiveMetadataResolverTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolverTest.java
index f3fbfc4e0..9dc83bd51 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/CustomTransitiveMetadataResolverTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/CustomTransitiveMetadataResolverTest.java
@@ -13,14 +13,12 @@
* 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.metadata;
+package com.tencent.cloud.metadata.core;
import java.util.Map;
-import com.tencent.cloud.metadata.core.CustomTransitiveMetadataResolver;
import org.assertj.core.api.Assertions;
import org.junit.Test;
@@ -29,6 +27,8 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
/**
+ * Test for {@link CustomTransitiveMetadataResolver}.
+ *
* @author quan
*/
public class CustomTransitiveMetadataResolverTest {
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataReactiveFilterTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataReactiveFilterTest.java
similarity index 96%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataReactiveFilterTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataReactiveFilterTest.java
index 48412d443..8edd3400c 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataReactiveFilterTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataReactiveFilterTest.java
@@ -13,14 +13,12 @@
* 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.metadata;
+package com.tencent.cloud.metadata.core;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
-import com.tencent.cloud.metadata.core.DecodeTransferMetadataReactiveFilter;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@@ -38,6 +36,8 @@ import org.springframework.web.server.WebFilterChain;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK;
/**
+ * Test for {@link DecodeTransferMetadataReactiveFilter}.
+ *
* @author Haotian Zhang
*/
@RunWith(SpringRunner.class)
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataServletFilterTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataServletFilterTest.java
similarity index 96%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataServletFilterTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataServletFilterTest.java
index 4f452ffb9..fca418b59 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/DecodeTransferMetadataServletFilterTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferMetadataServletFilterTest.java
@@ -13,10 +13,9 @@
* 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.metadata;
+package com.tencent.cloud.metadata.core;
import java.io.IOException;
@@ -25,7 +24,6 @@ import javax.servlet.ServletException;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
-import com.tencent.cloud.metadata.core.DecodeTransferMetadataServletFilter;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +38,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
+ * Test for {@link DecodeTransferMetadataServletFilter}.
+ *
* @author Haotian Zhang
*/
@RunWith(SpringRunner.class)
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataFeignInterceptorTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataFeignInterceptorTest.java
similarity index 96%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataFeignInterceptorTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataFeignInterceptorTest.java
index 9d8c7ea3f..c42629e0c 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataFeignInterceptorTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataFeignInterceptorTest.java
@@ -13,10 +13,9 @@
* 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.metadata.core.intercepter;
+package com.tencent.cloud.metadata.core;
import java.io.UnsupportedEncodingException;
@@ -24,7 +23,6 @@ import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
-import com.tencent.cloud.metadata.core.EncodeTransferMedataFeignInterceptor;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.assertj.core.api.Assertions;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataRestTemplateInterceptorTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataRestTemplateInterceptorTest.java
similarity index 95%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataRestTemplateInterceptorTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataRestTemplateInterceptorTest.java
index 10626e5a6..b61c42ed2 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/EncodeTransferMedataRestTemplateInterceptorTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataRestTemplateInterceptorTest.java
@@ -13,17 +13,15 @@
* 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.metadata.core.intercepter;
+package com.tencent.cloud.metadata.core;
import java.io.UnsupportedEncodingException;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
-import com.tencent.cloud.metadata.core.EncodeTransferMedataRestTemplateInterceptor;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMedataScgFilterTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataScgFilterTest.java
similarity index 82%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMedataScgFilterTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataScgFilterTest.java
index bc8a6277e..f6cc2fdcd 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMedataScgFilterTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMedataScgFilterTest.java
@@ -13,10 +13,9 @@
* 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.metadata.core.filter;
+package com.tencent.cloud.metadata.core;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@@ -25,9 +24,7 @@ import java.util.Map;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.util.JacksonUtils;
-import com.tencent.cloud.metadata.core.EncodeTransferMedataScgFilter;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -44,12 +41,14 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
+ * Test for {@link EncodeTransferMedataScgFilter}.
+ *
* @author quan
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT,
classes = EncodeTransferMedataScgFilterTest.TestApplication.class,
- properties = { "spring.config.location = classpath:application-test.yml", "spring.main.web-application-type = reactive" })
+ properties = {"spring.config.location = classpath:application-test.yml", "spring.main.web-application-type = reactive"})
public class EncodeTransferMedataScgFilterTest {
@Autowired
@@ -61,14 +60,20 @@ public class EncodeTransferMedataScgFilterTest {
@Test
public void testTransitiveMetadataFromApplicationConfig() throws UnsupportedEncodingException {
EncodeTransferMedataScgFilter filter = applicationContext.getBean(EncodeTransferMedataScgFilter.class);
+
+ // Mock Server Http Request
MockServerHttpRequest.BaseBuilder> builder = MockServerHttpRequest.get("");
MockServerWebExchange exchange = MockServerWebExchange.from(builder);
filter.filter(exchange, chain);
- String metadataStr = exchange.getRequest().getHeaders().getFirst(MetadataConstant.HeaderName.CUSTOM_METADATA);
- String decode = URLDecoder.decode(metadataStr, StandardCharsets.UTF_8.name());
+
+ // Check metadata str
+ String metadata = exchange.getRequest().getHeaders().getFirst(MetadataConstant.HeaderName.CUSTOM_METADATA);
+ Assertions.assertThat(metadata).isNotNull();
+
+ String decode = URLDecoder.decode(metadata, StandardCharsets.UTF_8.name());
Map transitiveMap = JacksonUtils.deserialize2Map(decode);
Assertions.assertThat(transitiveMap.size()).isEqualTo(1);
- Assert.assertEquals(transitiveMap.get("b"), "2");
+ Assertions.assertThat(transitiveMap.get("b")).isEqualTo("2");
}
@SpringBootApplication
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMetadataZuulFilterTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMetadataZuulFilterTest.java
similarity index 82%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMetadataZuulFilterTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMetadataZuulFilterTest.java
index 7cb159e84..adc3e1f7e 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/EncodeTransferMetadataZuulFilterTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/EncodeTransferMetadataZuulFilterTest.java
@@ -16,7 +16,7 @@
*
*/
-package com.tencent.cloud.metadata.core.filter;
+package com.tencent.cloud.metadata.core;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@@ -26,9 +26,7 @@ import java.util.Map;
import com.netflix.zuul.context.RequestContext;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.util.JacksonUtils;
-import com.tencent.cloud.metadata.core.EncodeTransferMetadataZuulFilter;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,19 +41,21 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
+ * Test for {@link EncodeTransferMetadataZuulFilter}.
+ *
* @author quan
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT,
classes = EncodeTransferMetadataZuulFilterTest.TestApplication.class,
- properties = { "spring.config.location = classpath:application-test.yml", "spring.main.web-application-type = reactive" })
+ properties = {"spring.config.location = classpath:application-test.yml", "spring.main.web-application-type = reactive"})
public class EncodeTransferMetadataZuulFilterTest {
@Autowired
private ApplicationContext applicationContext;
- private MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
+ private final MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
@Before
public void init() {
@@ -70,11 +70,13 @@ public class EncodeTransferMetadataZuulFilterTest {
filter.run();
final RequestContext ctx = RequestContext.getCurrentContext();
Map zuulRequestHeaders = ctx.getZuulRequestHeaders();
- String metaData = zuulRequestHeaders.get(MetadataConstant.HeaderName.CUSTOM_METADATA.toLowerCase());
- String decode = URLDecoder.decode(metaData, StandardCharsets.UTF_8.name());
+ String metadata = zuulRequestHeaders.get(MetadataConstant.HeaderName.CUSTOM_METADATA.toLowerCase());
+ Assertions.assertThat(metadata).isNotNull();
+
+ String decode = URLDecoder.decode(metadata, StandardCharsets.UTF_8.name());
Map transitiveMap = JacksonUtils.deserialize2Map(decode);
Assertions.assertThat(transitiveMap.size()).isEqualTo(1);
- Assert.assertEquals(transitiveMap.get("b"), "2");
+ Assertions.assertThat(transitiveMap.get("b")).isEqualTo("2");
}
@SpringBootApplication
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
index 5c8c0d957..80bb8a22a 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
@@ -102,6 +102,12 @@
test
+
+ org.springframework.boot
+ spring-boot-starter-web
+ test
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisRestTemplateAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisRestTemplateAutoConfiguration.java
index d537de32e..a81f1344b 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisRestTemplateAutoConfiguration.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisRestTemplateAutoConfiguration.java
@@ -32,9 +32,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
- * @author : wh
- * @date : 2022/6/21 21:34
- * @description: Auto configuration PolarisRestTemplateAutoConfiguration
+ * Auto configuration PolarisRestTemplateAutoConfiguration .
+ *
+ * @author wh 2022/6/21
*/
@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled",
havingValue = "true", matchIfMissing = true)
@@ -44,13 +44,16 @@ public class PolarisRestTemplateAutoConfiguration {
@Bean
@ConditionalOnBean(RestTemplate.class)
- public PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler(ConsumerAPI consumerAPI, @Autowired(required = false) PolarisResponseErrorHandler polarisResponseErrorHandler) {
+ public PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler(
+ ConsumerAPI consumerAPI, @Autowired(required = false) PolarisResponseErrorHandler polarisResponseErrorHandler) {
return new PolarisRestTemplateResponseErrorHandler(consumerAPI, polarisResponseErrorHandler);
}
@Bean
@ConditionalOnBean(RestTemplate.class)
- public PolarisRestTemplateModifier polarisRestTemplateBeanPostProcessor(PolarisRestTemplateResponseErrorHandler restTemplateResponseErrorHandler) {
+ public PolarisRestTemplateModifier polarisRestTemplateBeanPostProcessor(
+ PolarisRestTemplateResponseErrorHandler restTemplateResponseErrorHandler) {
return new PolarisRestTemplateModifier(restTemplateResponseErrorHandler);
}
+
}
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisResponseErrorHandler.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisResponseErrorHandler.java
index 5ddd1e6aa..3c690b1cc 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisResponseErrorHandler.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisResponseErrorHandler.java
@@ -20,9 +20,9 @@ package com.tencent.cloud.polaris.circuitbreaker.resttemplate;
import org.springframework.web.client.ResponseErrorHandler;
/**
- * @author : wh
- * @date : 2022/6/21 19:12
- * @description: errorHandler {@link ResponseErrorHandler}
+ * Polaris Response Error Handler Definition Of {@link ResponseErrorHandler}.
+ *
+ * @author wh 2022/6/21
*/
public interface PolarisResponseErrorHandler extends ResponseErrorHandler {
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateModifier.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateModifier.java
index bd43913f4..aa6eb3cbc 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateModifier.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateModifier.java
@@ -28,10 +28,10 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
/**
- * @author : wh
- * @date : 2022/6/21 21:20
- * @description: auto configuration RestTemplate Find the RestTemplate bean annotated with {@link LoadBalanced} and replace {@link org.springframework.web.client.ResponseErrorHandler}
- * with {@link PolarisRestTemplateResponseErrorHandler}
+ * Auto configuration RestTemplate, Find the RestTemplate bean annotated with {@link LoadBalanced},
+ * then replace {@link org.springframework.web.client.ResponseErrorHandler} with {@link PolarisRestTemplateResponseErrorHandler} .
+ *
+ * @author wh 2022/6/21
*/
public class PolarisRestTemplateModifier implements ApplicationContextAware, SmartInitializingSingleton {
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandler.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandler.java
index e6e003d90..8a7dc16ab 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandler.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandler.java
@@ -29,24 +29,25 @@ import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.pojo.RetStatus;
import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.rpc.ServiceCallResult;
-import com.tencent.polaris.api.utils.StringUtils;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.lang.NonNull;
import org.springframework.web.client.ResponseErrorHandler;
/**
- * @author : wh
- * @date : 2022/6/21 17:25
- * @description: Extend ResponseErrorHandler to get request information
+ * Extend ResponseErrorHandler to get request information.
+ *
+ * @author wh 2022/6/21
*/
public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHandler {
private static final Logger LOG = LoggerFactory.getLogger(PolarisRestTemplateResponseErrorHandler.class);
- private static final String FileName = "connection";
+ private static final String FIELD_NAME = "connection";
private final ConsumerAPI consumerAPI;
@@ -59,12 +60,12 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
}
@Override
- public boolean hasError(ClientHttpResponse response) {
+ public boolean hasError(@NonNull ClientHttpResponse response) {
return true;
}
@Override
- public void handleError(ClientHttpResponse response) throws IOException {
+ public void handleError(@NonNull ClientHttpResponse response) throws IOException {
if (Objects.nonNull(polarisResponseErrorHandler)) {
if (polarisResponseErrorHandler.hasError(response)) {
polarisResponseErrorHandler.handleError(response);
@@ -72,12 +73,22 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
}
}
- public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
- ServiceCallResult resultRequest = null;
+ @Override
+ public void handleError(@NonNull URI url, @NonNull HttpMethod method, @NonNull ClientHttpResponse response) throws IOException {
+ ServiceCallResult resultRequest = createServiceCallResult(url);
try {
- resultRequest = builderServiceCallResult(url, response);
+ HttpURLConnection connection = (HttpURLConnection) ReflectionUtils.getFieldValue(response, FIELD_NAME);
+ if (connection != null) {
+ URL realURL = connection.getURL();
+ resultRequest.setHost(realURL.getHost());
+ resultRequest.setPort(realURL.getPort());
+ }
+
+ if (response.getStatusCode().value() > 500) {
+ resultRequest.setRetStatus(RetStatus.RetFail);
+ }
}
- catch (IOException e) {
+ catch (Exception e) {
LOG.error("Will report response of {} url {}", response, url, e);
throw e;
}
@@ -86,7 +97,7 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
}
}
- private ServiceCallResult builderServiceCallResult(URI uri, ClientHttpResponse response) throws IOException {
+ private ServiceCallResult createServiceCallResult(URI uri) {
ServiceCallResult resultRequest = new ServiceCallResult();
String serviceName = uri.getHost();
resultRequest.setService(serviceName);
@@ -98,13 +109,6 @@ public class PolarisRestTemplateResponseErrorHandler implements ResponseErrorHan
if (StringUtils.isNotBlank(sourceNamespace) && StringUtils.isNotBlank(sourceService)) {
resultRequest.setCallerService(new ServiceKey(sourceNamespace, sourceService));
}
- HttpURLConnection connection = (HttpURLConnection) ReflectionUtils.getFieldValue(response, FileName);
- URL url = connection.getURL();
- resultRequest.setHost(url.getHost());
- resultRequest.setPort(url.getPort());
- if (response.getStatusCode().value() > 500) {
- resultRequest.setRetStatus(RetStatus.RetFail);
- }
return resultRequest;
}
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateAutoConfigurationTest.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateAutoConfigurationTest.java
new file mode 100644
index 000000000..a3dc9999c
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateAutoConfigurationTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.circuitbreaker;
+
+import com.tencent.cloud.polaris.circuitbreaker.config.PolarisRestTemplateAutoConfiguration;
+import com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisRestTemplateModifier;
+import com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisRestTemplateResponseErrorHandler;
+import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
+import org.junit.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test For {@link PolarisRestTemplateAutoConfiguration} .
+ *
+ * @author Palmer Xu 2022-06-28
+ */
+public class PolarisRestTemplateAutoConfigurationTest {
+
+ private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(
+ PolarisRestTemplateAutoConfigurationTester.class,
+ PolarisContextAutoConfiguration.class,
+ PolarisRestTemplateAutoConfiguration.class))
+ .withPropertyValues("spring.cloud.polaris.circuitbreaker.enabled=true");
+
+ @Test
+ public void testInitialization() {
+ this.contextRunner
+ .run(context -> {
+ assertThat(context).hasSingleBean(PolarisRestTemplateModifier.class);
+ assertThat(context).hasSingleBean(PolarisRestTemplateResponseErrorHandler.class);
+ });
+ }
+
+ @Configuration
+ @EnableAutoConfiguration
+ @AutoConfigureBefore(PolarisRestTemplateAutoConfiguration.class)
+ static class PolarisRestTemplateAutoConfigurationTester {
+
+ @Bean
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+ }
+
+}
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateResponseErrorHandlerTest.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandlerTest.java
similarity index 90%
rename from spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateResponseErrorHandlerTest.java
rename to spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandlerTest.java
index 5daf30bc6..6cb630e37 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisRestTemplateResponseErrorHandlerTest.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/PolarisRestTemplateResponseErrorHandlerTest.java
@@ -15,14 +15,13 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.polaris.circuitbreaker;
+package com.tencent.cloud.polaris.circuitbreaker.resttemplate;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
-import com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisRestTemplateResponseErrorHandler;
import com.tencent.polaris.api.core.ConsumerAPI;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,9 +35,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
- * @author : wh
- * @date : 2022/6/22 09:00
- * @description: Test for {@link PolarisRestTemplateResponseErrorHandler}.
+ * Test For {@link PolarisRestTemplateResponseErrorHandler}.
+ *
+ * @author wh 2022/6/22
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolarisRestTemplateResponseErrorHandlerTest.TestApplication.class,
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/SimpleClientHttpResponseTest.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/SimpleClientHttpResponseTest.java
similarity index 93%
rename from spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/SimpleClientHttpResponseTest.java
rename to spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/SimpleClientHttpResponseTest.java
index ed76da17b..871f39caa 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/SimpleClientHttpResponseTest.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/resttemplate/SimpleClientHttpResponseTest.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.polaris.circuitbreaker;
+package com.tencent.cloud.polaris.circuitbreaker.resttemplate;
import java.io.IOException;
import java.io.InputStream;
@@ -29,9 +29,9 @@ import org.springframework.util.StringUtils;
/**
- * @author : wh
- * @date : 2022/6/22 09:00
- * @description: mock {@link org.springframework.http.client.SimpleClientHttpResponse}
+ * Mock Test for {@link AbstractClientHttpResponse}.
+ *
+ * @author wh 2022/6/22
*/
public class SimpleClientHttpResponseTest extends AbstractClientHttpResponse {
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/refresh/PolarisRefreshApplicationReadyEventListener.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/refresh/PolarisRefreshApplicationReadyEventListener.java
index 9591cb389..53292e7cf 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/refresh/PolarisRefreshApplicationReadyEventListener.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/refresh/PolarisRefreshApplicationReadyEventListener.java
@@ -25,6 +25,7 @@ import com.tencent.polaris.client.util.NamedThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.context.ApplicationEventPublisher;
@@ -38,7 +39,7 @@ import static com.tencent.cloud.polaris.discovery.refresh.PolarisServiceStatusCh
*
* @author Haotian Zhang
*/
-public class PolarisRefreshApplicationReadyEventListener implements ApplicationListener, ApplicationEventPublisherAware {
+public class PolarisRefreshApplicationReadyEventListener implements ApplicationListener, ApplicationEventPublisherAware, DisposableBean {
private static final Logger LOG = LoggerFactory.getLogger(PolarisRefreshApplicationReadyEventListener.class);
private static final int DELAY = 60;
@@ -83,4 +84,9 @@ public class PolarisRefreshApplicationReadyEventListener implements ApplicationL
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
+
+ @Override
+ public void destroy() throws Exception {
+ refreshExecutor.shutdown();
+ }
}