diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index e516afb42..a56dd0d4b 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -28,3 +28,4 @@ fixes #
- [ ] Will pull request to branch of 2020.0.
- [ ] Will pull request to branch of 2022.0.
+- [ ] Will pull request to branch of hoxton.
diff --git a/.licenserc.yaml b/.licenserc.yaml
index 32266c414..04f07307a 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -16,7 +16,7 @@ header:
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
paths:
- - "**/java/**"
+ - "**/tencent/**"
language:
Java:
extensions:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5133001aa..afd75ffba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,4 +7,8 @@
- [Refactoring:remove invalid @AutoConfigureAfter and @AutoConfigureBefore from discovery client automatic configuration.](https://github.com/Tencent/spring-cloud-tencent/pull/1115)
- [feat: support log path configuration parameters.](https://github.com/Tencent/spring-cloud-tencent/pull/1128)
- [refactor:optimize the order and condition matching of service registration automatic configuration.](https://github.com/Tencent/spring-cloud-tencent/pull/1129)
+- [feat: add circuit breaker actuator.](https://github.com/Tencent/spring-cloud-tencent/pull/1136)
- [feat: add metadata transfer for http header via spring.cloud.tencent.metadata.headers.](https://github.com/Tencent/spring-cloud-tencent/pull/1137)
+- [feat:support service contract reporting.](https://github.com/Tencent/spring-cloud-tencent/pull/1139)
+- [feat:add swagger exposure filters.](https://github.com/Tencent/spring-cloud-tencent/pull/1146)
+- [feat:add swagger report switch.](https://github.com/Tencent/spring-cloud-tencent/pull/1148)
diff --git a/README-zh.md b/README-zh.md
index 548c7ff73..b4447195a 100644
--- a/README-zh.md
+++ b/README-zh.md
@@ -78,7 +78,7 @@ Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要
com.tencent.cloud
spring-cloud-tencent-dependencies
- 1.12.0-2021.0.8
+ 1.12.1-2021.0.8
pom
import
diff --git a/README.md b/README.md
index 17092db54..2cb1f52e7 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,7 @@ For example:
com.tencent.cloud
spring-cloud-tencent-dependencies
- 1.12.0-2021.0.8
+ 1.12.1-2021.0.8
pom
import
diff --git a/pom.xml b/pom.xml
index dab311801..2b46501a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,6 +47,7 @@
spring-cloud-starter-tencent-polaris-ratelimit
spring-cloud-starter-tencent-polaris-circuitbreaker
spring-cloud-starter-tencent-polaris-router
+ spring-cloud-starter-tencent-polaris-contract
spring-cloud-tencent-plugin-starters
spring-cloud-tencent-dependencies
spring-cloud-starter-tencent-all
@@ -91,7 +92,7 @@
1.13.0-2021.0.8-SNAPSHOT
- 5.3.29
+ 5.3.25
2.6.15
diff --git a/spring-cloud-starter-tencent-all/pom.xml b/spring-cloud-starter-tencent-all/pom.xml
index 1c45b11d7..fc6470e9a 100644
--- a/spring-cloud-starter-tencent-all/pom.xml
+++ b/spring-cloud-starter-tencent-all/pom.xml
@@ -45,6 +45,11 @@
spring-cloud-starter-tencent-metadata-transfer
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-contract
+
+
org.springframework.cloud
@@ -88,12 +93,19 @@
true
-
-
- META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports
+
+
+
+ META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports
+
-
- META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+
+
+ META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
index 58a68a422..230e50a82 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
@@ -96,6 +96,18 @@
+
+ org.springframework.boot
+ spring-boot-actuator
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-actuator-autoconfigure
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/endpoint/PolarisCircuitBreakerEndpoint.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/endpoint/PolarisCircuitBreakerEndpoint.java
new file mode 100644
index 000000000..b2ff0eeff
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/endpoint/PolarisCircuitBreakerEndpoint.java
@@ -0,0 +1,86 @@
+/*
+ * 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.endpoint;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.util.JsonFormat;
+import com.tencent.cloud.common.metadata.MetadataContext;
+import com.tencent.cloud.common.util.JacksonUtils;
+import com.tencent.cloud.polaris.context.ServiceRuleManager;
+import com.tencent.polaris.specification.api.v1.fault.tolerance.CircuitBreakerProto;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+
+/**
+ * Endpoint of polaris circuit breaker, include circuit breaker rules.
+ *
+ * @author wenxuan70
+ */
+@Endpoint(id = "polaris-circuit-breaker")
+public class PolarisCircuitBreakerEndpoint {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PolarisCircuitBreakerEndpoint.class);
+
+ private final ServiceRuleManager serviceRuleManager;
+
+ public PolarisCircuitBreakerEndpoint(ServiceRuleManager serviceRuleManager) {
+ this.serviceRuleManager = serviceRuleManager;
+ }
+
+ @ReadOperation
+ public Map circuitBreaker() {
+ CircuitBreakerProto.CircuitBreaker circuitBreaker = serviceRuleManager.getServiceCircuitBreakerRule(
+ MetadataContext.LOCAL_NAMESPACE,
+ MetadataContext.LOCAL_SERVICE
+ );
+
+ Map polarisCircuitBreakerInfo = new HashMap<>();
+
+ polarisCircuitBreakerInfo.put("namespace", MetadataContext.LOCAL_NAMESPACE);
+ polarisCircuitBreakerInfo.put("service", MetadataContext.LOCAL_SERVICE);
+ polarisCircuitBreakerInfo.put("circuitBreakerRules", parseCircuitBreakerRule(circuitBreaker));
+
+ return polarisCircuitBreakerInfo;
+ }
+
+ private List
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-contract
+
+
com.tencent.cloud
spring-cloud-starter-tencent-discovery-adapter-plugin
- ${revision}
diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml
index 6cce1e8c6..80852a9dd 100644
--- a/spring-cloud-tencent-dependencies/pom.xml
+++ b/spring-cloud-tencent-dependencies/pom.xml
@@ -76,6 +76,8 @@
1.15.0-SNAPSHOT
32.0.1-jre
1.2.11
+ 3.0.0
+ 1.5.24
4.5.1
1.12.10
3.21.7
@@ -154,6 +156,12 @@
${revision}
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-contract
+ ${revision}
+
+
com.tencent.cloud
spring-cloud-starter-tencent-all
@@ -212,6 +220,24 @@
${logback.version}
+
+ io.springfox
+ springfox-boot-starter
+ ${springfox.swagger2.version}
+
+
+
+ io.swagger
+ swagger-models
+ ${io.swagger.version}
+
+
+
+ io.swagger
+ swagger-annotations
+ ${io.swagger.version}
+
+
com.google.protobuf
protobuf-java
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml
index 9b974df4c..312b45c1a 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/pom.xml
@@ -19,10 +19,10 @@
spring-boot-starter-webflux
-
-
-
-
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-contract
+
com.tencent.cloud
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
index ec34c0c35..1f3a5b9e5 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
@@ -11,6 +11,8 @@ spring:
discovery:
enabled: true
register: true
+ contract:
+ exposure: true
stat:
enabled: true
port: 28082
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
index aadcea9ee..69e5c1e64 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
@@ -28,6 +28,11 @@
spring-cloud-starter-tencent-polaris-discovery
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-contract
+
+
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/java/com/tencent/cloud/polaris/discovery/service/caller/DiscoveryCallerController.java b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/java/com/tencent/cloud/polaris/discovery/service/caller/DiscoveryCallerController.java
index f2ecaf5e4..166441cd6 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/java/com/tencent/cloud/polaris/discovery/service/caller/DiscoveryCallerController.java
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/java/com/tencent/cloud/polaris/discovery/service/caller/DiscoveryCallerController.java
@@ -45,7 +45,7 @@ public class DiscoveryCallerController {
* @param value2 value 2
* @return sum
*/
- @GetMapping("/feign")
+ @RequestMapping("/feign")
public int feign(@RequestParam int value1, @RequestParam int value2) {
return discoveryCalleeService.sum(value1, value2);
}
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
index 71f388051..f75a5c4a6 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
@@ -22,6 +22,10 @@ spring:
heartbeat:
enabled: true
health-check-url: /discovery/service/caller/healthCheck
+ contract:
+ exposure: true
+ report:
+ enabled: true
stat:
enabled: true
port: 28081
diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ServiceRuleManager.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ServiceRuleManager.java
index 128899491..826d4fbe2 100644
--- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ServiceRuleManager.java
+++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/ServiceRuleManager.java
@@ -27,13 +27,14 @@ import com.tencent.polaris.api.pojo.ServiceRule;
import com.tencent.polaris.api.rpc.GetServiceRuleRequest;
import com.tencent.polaris.api.rpc.ServiceRuleResponse;
import com.tencent.polaris.client.api.SDKContext;
+import com.tencent.polaris.specification.api.v1.fault.tolerance.CircuitBreakerProto;
import com.tencent.polaris.specification.api.v1.traffic.manage.RateLimitProto;
import com.tencent.polaris.specification.api.v1.traffic.manage.RoutingProto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * the manager of service governance rules. for example: rate limit rule, router rules.
+ * the manager of service governance rules. for example: rate limit rule, router rules, circuit breaker rules.
*
* @author lepdou 2022-05-13
*/
@@ -88,6 +89,20 @@ public class ServiceRuleManager {
return rules;
}
+ public CircuitBreakerProto.CircuitBreaker getServiceCircuitBreakerRule(String namespace, String service) {
+ LOG.debug("Get service circuit breaker rules with namespace:{} and service:{}.", namespace, service);
+
+ ServiceRule serviceRule = getServiceRule(namespace, service, ServiceEventKey.EventType.CIRCUIT_BREAKING);
+ if (serviceRule != null) {
+ Object rule = serviceRule.getRule();
+ if (rule instanceof CircuitBreakerProto.CircuitBreaker) {
+ return (CircuitBreakerProto.CircuitBreaker) rule;
+ }
+ }
+
+ return null;
+ }
+
private ServiceRule getServiceRule(String namespace, String service, ServiceEventKey.EventType eventType) {
GetServiceRuleRequest getServiceRuleRequest = new GetServiceRuleRequest();
getServiceRuleRequest.setRuleType(eventType);
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 968d8a0e2..3b52a6ade 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
@@ -30,12 +30,6 @@ import com.tencent.cloud.rpc.enhancement.filter.EnhancedServletFilter;
import com.tencent.cloud.rpc.enhancement.plugin.DefaultEnhancedPluginRunner;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginRunner;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientExceptionHook;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPostHook;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPreHook;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerExceptionHook;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPostHook;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPreHook;
import com.tencent.cloud.rpc.enhancement.plugin.reporter.ExceptionPolarisReporter;
import com.tencent.cloud.rpc.enhancement.plugin.reporter.SuccessPolarisReporter;
import com.tencent.cloud.rpc.enhancement.resttemplate.EnhancedRestTemplateInterceptor;
@@ -115,36 +109,6 @@ public class RpcEnhancementAutoConfiguration {
return new ExceptionPolarisReporter(properties, polarisSDKContextManager.getConsumerAPI());
}
- @Bean
- public AssemblyClientExceptionHook assemblyClientExceptionHook(PolarisSDKContextManager polarisSDKContextManager, InstanceTransformer instanceTransformer) {
- return new AssemblyClientExceptionHook(polarisSDKContextManager.getAssemblyAPI(), instanceTransformer);
- }
-
- @Bean
- public AssemblyClientPostHook assemblyClientPostHook(PolarisSDKContextManager polarisSDKContextManager, InstanceTransformer instanceTransformer) {
- return new AssemblyClientPostHook(polarisSDKContextManager.getAssemblyAPI(), instanceTransformer);
- }
-
- @Bean
- public AssemblyClientPreHook assemblyClientPreHook(PolarisSDKContextManager polarisSDKContextManager) {
- return new AssemblyClientPreHook(polarisSDKContextManager.getAssemblyAPI());
- }
-
- @Bean
- public AssemblyServerExceptionHook assemblyServerExceptionHook(PolarisSDKContextManager polarisSDKContextManager) {
- return new AssemblyServerExceptionHook(polarisSDKContextManager.getAssemblyAPI());
- }
-
- @Bean
- public AssemblyServerPostHook assemblyServerPostHook(PolarisSDKContextManager polarisSDKContextManager) {
- return new AssemblyServerPostHook(polarisSDKContextManager.getAssemblyAPI());
- }
-
- @Bean
- public AssemblyServerPreHook assemblyServerPreHook(PolarisSDKContextManager polarisSDKContextManager) {
- return new AssemblyServerPreHook(polarisSDKContextManager.getAssemblyAPI());
- }
-
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
protected static class RpcEnhancementServletFilterConfig {
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/PluginOrderConstant.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/PluginOrderConstant.java
index 95807dbab..6677dac0a 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/PluginOrderConstant.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/PluginOrderConstant.java
@@ -44,27 +44,5 @@ public class PluginOrderConstant {
* {@link com.tencent.cloud.polaris.circuitbreaker.reporter.ExceptionCircuitBreakerReporter}.
*/
public static final int CIRCUIT_BREAKER_REPORTER_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 2;
-
- /**
- * order for
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPreHook}
- * and
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPostHook}
- * and
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientExceptionHook}.
- */
- public static final int ASSEMBLY_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 3;
- }
-
- public static class ServerPluginOrder {
- /**
- * order for
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPreHook}
- * and
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPostHook}
- * and
- * {@link com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerExceptionHook}.
- */
- public static final int ASSEMBLY_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE + 1;
}
}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyMetadataProvider.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyMetadataProvider.java
deleted file mode 100644
index e937f244b..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyMetadataProvider.java
+++ /dev/null
@@ -1,56 +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.rpc.enhancement.plugin.assembly;
-
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.api.rpc.MetadataProvider;
-
-import org.springframework.cloud.client.ServiceInstance;
-
-/**
- * AssemblyMetadataProvider.
- *
- * @author sean yu
- */
-public class AssemblyMetadataProvider implements MetadataProvider {
-
- private final ServiceInstance serviceInstance;
-
- private final String namespace;
-
- public AssemblyMetadataProvider(ServiceInstance localServiceInstance, String namespace) {
- this.serviceInstance = localServiceInstance;
- this.namespace = namespace;
- }
-
- @Override
- public String getMetadata(String key) {
- return serviceInstance.getMetadata().get(key);
- }
-
- @Override
- public ServiceKey getLocalService() {
- return new ServiceKey(namespace, serviceInstance.getServiceId());
- }
-
- @Override
- public String getLocalIp() {
- return serviceInstance.getHost();
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyRequestContext.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyRequestContext.java
deleted file mode 100644
index dfcaa2ed8..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyRequestContext.java
+++ /dev/null
@@ -1,126 +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.rpc.enhancement.plugin.assembly;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import com.google.common.net.HttpHeaders;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedRequestContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.api.rpc.RequestContext;
-
-import org.springframework.http.HttpMethod;
-
-/**
- * AssemblyRequestContext.
- *
- * @author sean yu
- */
-public class AssemblyRequestContext implements RequestContext {
-
- private final EnhancedRequestContext requestContext;
-
- private final ServiceKey callerService;
-
- private final String callerIp;
-
- private final Map cookies;
-
- public AssemblyRequestContext(EnhancedRequestContext requestContext, ServiceKey callerService, String callerIp) {
- this.requestContext = requestContext;
- this.callerService = callerService;
- this.callerIp = callerIp;
- this.cookies = new HashMap<>();
- List allCookies =
- Optional.ofNullable(requestContext.getHttpHeaders().get(HttpHeaders.COOKIE))
- .orElse(new ArrayList<>())
- .stream()
- .flatMap(it -> Arrays.stream(it.split(";")))
- .collect(Collectors.toList());
- allCookies.forEach(cookie -> {
- String[] cookieKV = cookie.split("=");
- if (cookieKV.length == 2) {
- cookies.put(cookieKV[0], cookieKV[1]);
- }
- });
- }
-
- @Override
- public String getMethod() {
- return requestContext.getHttpMethod().name();
- }
-
- @Override
- public void setMethod(String method) {
- requestContext.setHttpMethod(HttpMethod.valueOf(method));
- }
-
- @Override
- public String getHeader(String key) {
- return requestContext.getHttpHeaders().getFirst(key);
- }
-
- @Override
- public void setHeader(String key, String value) {
- requestContext.getHttpHeaders().set(key, value);
- }
-
- @Override
- public Collection listHeaderKeys() {
- return requestContext.getHttpHeaders().keySet();
- }
-
- @Override
- public String getCookie(String key) {
- return this.cookies.get(key);
- }
-
- @Override
- public void setCookie(String key, String value) {
- this.cookies.put(key, value);
- }
-
- @Override
- public Collection listCookieKeys() {
- return this.cookies.keySet();
- }
-
- @Override
- public String getCallerIp() {
- return callerIp;
- }
-
- @Override
- public ServiceKey getCallerService() {
- return callerService;
- }
-
- @Override
- public URI getURI() {
- return requestContext.getUrl();
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyResponseContext.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyResponseContext.java
deleted file mode 100644
index 4dbfa81d7..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/AssemblyResponseContext.java
+++ /dev/null
@@ -1,87 +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.rpc.enhancement.plugin.assembly;
-
-import java.util.Collection;
-
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedResponseContext;
-import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
-import com.tencent.polaris.api.pojo.RetStatus;
-import com.tencent.polaris.api.rpc.ResponseContext;
-
-import org.springframework.lang.Nullable;
-
-/**
- * AssemblyResponseContext.
- *
- * @author sean yu
- */
-public class AssemblyResponseContext implements ResponseContext {
-
- private final EnhancedResponseContext responseContext;
-
- private final Throwable throwable;
-
- private final RetStatus retStatus;
-
- public AssemblyResponseContext(@Nullable EnhancedResponseContext responseContext, @Nullable Throwable throwable) {
- this.responseContext = responseContext;
- this.throwable = throwable;
- if (responseContext == null) {
- this.retStatus = PolarisEnhancedPluginUtils.getRetStatusFromRequest(null, null, throwable);
- }
- else {
- this.retStatus = PolarisEnhancedPluginUtils.getRetStatusFromRequest(responseContext.getHttpHeaders(), responseContext.getHttpStatus(), throwable);
- }
- }
-
- @Override
- public Object getRetCode() {
- if (responseContext == null) {
- return null;
- }
- return this.responseContext.getHttpStatus();
- }
-
- @Override
- public String getHeader(String key) {
- if (responseContext == null) {
- return null;
- }
- return this.responseContext.getHttpHeaders().getFirst(key);
- }
-
- @Override
- public Collection listHeaders() {
- if (responseContext == null) {
- return null;
- }
- return this.responseContext.getHttpHeaders().keySet();
- }
-
- @Override
- public Throwable getThrowable() {
- return this.throwable;
- }
-
- @Override
- public RetStatus getRetStatus() {
- return this.retStatus;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientExceptionHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientExceptionHook.java
deleted file mode 100644
index 398485b59..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientExceptionHook.java
+++ /dev/null
@@ -1,82 +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.rpc.enhancement.plugin.assembly.client;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
-import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.AfterRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ClientPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-/**
- * AssemblyClientExceptionHook.
- *
- * @author sean yu
- */
-public class AssemblyClientExceptionHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- private final InstanceTransformer instanceTransformer;
-
- public AssemblyClientExceptionHook(AssemblyAPI assemblyAPI, InstanceTransformer instanceTransformer) {
- this.assemblyAPI = assemblyAPI;
- this.instanceTransformer = instanceTransformer;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Client.EXCEPTION;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
-
- AfterRequest afterRequest = new AfterRequest();
- afterRequest.setCapabilities(new Capability[]{Capability.ALL});
- afterRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- afterRequest.setResponseContext(new AssemblyResponseContext(null, context.getThrowable()));
- afterRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
- afterRequest.setDelay(context.getDelay());
- afterRequest.setRouteLabels(PolarisEnhancedPluginUtils.getLabelMap(context.getRequest().getHttpHeaders()));
- // TargetService and TargetInstance only exist in client side
- afterRequest.setTargetService(new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getTargetServiceInstance().getServiceId()));
- afterRequest.setTargetInstance(instanceTransformer.transform(context.getTargetServiceInstance()));
-
- assemblyAPI.afterCallService(afterRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPostHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPostHook.java
deleted file mode 100644
index 9148a0de9..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPostHook.java
+++ /dev/null
@@ -1,83 +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.rpc.enhancement.plugin.assembly.client;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
-import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.AfterRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ClientPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-/**
- * AssemblyClientPostHook.
- *
- * @author sean yu
- */
-public class AssemblyClientPostHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- private final InstanceTransformer instanceTransformer;
-
- public AssemblyClientPostHook(AssemblyAPI assemblyAPI, InstanceTransformer instanceTransformer) {
- this.assemblyAPI = assemblyAPI;
- this.instanceTransformer = instanceTransformer;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Client.POST;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
-
- AfterRequest afterRequest = new AfterRequest();
- afterRequest.setCapabilities(new Capability[]{Capability.ALL});
- afterRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- afterRequest.setResponseContext(new AssemblyResponseContext(context.getResponse(), null));
- afterRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
- afterRequest.setDelay(context.getDelay());
- afterRequest.setRouteLabels(PolarisEnhancedPluginUtils.getLabelMap(context.getRequest().getHttpHeaders()));
- // TargetService and TargetInstance only exist in client side
- afterRequest.setTargetService(new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getTargetServiceInstance().getServiceId()));
- afterRequest.setTargetInstance(instanceTransformer.transform(context.getTargetServiceInstance()));
-
- assemblyAPI.afterCallService(afterRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPreHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPreHook.java
deleted file mode 100644
index fde540277..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/client/AssemblyClientPreHook.java
+++ /dev/null
@@ -1,73 +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.rpc.enhancement.plugin.assembly.client;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.BeforeRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ClientPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-/**
- * AssemblyClientPreHook.
- *
- * @author sean yu
- */
-public class AssemblyClientPreHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- public AssemblyClientPreHook(AssemblyAPI assemblyAPI) {
- this.assemblyAPI = assemblyAPI;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Client.PRE;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
-
- BeforeRequest beforeRequest = new BeforeRequest();
- beforeRequest.setCapabilities(new Capability[]{Capability.ALL});
- beforeRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- beforeRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
- // TargetService only exist in client side
- beforeRequest.setTargetService(new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getTargetServiceInstance().getServiceId()));
-
- assemblyAPI.beforeCallService(beforeRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerExceptionHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerExceptionHook.java
deleted file mode 100644
index bde03d0d7..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerExceptionHook.java
+++ /dev/null
@@ -1,76 +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.rpc.enhancement.plugin.assembly.server;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.AfterRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ServerPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-
-/**
- * AssemblyServerExceptionHook.
- *
- * @author sean yu
- */
-public class AssemblyServerExceptionHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- public AssemblyServerExceptionHook(AssemblyAPI assemblyAPI) {
- this.assemblyAPI = assemblyAPI;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Server.EXCEPTION;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
- AfterRequest afterRequest = new AfterRequest();
- afterRequest.setCapabilities(new Capability[]{Capability.ALL});
- afterRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- afterRequest.setResponseContext(new AssemblyResponseContext(null, context.getThrowable()));
- afterRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
- afterRequest.setDelay(context.getDelay());
- afterRequest.setRouteLabels(PolarisEnhancedPluginUtils.getLabelMap(context.getRequest().getHttpHeaders()));
-
- assemblyAPI.afterProcess(afterRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPostHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPostHook.java
deleted file mode 100644
index 855994eb1..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPostHook.java
+++ /dev/null
@@ -1,75 +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.rpc.enhancement.plugin.assembly.server;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.PolarisEnhancedPluginUtils;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.AfterRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ServerPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-/**
- * AssemblyServerPostHook.
- *
- * @author sean yu
- */
-public class AssemblyServerPostHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- public AssemblyServerPostHook(AssemblyAPI assemblyAPI) {
- this.assemblyAPI = assemblyAPI;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Server.POST;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
- AfterRequest afterRequest = new AfterRequest();
- afterRequest.setCapabilities(new Capability[]{Capability.ALL});
- afterRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- afterRequest.setResponseContext(new AssemblyResponseContext(context.getResponse(), null));
- afterRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
- afterRequest.setDelay(context.getDelay());
- afterRequest.setRouteLabels(PolarisEnhancedPluginUtils.getLabelMap(context.getRequest().getHttpHeaders()));
-
- assemblyAPI.afterProcess(afterRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPreHook.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPreHook.java
deleted file mode 100644
index 5b279b80d..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/plugin/assembly/server/AssemblyServerPreHook.java
+++ /dev/null
@@ -1,70 +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.rpc.enhancement.plugin.assembly.server;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPlugin;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
-import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-import com.tencent.polaris.assembly.api.pojo.BeforeRequest;
-import com.tencent.polaris.assembly.api.pojo.Capability;
-
-import static com.tencent.cloud.rpc.enhancement.plugin.PluginOrderConstant.ServerPluginOrder.ASSEMBLY_PLUGIN_ORDER;
-
-/**
- * AssemblyServerPreHook.
- *
- * @author sean yu
- */
-public class AssemblyServerPreHook implements EnhancedPlugin {
-
- private final AssemblyAPI assemblyAPI;
-
- public AssemblyServerPreHook(AssemblyAPI assemblyAPI) {
- this.assemblyAPI = assemblyAPI;
- }
-
- @Override
- public EnhancedPluginType getType() {
- return EnhancedPluginType.Server.PRE;
- }
-
- @Override
- public void run(EnhancedPluginContext context) {
- BeforeRequest beforeRequest = new BeforeRequest();
- beforeRequest.setCapabilities(new Capability[]{Capability.ALL});
- beforeRequest.setRequestContext(new AssemblyRequestContext(
- context.getRequest(),
- new ServiceKey(MetadataContext.LOCAL_NAMESPACE, context.getLocalServiceInstance().getServiceId()),
- context.getLocalServiceInstance().getHost()
- ));
- beforeRequest.setMetadataProvider(new AssemblyMetadataProvider(context.getLocalServiceInstance(), MetadataContext.LOCAL_NAMESPACE));
-
- assemblyAPI.beforeProcess(beforeRequest);
- }
-
- @Override
- public int getOrder() {
- return ASSEMBLY_PLUGIN_ORDER;
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientExceptionHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientExceptionHookTest.java
deleted file mode 100644
index d89006ccd..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientExceptionHookTest.java
+++ /dev/null
@@ -1,146 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientExceptionHook;
-import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyClientExceptionHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyClientExceptionHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyClientExceptionHook assemblyClientExceptionHook;
- @Mock
- private AssemblyAPI assemblyAPI;
- @Mock
- private InstanceTransformer instanceTransformer;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyClientExceptionHook.getName()).isEqualTo(AssemblyClientExceptionHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyClientExceptionHook.getType()).isEqualTo(EnhancedPluginType.Client.EXCEPTION);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyClientExceptionHook.run(pluginContext);
- assemblyClientExceptionHook.getOrder();
- assemblyClientExceptionHook.getName();
- assemblyClientExceptionHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyClientExceptionHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPostHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPostHookTest.java
deleted file mode 100644
index 9aa3f0d8e..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPostHookTest.java
+++ /dev/null
@@ -1,146 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPostHook;
-import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyClientPostHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyClientPostHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyClientPostHook assemblyClientPostHook;
- @Mock
- private AssemblyAPI assemblyAPI;
- @Mock
- private InstanceTransformer instanceTransformer;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyClientPostHook.getName()).isEqualTo(AssemblyClientPostHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyClientPostHook.getType()).isEqualTo(EnhancedPluginType.Client.POST);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyClientPostHook.run(pluginContext);
- assemblyClientPostHook.getOrder();
- assemblyClientPostHook.getName();
- assemblyClientPostHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyClientPostHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPreHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPreHookTest.java
deleted file mode 100644
index f597c1026..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyClientPreHookTest.java
+++ /dev/null
@@ -1,143 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.client.AssemblyClientPreHook;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyClientPreHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyClientPreHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyClientPreHook assemblyClientPreHook;
- @Mock
- private AssemblyAPI assemblyAPI;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyClientPreHook.getName()).isEqualTo(AssemblyClientPreHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyClientPreHook.getType()).isEqualTo(EnhancedPluginType.Client.PRE);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyClientPreHook.run(pluginContext);
- assemblyClientPreHook.getOrder();
- assemblyClientPreHook.getName();
- assemblyClientPreHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyClientPreHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyMetadataProviderTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyMetadataProviderTest.java
deleted file mode 100644
index 8a216977e..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyMetadataProviderTest.java
+++ /dev/null
@@ -1,57 +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.rpc.enhancement.plugin;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyMetadataProvider;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.ServiceInstance;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.doReturn;
-
-/**
- * AssemblyMetadataProviderTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyMetadataProviderTest {
-
- @Test
- public void testAssemblyMetadataProvider() {
- ServiceInstance serviceInstance = Mockito.mock(ServiceInstance.class);
- Map metadata = new HashMap() {{
- put("k", "v");
- }};
- doReturn(metadata).when(serviceInstance).getMetadata();
- doReturn("0.0.0.0").when(serviceInstance).getHost();
- doReturn("test").when(serviceInstance).getServiceId();
- AssemblyMetadataProvider assemblyMetadataProvider = new AssemblyMetadataProvider(serviceInstance, "test");
- assertThat(assemblyMetadataProvider.getMetadata("k")).isEqualTo("v");
- assertThat(assemblyMetadataProvider.getLocalIp()).isEqualTo("0.0.0.0");
- assertThat(assemblyMetadataProvider.getLocalService()).isEqualTo(new ServiceKey("test", "test"));
- }
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyRequestContextTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyRequestContextTest.java
deleted file mode 100644
index de8f7f17f..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyRequestContextTest.java
+++ /dev/null
@@ -1,83 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashSet;
-
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyRequestContext;
-import com.tencent.polaris.api.pojo.ServiceKey;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * AssemblyRequestContextTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyRequestContextTest {
-
- @Test
- public void testAssemblyRequestContext() {
- URI uri = URI.create("http://0.0.0.0/");
-
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.add("a", "a");
- httpHeaders.add(HttpHeaders.COOKIE, "cookies-k1=cookies-v1;cookies-k2=cookies-v2");
-
- EnhancedRequestContext enhancedRequestContext = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(uri)
- .httpHeaders(httpHeaders)
- .build();
-
- ServiceKey callerService = new ServiceKey("test", "test");
- AssemblyRequestContext assemblyRequestContext = new AssemblyRequestContext(
- enhancedRequestContext,
- callerService,
- "0.0.0.0"
- );
-
- assertThat(assemblyRequestContext.getURI()).isEqualTo(uri);
-
- assertThat(assemblyRequestContext.getHeader("a")).isEqualTo("a");
- assemblyRequestContext.setHeader("b", "b");
- assertThat(assemblyRequestContext.listHeaderKeys()).isEqualTo(new HashSet<>(Arrays.asList(HttpHeaders.COOKIE, "a", "b")));
-
- assertThat(assemblyRequestContext.getMethod()).isEqualTo(HttpMethod.GET.toString());
- assemblyRequestContext.setMethod(HttpMethod.OPTIONS.name());
- assertThat(assemblyRequestContext.getMethod()).isEqualTo(HttpMethod.OPTIONS.toString());
-
- assertThat(assemblyRequestContext.getCookie("cookies-k1")).isEqualTo("cookies-v1");
- assertThat(assemblyRequestContext.getCookie("cookies-k2")).isEqualTo("cookies-v2");
- assemblyRequestContext.setCookie("cookies-k3", "cookies-v3");
- assertThat(assemblyRequestContext.listCookieKeys()).isEqualTo(new HashSet<>(Arrays.asList("cookies-k1", "cookies-k2", "cookies-k3")));
-
- assertThat(assemblyRequestContext.getCallerService()).isEqualTo(callerService);
- assertThat(assemblyRequestContext.getCallerIp()).isEqualTo("0.0.0.0");
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyResponseContextTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyResponseContextTest.java
deleted file mode 100644
index d3c96e899..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyResponseContextTest.java
+++ /dev/null
@@ -1,101 +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.rpc.enhancement.plugin;
-
-import java.net.SocketTimeoutException;
-import java.util.Arrays;
-import java.util.HashSet;
-
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.AssemblyResponseContext;
-import com.tencent.polaris.api.pojo.RetStatus;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyResponseContextTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyResponseContextTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @Test
- public void testAssemblyResponseContext() {
-
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.add("a", "a");
-
- EnhancedResponseContext enhancedResponseContext = EnhancedResponseContext.builder()
- .httpHeaders(httpHeaders)
- .httpStatus(HttpStatus.OK.value())
- .build();
-
- AssemblyResponseContext assemblyResponseContext = new AssemblyResponseContext(enhancedResponseContext, null);
- assertThat(assemblyResponseContext.getHeader("a")).isEqualTo("a");
- assertThat(assemblyResponseContext.getRetCode()).isEqualTo(HttpStatus.OK.value());
- assertThat(assemblyResponseContext.getThrowable()).isEqualTo(null);
- assertThat(assemblyResponseContext.getRetStatus()).isEqualTo(RetStatus.RetSuccess);
- assertThat(assemblyResponseContext.listHeaders()).isEqualTo(new HashSet<>(Arrays.asList("a")));
-
- Throwable e = new SocketTimeoutException();
- assemblyResponseContext = new AssemblyResponseContext(null, e);
- assertThat(assemblyResponseContext.getHeader("a")).isEqualTo(null);
- assertThat(assemblyResponseContext.getRetCode()).isEqualTo(null);
- assertThat(assemblyResponseContext.getThrowable()).isEqualTo(e);
- assertThat(assemblyResponseContext.getRetStatus()).isEqualTo(RetStatus.RetTimeout);
- assertThat(assemblyResponseContext.listHeaders()).isEqualTo(null);
-
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerExceptionHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerExceptionHookTest.java
deleted file mode 100644
index ff04c578a..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerExceptionHookTest.java
+++ /dev/null
@@ -1,143 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerExceptionHook;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyServerExceptionHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyServerExceptionHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyServerExceptionHook assemblyServerExceptionHook;
- @Mock
- private AssemblyAPI assemblyAPI;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyServerExceptionHook.getName()).isEqualTo(AssemblyServerExceptionHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyServerExceptionHook.getType()).isEqualTo(EnhancedPluginType.Server.EXCEPTION);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyServerExceptionHook.run(pluginContext);
- assemblyServerExceptionHook.getOrder();
- assemblyServerExceptionHook.getName();
- assemblyServerExceptionHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyServerExceptionHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPostHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPostHookTest.java
deleted file mode 100644
index a15cd5796..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPostHookTest.java
+++ /dev/null
@@ -1,143 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPostHook;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyServerPostHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyServerPostHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyServerPostHook assemblyServerPostHook;
- @Mock
- private AssemblyAPI assemblyAPI;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyServerPostHook.getName()).isEqualTo(AssemblyServerPostHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyServerPostHook.getType()).isEqualTo(EnhancedPluginType.Server.POST);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyServerPostHook.run(pluginContext);
- assemblyServerPostHook.getOrder();
- assemblyServerPostHook.getName();
- assemblyServerPostHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyServerPostHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPreHookTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPreHookTest.java
deleted file mode 100644
index 8bfe4c9a0..000000000
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/plugin/AssemblyServerPreHookTest.java
+++ /dev/null
@@ -1,143 +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.rpc.enhancement.plugin;
-
-import java.net.URI;
-
-import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
-import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
-import com.tencent.cloud.rpc.enhancement.plugin.assembly.server.AssemblyServerPreHook;
-import com.tencent.polaris.assembly.api.AssemblyAPI;
-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.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.context.ApplicationContext;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-
-import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
-import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-/**
- * AssemblyServerPreHookTest.
- *
- * @author sean yu
- */
-@ExtendWith(MockitoExtension.class)
-public class AssemblyServerPreHookTest {
-
- private static MockedStatic mockedApplicationContextAwareUtils;
- @InjectMocks
- private AssemblyServerPreHook assemblyServerPreHook;
- @Mock
- private AssemblyAPI assemblyAPI;
-
- @BeforeAll
- static void beforeAll() {
- mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class);
- mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties(anyString()))
- .thenReturn("unit-test");
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- RpcEnhancementReporterProperties reporterProperties = mock(RpcEnhancementReporterProperties.class);
- doReturn(reporterProperties)
- .when(applicationContext).getBean(RpcEnhancementReporterProperties.class);
- mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
- .thenReturn(applicationContext);
- }
-
- @AfterAll
- static void afterAll() {
- mockedApplicationContextAwareUtils.close();
- }
-
- @BeforeEach
- void setUp() {
- MetadataContext.LOCAL_NAMESPACE = NAMESPACE_TEST;
- MetadataContext.LOCAL_SERVICE = SERVICE_PROVIDER;
- }
-
- @Test
- public void testGetName() {
- assertThat(assemblyServerPreHook.getName()).isEqualTo(AssemblyServerPreHook.class.getName());
- }
-
- @Test
- public void testType() {
- assertThat(assemblyServerPreHook.getType()).isEqualTo(EnhancedPluginType.Server.PRE);
- }
-
- @Test
- public void testRun() {
- EnhancedPluginContext pluginContext = new EnhancedPluginContext();
- EnhancedRequestContext request = EnhancedRequestContext.builder()
- .httpMethod(HttpMethod.GET)
- .url(URI.create("http://0.0.0.0/"))
- .httpHeaders(new HttpHeaders())
- .build();
- request.toString();
- EnhancedResponseContext response = EnhancedResponseContext.builder()
- .httpStatus(200)
- .build();
- response.toString();
-
- DefaultServiceInstance targetServiceInstance = new DefaultServiceInstance();
- targetServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- DefaultServiceInstance localServiceInstance = new DefaultServiceInstance();
- localServiceInstance.setServiceId(SERVICE_PROVIDER);
-
- pluginContext.setRequest(request);
- pluginContext.setResponse(response);
- pluginContext.setTargetServiceInstance(targetServiceInstance, null);
- pluginContext.setLocalServiceInstance(localServiceInstance);
- pluginContext.setThrowable(new RuntimeException());
-
- assemblyServerPreHook.run(pluginContext);
- assemblyServerPreHook.getOrder();
- assemblyServerPreHook.getName();
- assemblyServerPreHook.getType();
- }
-
- @Test
- public void testHandlerThrowable() {
- // mock request
- EnhancedRequestContext request = mock(EnhancedRequestContext.class);
- // mock response
- EnhancedResponseContext response = mock(EnhancedResponseContext.class);
-
- EnhancedPluginContext context = new EnhancedPluginContext();
- context.setRequest(request);
- context.setResponse(response);
- assemblyServerPreHook.handlerThrowable(context, new RuntimeException("Mock exception."));
- }
-
-}