fix:fix only config file metadata can be used in routing bug. (#518)

pull/530/head
Haotian Zhang 2 years ago committed by GitHub
parent 4f3ed9321c
commit de6aa9ce3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,3 +11,4 @@
- [Refactor : optimize project and code](https://github.com/Tencent/spring-cloud-tencent/pull/506) - [Refactor : optimize project and code](https://github.com/Tencent/spring-cloud-tencent/pull/506)
- [Fix typo & Code optimization](https://github.com/Tencent/spring-cloud-tencent/pull/507) - [Fix typo & Code optimization](https://github.com/Tencent/spring-cloud-tencent/pull/507)
- [BugfixBeanFactoryUtils returns all beans including beans defined in ancestor bean factories](https://github.com/Tencent/spring-cloud-tencent/pull/515) - [BugfixBeanFactoryUtils returns all beans including beans defined in ancestor bean factories](https://github.com/Tencent/spring-cloud-tencent/pull/515)
- [fix:fix only config file metadata can be used in routing bug.](https://github.com/Tencent/spring-cloud-tencent/pull/518)

@ -20,7 +20,7 @@ package com.tencent.cloud.polaris.router.beanprocessor;
import java.util.List; import java.util.List;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.BeanFactoryUtils; import com.tencent.cloud.common.util.BeanFactoryUtils;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
import com.tencent.cloud.polaris.router.scg.PolarisLoadBalancerClientFilter; import com.tencent.cloud.polaris.router.scg.PolarisLoadBalancerClientFilter;
@ -57,11 +57,11 @@ public class LoadBalancerClientFilterBeanPostProcessor implements BeanPostProces
LoadBalancerClient loadBalancerClient = this.factory.getBean(LoadBalancerClient.class); LoadBalancerClient loadBalancerClient = this.factory.getBean(LoadBalancerClient.class);
LoadBalancerProperties loadBalancerProperties = this.factory.getBean(LoadBalancerProperties.class); LoadBalancerProperties loadBalancerProperties = this.factory.getBean(LoadBalancerProperties.class);
List<SpringWebRouterLabelResolver> routerLabelResolvers = BeanFactoryUtils.getBeans(factory, SpringWebRouterLabelResolver.class); List<SpringWebRouterLabelResolver> routerLabelResolvers = BeanFactoryUtils.getBeans(factory, SpringWebRouterLabelResolver.class);
MetadataLocalProperties metadataLocalProperties = this.factory.getBean(MetadataLocalProperties.class); StaticMetadataManager staticMetadataManager = this.factory.getBean(StaticMetadataManager.class);
RouterRuleLabelResolver routerRuleLabelResolver = this.factory.getBean(RouterRuleLabelResolver.class); RouterRuleLabelResolver routerRuleLabelResolver = this.factory.getBean(RouterRuleLabelResolver.class);
return new PolarisLoadBalancerClientFilter(loadBalancerClient, loadBalancerProperties, return new PolarisLoadBalancerClientFilter(loadBalancerClient, loadBalancerProperties,
metadataLocalProperties, routerRuleLabelResolver, routerLabelResolvers); staticMetadataManager, routerRuleLabelResolver, routerLabelResolvers);
} }
return bean; return bean;
} }

@ -20,7 +20,7 @@ package com.tencent.cloud.polaris.router.beanprocessor;
import java.util.List; import java.util.List;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.BeanFactoryUtils; import com.tencent.cloud.common.util.BeanFactoryUtils;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
import com.tencent.cloud.polaris.router.resttemplate.PolarisLoadBalancerInterceptor; import com.tencent.cloud.polaris.router.resttemplate.PolarisLoadBalancerInterceptor;
@ -58,11 +58,11 @@ public class LoadBalancerInterceptorBeanPostProcessor implements BeanPostProcess
LoadBalancerRequestFactory requestFactory = this.factory.getBean(LoadBalancerRequestFactory.class); LoadBalancerRequestFactory requestFactory = this.factory.getBean(LoadBalancerRequestFactory.class);
LoadBalancerClient loadBalancerClient = this.factory.getBean(LoadBalancerClient.class); LoadBalancerClient loadBalancerClient = this.factory.getBean(LoadBalancerClient.class);
List<SpringWebRouterLabelResolver> routerLabelResolvers = BeanFactoryUtils.getBeans(factory, SpringWebRouterLabelResolver.class); List<SpringWebRouterLabelResolver> routerLabelResolvers = BeanFactoryUtils.getBeans(factory, SpringWebRouterLabelResolver.class);
MetadataLocalProperties metadataLocalProperties = this.factory.getBean(MetadataLocalProperties.class); StaticMetadataManager staticMetadataManager = this.factory.getBean(StaticMetadataManager.class);
RouterRuleLabelResolver routerRuleLabelResolver = this.factory.getBean(RouterRuleLabelResolver.class); RouterRuleLabelResolver routerRuleLabelResolver = this.factory.getBean(RouterRuleLabelResolver.class);
return new PolarisLoadBalancerInterceptor(loadBalancerClient, requestFactory, return new PolarisLoadBalancerInterceptor(loadBalancerClient, requestFactory,
routerLabelResolvers, metadataLocalProperties, routerRuleLabelResolver); routerLabelResolvers, staticMetadataManager, routerRuleLabelResolver);
} }
return bean; return bean;
} }

@ -20,7 +20,7 @@ package com.tencent.cloud.polaris.router.config;
import java.util.List; import java.util.List;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
import com.tencent.cloud.polaris.router.feign.PolarisCachingSpringLoadBalanceFactory; import com.tencent.cloud.polaris.router.feign.PolarisCachingSpringLoadBalanceFactory;
import com.tencent.cloud.polaris.router.feign.RouterLabelFeignInterceptor; import com.tencent.cloud.polaris.router.feign.RouterLabelFeignInterceptor;
@ -46,9 +46,9 @@ public class FeignAutoConfiguration {
@Bean @Bean
public RouterLabelFeignInterceptor routerLabelInterceptor(@Nullable List<FeignRouterLabelResolver> routerLabelResolvers, public RouterLabelFeignInterceptor routerLabelInterceptor(@Nullable List<FeignRouterLabelResolver> routerLabelResolvers,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver) { RouterRuleLabelResolver routerRuleLabelResolver) {
return new RouterLabelFeignInterceptor(routerLabelResolvers, metadataLocalProperties, routerRuleLabelResolver); return new RouterLabelFeignInterceptor(routerLabelResolvers, staticMetadataManager, routerRuleLabelResolver);
} }
@Bean @Bean

@ -20,7 +20,7 @@ package com.tencent.cloud.polaris.router.config;
import java.util.List; import java.util.List;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.polaris.context.ServiceRuleManager; import com.tencent.cloud.polaris.context.ServiceRuleManager;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
import com.tencent.cloud.polaris.router.beanprocessor.LoadBalancerClientFilterBeanPostProcessor; import com.tencent.cloud.polaris.router.beanprocessor.LoadBalancerClientFilterBeanPostProcessor;
@ -106,10 +106,10 @@ public class RouterAutoConfiguration {
@Bean(initMethod = "init") @Bean(initMethod = "init")
public PolarisRibbonRoutingFilter ribbonRoutingFilter(ProxyRequestHelper helper, public PolarisRibbonRoutingFilter ribbonRoutingFilter(ProxyRequestHelper helper,
RibbonCommandFactory<?> ribbonCommandFactory, RibbonCommandFactory<?> ribbonCommandFactory,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver, RouterRuleLabelResolver routerRuleLabelResolver,
List<ServletRouterLabelResolver> routerLabelResolvers) { List<ServletRouterLabelResolver> routerLabelResolvers) {
return new PolarisRibbonRoutingFilter(helper, ribbonCommandFactory, metadataLocalProperties, return new PolarisRibbonRoutingFilter(helper, ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, routerLabelResolvers); routerRuleLabelResolver, routerLabelResolvers);
} }
} }

@ -29,7 +29,7 @@ import java.util.Set;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.JacksonUtils; import com.tencent.cloud.common.util.JacksonUtils;
import com.tencent.cloud.polaris.router.RouterConstants; import com.tencent.cloud.polaris.router.RouterConstants;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
@ -53,11 +53,11 @@ public class RouterLabelFeignInterceptor implements RequestInterceptor, Ordered
private static final Logger LOGGER = LoggerFactory.getLogger(RouterLabelFeignInterceptor.class); private static final Logger LOGGER = LoggerFactory.getLogger(RouterLabelFeignInterceptor.class);
private final List<FeignRouterLabelResolver> routerLabelResolvers; private final List<FeignRouterLabelResolver> routerLabelResolvers;
private final MetadataLocalProperties metadataLocalProperties; private final StaticMetadataManager staticMetadataManager;
private final RouterRuleLabelResolver routerRuleLabelResolver; private final RouterRuleLabelResolver routerRuleLabelResolver;
public RouterLabelFeignInterceptor(List<FeignRouterLabelResolver> routerLabelResolvers, public RouterLabelFeignInterceptor(List<FeignRouterLabelResolver> routerLabelResolvers,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver) { RouterRuleLabelResolver routerRuleLabelResolver) {
if (!CollectionUtils.isEmpty(routerLabelResolvers)) { if (!CollectionUtils.isEmpty(routerLabelResolvers)) {
routerLabelResolvers.sort(Comparator.comparingInt(Ordered::getOrder)); routerLabelResolvers.sort(Comparator.comparingInt(Ordered::getOrder));
@ -66,7 +66,7 @@ public class RouterLabelFeignInterceptor implements RequestInterceptor, Ordered
else { else {
this.routerLabelResolvers = null; this.routerLabelResolvers = null;
} }
this.metadataLocalProperties = metadataLocalProperties; this.staticMetadataManager = staticMetadataManager;
this.routerRuleLabelResolver = routerRuleLabelResolver; this.routerRuleLabelResolver = routerRuleLabelResolver;
} }
@ -78,7 +78,7 @@ public class RouterLabelFeignInterceptor implements RequestInterceptor, Ordered
@Override @Override
public void apply(RequestTemplate requestTemplate) { public void apply(RequestTemplate requestTemplate) {
// local service labels // local service labels
Map<String, String> labels = new HashMap<>(metadataLocalProperties.getContent()); Map<String, String> labels = new HashMap<>(staticMetadataManager.getMergedStaticMetadata());
// labels from rule expression // labels from rule expression
String peerServiceName = requestTemplate.feignTarget().name(); String peerServiceName = requestTemplate.feignTarget().name();
@ -103,7 +103,8 @@ public class RouterLabelFeignInterceptor implements RequestInterceptor, Ordered
} }
// labels from downstream // labels from downstream
Map<String, String> transitiveLabels = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE); Map<String, String> transitiveLabels = MetadataContextHolder.get()
.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
labels.putAll(transitiveLabels); labels.putAll(transitiveLabels);
// pass label by header // pass label by header

@ -29,7 +29,7 @@ import java.util.Set;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.expresstion.SpringWebExpressionLabelUtils; import com.tencent.cloud.common.util.expresstion.SpringWebExpressionLabelUtils;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
@ -60,7 +60,7 @@ public class PolarisLoadBalancerInterceptor extends LoadBalancerInterceptor {
private final LoadBalancerClient loadBalancer; private final LoadBalancerClient loadBalancer;
private final LoadBalancerRequestFactory requestFactory; private final LoadBalancerRequestFactory requestFactory;
private final List<SpringWebRouterLabelResolver> routerLabelResolvers; private final List<SpringWebRouterLabelResolver> routerLabelResolvers;
private final MetadataLocalProperties metadataLocalProperties; private final StaticMetadataManager staticMetadataManager;
private final RouterRuleLabelResolver routerRuleLabelResolver; private final RouterRuleLabelResolver routerRuleLabelResolver;
private final boolean isRibbonLoadBalanceClient; private final boolean isRibbonLoadBalanceClient;
@ -68,12 +68,12 @@ public class PolarisLoadBalancerInterceptor extends LoadBalancerInterceptor {
public PolarisLoadBalancerInterceptor(LoadBalancerClient loadBalancer, public PolarisLoadBalancerInterceptor(LoadBalancerClient loadBalancer,
LoadBalancerRequestFactory requestFactory, LoadBalancerRequestFactory requestFactory,
List<SpringWebRouterLabelResolver> routerLabelResolvers, List<SpringWebRouterLabelResolver> routerLabelResolvers,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver) { RouterRuleLabelResolver routerRuleLabelResolver) {
super(loadBalancer, requestFactory); super(loadBalancer, requestFactory);
this.loadBalancer = loadBalancer; this.loadBalancer = loadBalancer;
this.requestFactory = requestFactory; this.requestFactory = requestFactory;
this.metadataLocalProperties = metadataLocalProperties; this.staticMetadataManager = staticMetadataManager;
this.routerRuleLabelResolver = routerRuleLabelResolver; this.routerRuleLabelResolver = routerRuleLabelResolver;
if (!CollectionUtils.isEmpty(routerLabelResolvers)) { if (!CollectionUtils.isEmpty(routerLabelResolvers)) {
@ -107,7 +107,7 @@ public class PolarisLoadBalancerInterceptor extends LoadBalancerInterceptor {
PolarisRouterContext genRouterContext(HttpRequest request, byte[] body, String peerServiceName) { PolarisRouterContext genRouterContext(HttpRequest request, byte[] body, String peerServiceName) {
// local service labels // local service labels
Map<String, String> labels = new HashMap<>(metadataLocalProperties.getContent()); Map<String, String> labels = new HashMap<>(staticMetadataManager.getMergedStaticMetadata());
// labels from rule expression // labels from rule expression
Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE, Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE,

@ -28,7 +28,7 @@ import java.util.Set;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.expresstion.SpringWebExpressionLabelUtils; import com.tencent.cloud.common.util.expresstion.SpringWebExpressionLabelUtils;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
@ -55,18 +55,18 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.G
public class PolarisLoadBalancerClientFilter extends LoadBalancerClientFilter { public class PolarisLoadBalancerClientFilter extends LoadBalancerClientFilter {
private final static Logger LOGGER = LoggerFactory.getLogger(PolarisLoadBalancerClientFilter.class); private final static Logger LOGGER = LoggerFactory.getLogger(PolarisLoadBalancerClientFilter.class);
private final MetadataLocalProperties metadataLocalProperties; private final StaticMetadataManager staticMetadataManager;
private final RouterRuleLabelResolver routerRuleLabelResolver; private final RouterRuleLabelResolver routerRuleLabelResolver;
private final List<SpringWebRouterLabelResolver> routerLabelResolvers; private final List<SpringWebRouterLabelResolver> routerLabelResolvers;
private final boolean isRibbonLoadBalanceClient; private final boolean isRibbonLoadBalanceClient;
public PolarisLoadBalancerClientFilter(LoadBalancerClient loadBalancer, LoadBalancerProperties properties, public PolarisLoadBalancerClientFilter(LoadBalancerClient loadBalancer, LoadBalancerProperties properties,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver, RouterRuleLabelResolver routerRuleLabelResolver,
List<SpringWebRouterLabelResolver> routerLabelResolvers) { List<SpringWebRouterLabelResolver> routerLabelResolvers) {
super(loadBalancer, properties); super(loadBalancer, properties);
this.metadataLocalProperties = metadataLocalProperties; this.staticMetadataManager = staticMetadataManager;
this.routerRuleLabelResolver = routerRuleLabelResolver; this.routerRuleLabelResolver = routerRuleLabelResolver;
if (!CollectionUtils.isEmpty(routerLabelResolvers)) { if (!CollectionUtils.isEmpty(routerLabelResolvers)) {
@ -96,7 +96,7 @@ public class PolarisLoadBalancerClientFilter extends LoadBalancerClientFilter {
PolarisRouterContext genRouterContext(ServerWebExchange exchange, String peerServiceName) { PolarisRouterContext genRouterContext(ServerWebExchange exchange, String peerServiceName) {
// local service labels // local service labels
Map<String, String> labels = new HashMap<>(metadataLocalProperties.getContent()); Map<String, String> labels = new HashMap<>(staticMetadataManager.getMergedStaticMetadata());
// labels from rule expression // labels from rule expression
Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE, Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE,

@ -31,7 +31,7 @@ import javax.servlet.http.HttpServletRequest;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.BeanFactoryUtils; import com.tencent.cloud.common.util.BeanFactoryUtils;
import com.tencent.cloud.common.util.expresstion.ServletExpressionLabelUtils; import com.tencent.cloud.common.util.expresstion.ServletExpressionLabelUtils;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
@ -65,24 +65,19 @@ import static org.springframework.cloud.netflix.zuul.filters.support.FilterConst
public class PolarisRibbonRoutingFilter extends RibbonRoutingFilter implements BeanFactoryAware { public class PolarisRibbonRoutingFilter extends RibbonRoutingFilter implements BeanFactoryAware {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRibbonRoutingFilter.class); private static final Logger LOGGER = LoggerFactory.getLogger(PolarisRibbonRoutingFilter.class);
private final StaticMetadataManager staticMetadataManager;
private BeanFactory factory;
private final MetadataLocalProperties metadataLocalProperties;
private final RouterRuleLabelResolver routerRuleLabelResolver; private final RouterRuleLabelResolver routerRuleLabelResolver;
private final List<ServletRouterLabelResolver> routerLabelResolvers; private final List<ServletRouterLabelResolver> routerLabelResolvers;
private BeanFactory factory;
private boolean useServlet31 = true; private boolean useServlet31 = true;
public PolarisRibbonRoutingFilter(ProxyRequestHelper helper, public PolarisRibbonRoutingFilter(ProxyRequestHelper helper,
RibbonCommandFactory<?> ribbonCommandFactory, RibbonCommandFactory<?> ribbonCommandFactory,
MetadataLocalProperties metadataLocalProperties, StaticMetadataManager staticMetadataManager,
RouterRuleLabelResolver routerRuleLabelResolver, RouterRuleLabelResolver routerRuleLabelResolver,
List<ServletRouterLabelResolver> routerLabelResolvers) { List<ServletRouterLabelResolver> routerLabelResolvers) {
super(helper, ribbonCommandFactory, Collections.emptyList()); super(helper, ribbonCommandFactory, Collections.emptyList());
this.metadataLocalProperties = metadataLocalProperties; this.staticMetadataManager = staticMetadataManager;
this.routerRuleLabelResolver = routerRuleLabelResolver; this.routerRuleLabelResolver = routerRuleLabelResolver;
if (!CollectionUtils.isEmpty(routerLabelResolvers)) { if (!CollectionUtils.isEmpty(routerLabelResolvers)) {
@ -139,7 +134,7 @@ public class PolarisRibbonRoutingFilter extends RibbonRoutingFilter implements B
PolarisRouterContext genRouterContext(HttpServletRequest request, String serviceId) { PolarisRouterContext genRouterContext(HttpServletRequest request, String serviceId) {
// local service labels // local service labels
Map<String, String> labels = new HashMap<>(metadataLocalProperties.getContent()); Map<String, String> labels = new HashMap<>(staticMetadataManager.getMergedStaticMetadata());
// labels from rule expression // labels from rule expression
Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE, Set<String> expressionLabelKeys = routerRuleLabelResolver.getExpressionLabelKeys(MetadataContext.LOCAL_NAMESPACE,

@ -29,7 +29,7 @@ import java.util.Set;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.common.util.JacksonUtils; import com.tencent.cloud.common.util.JacksonUtils;
import com.tencent.cloud.polaris.router.RouterConstants; import com.tencent.cloud.polaris.router.RouterConstants;
@ -58,7 +58,7 @@ import static org.mockito.Mockito.when;
public class RouterLabelFeignInterceptorTest { public class RouterLabelFeignInterceptorTest {
@Mock @Mock
private MetadataLocalProperties metadataLocalProperties; private StaticMetadataManager staticMetadataManager;
@Mock @Mock
private RouterRuleLabelResolver routerRuleLabelResolver; private RouterRuleLabelResolver routerRuleLabelResolver;
@Mock @Mock
@ -67,7 +67,7 @@ public class RouterLabelFeignInterceptorTest {
@Test @Test
public void testResolveRouterLabel() { public void testResolveRouterLabel() {
RouterLabelFeignInterceptor routerLabelFeignInterceptor = new RouterLabelFeignInterceptor( RouterLabelFeignInterceptor routerLabelFeignInterceptor = new RouterLabelFeignInterceptor(
Collections.singletonList(routerLabelResolver), metadataLocalProperties, routerRuleLabelResolver); Collections.singletonList(routerLabelResolver), staticMetadataManager, routerRuleLabelResolver);
// mock request template // mock request template
RequestTemplate requestTemplate = new RequestTemplate(); RequestTemplate requestTemplate = new RequestTemplate();
@ -113,7 +113,7 @@ public class RouterLabelFeignInterceptorTest {
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("k3", "v31"); localMetadata.put("k3", "v31");
localMetadata.put("k4", "v4"); localMetadata.put("k4", "v4");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
routerLabelFeignInterceptor.apply(requestTemplate); routerLabelFeignInterceptor.apply(requestTemplate);

@ -18,7 +18,7 @@
package com.tencent.cloud.polaris.router.resttemplate; package com.tencent.cloud.polaris.router.resttemplate;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.BeanFactoryUtils; import com.tencent.cloud.common.util.BeanFactoryUtils;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
import com.tencent.cloud.polaris.router.beanprocessor.LoadBalancerInterceptorBeanPostProcessor; import com.tencent.cloud.polaris.router.beanprocessor.LoadBalancerInterceptorBeanPostProcessor;
@ -51,7 +51,7 @@ public class PolarisLoadBalancerBeanPostProcessorTest {
@Mock @Mock
private LoadBalancerRequestFactory loadBalancerRequestFactory; private LoadBalancerRequestFactory loadBalancerRequestFactory;
@Mock @Mock
private MetadataLocalProperties metadataLocalProperties; private StaticMetadataManager staticMetadataManager;
@Mock @Mock
private RouterRuleLabelResolver routerRuleLabelResolver; private RouterRuleLabelResolver routerRuleLabelResolver;
@Mock @Mock
@ -61,7 +61,7 @@ public class PolarisLoadBalancerBeanPostProcessorTest {
public void testWrapperLoadBalancerInterceptor() { public void testWrapperLoadBalancerInterceptor() {
when(beanFactory.getBean(LoadBalancerRequestFactory.class)).thenReturn(loadBalancerRequestFactory); when(beanFactory.getBean(LoadBalancerRequestFactory.class)).thenReturn(loadBalancerRequestFactory);
when(beanFactory.getBean(LoadBalancerClient.class)).thenReturn(loadBalancerClient); when(beanFactory.getBean(LoadBalancerClient.class)).thenReturn(loadBalancerClient);
when(beanFactory.getBean(MetadataLocalProperties.class)).thenReturn(metadataLocalProperties); when(beanFactory.getBean(StaticMetadataManager.class)).thenReturn(staticMetadataManager);
when(beanFactory.getBean(RouterRuleLabelResolver.class)).thenReturn(routerRuleLabelResolver); when(beanFactory.getBean(RouterRuleLabelResolver.class)).thenReturn(routerRuleLabelResolver);
try (MockedStatic<BeanFactoryUtils> mockedBeanFactoryUtils = Mockito.mockStatic(BeanFactoryUtils.class)) { try (MockedStatic<BeanFactoryUtils> mockedBeanFactoryUtils = Mockito.mockStatic(BeanFactoryUtils.class)) {

@ -28,7 +28,7 @@ import java.util.Set;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
@ -72,7 +72,7 @@ public class PolarisLoadBalancerInterceptorTest {
@Mock @Mock
private SpringWebRouterLabelResolver routerLabelResolver; private SpringWebRouterLabelResolver routerLabelResolver;
@Mock @Mock
private MetadataLocalProperties metadataLocalProperties; private StaticMetadataManager staticMetadataManager;
@Mock @Mock
private RouterRuleLabelResolver routerRuleLabelResolver; private RouterRuleLabelResolver routerRuleLabelResolver;
@ -86,7 +86,7 @@ public class PolarisLoadBalancerInterceptorTest {
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("k1", "v1"); localMetadata.put("k1", "v1");
localMetadata.put("k2", "v2"); localMetadata.put("k2", "v2");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
// mock expression rule labels // mock expression rule labels
Set<String> expressionKeys = new HashSet<>(); Set<String> expressionKeys = new HashSet<>();
@ -120,11 +120,11 @@ public class PolarisLoadBalancerInterceptorTest {
when(loadBalancerRequestFactory.createRequest(request, null, null)).thenReturn(loadBalancerRequest); when(loadBalancerRequestFactory.createRequest(request, null, null)).thenReturn(loadBalancerRequest);
PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor = new PolarisLoadBalancerInterceptor(loadBalancerClient, PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor = new PolarisLoadBalancerInterceptor(loadBalancerClient,
loadBalancerRequestFactory, Collections.singletonList(routerLabelResolver), metadataLocalProperties, routerRuleLabelResolver); loadBalancerRequestFactory, Collections.singletonList(routerLabelResolver), staticMetadataManager, routerRuleLabelResolver);
polarisLoadBalancerInterceptor.intercept(request, null, null); polarisLoadBalancerInterceptor.intercept(request, null, null);
verify(metadataLocalProperties).getContent(); verify(staticMetadataManager).getMergedStaticMetadata();
verify(routerRuleLabelResolver).getExpressionLabelKeys(callerService, callerService, calleeService); verify(routerRuleLabelResolver).getExpressionLabelKeys(callerService, callerService, calleeService);
verify(routerLabelResolver).resolve(request, null, expressionKeys); verify(routerLabelResolver).resolve(request, null, expressionKeys);
} }
@ -145,7 +145,7 @@ public class PolarisLoadBalancerInterceptorTest {
PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor = new PolarisLoadBalancerInterceptor( PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor = new PolarisLoadBalancerInterceptor(
notRibbonLoadBalancerClient, loadBalancerRequestFactory, notRibbonLoadBalancerClient, loadBalancerRequestFactory,
Collections.singletonList(routerLabelResolver), metadataLocalProperties, Collections.singletonList(routerLabelResolver), staticMetadataManager,
routerRuleLabelResolver); routerRuleLabelResolver);
ClientHttpResponse response = polarisLoadBalancerInterceptor.intercept(request, null, null); ClientHttpResponse response = polarisLoadBalancerInterceptor.intercept(request, null, null);
@ -166,7 +166,7 @@ public class PolarisLoadBalancerInterceptorTest {
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("k1", "v1"); localMetadata.put("k1", "v1");
localMetadata.put("k2", "v2"); localMetadata.put("k2", "v2");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
// mock expression rule labels // mock expression rule labels
Set<String> expressionKeys = new HashSet<>(); Set<String> expressionKeys = new HashSet<>();
@ -197,12 +197,12 @@ public class PolarisLoadBalancerInterceptorTest {
PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor = PolarisLoadBalancerInterceptor polarisLoadBalancerInterceptor =
new PolarisLoadBalancerInterceptor(loadBalancerClient, loadBalancerRequestFactory, new PolarisLoadBalancerInterceptor(loadBalancerClient, loadBalancerRequestFactory,
Collections.singletonList(routerLabelResolver), metadataLocalProperties, Collections.singletonList(routerLabelResolver), staticMetadataManager,
routerRuleLabelResolver); routerRuleLabelResolver);
PolarisRouterContext routerContext = polarisLoadBalancerInterceptor.genRouterContext(request, null, calleeService); PolarisRouterContext routerContext = polarisLoadBalancerInterceptor.genRouterContext(request, null, calleeService);
verify(metadataLocalProperties).getContent(); verify(staticMetadataManager).getMergedStaticMetadata();
verify(routerRuleLabelResolver).getExpressionLabelKeys(callerService, callerService, calleeService); verify(routerRuleLabelResolver).getExpressionLabelKeys(callerService, callerService, calleeService);
verify(routerLabelResolver).resolve(request, null, expressionKeys); verify(routerLabelResolver).resolve(request, null, expressionKeys);
@ -211,8 +211,10 @@ public class PolarisLoadBalancerInterceptorTest {
Assert.assertEquals("v1", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k1")); Assert.assertEquals("v1", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k1"));
Assert.assertEquals("v22", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k2")); Assert.assertEquals("v22", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k2"));
Assert.assertEquals("v4", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k4")); Assert.assertEquals("v4", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("k4"));
Assert.assertEquals("GET", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("${http.method}")); Assert.assertEquals("GET", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS)
Assert.assertEquals("/user/get", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS).get("${http.uri}")); .get("${http.method}"));
Assert.assertEquals("/user/get", routerContext.getLabels(PolarisRouterContext.ROUTER_LABELS)
.get("${http.uri}"));
} }
} }
} }

@ -27,7 +27,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
import com.tencent.cloud.polaris.router.RouterRuleLabelResolver; import com.tencent.cloud.polaris.router.RouterRuleLabelResolver;
@ -68,7 +68,7 @@ public class PolarisLoadBalancerClientFilterTest {
private static MockedStatic<ApplicationContextAwareUtils> mockedApplicationContextAwareUtils; private static MockedStatic<ApplicationContextAwareUtils> mockedApplicationContextAwareUtils;
private static MockedStatic<MetadataContextHolder> mockedMetadataContextHolder; private static MockedStatic<MetadataContextHolder> mockedMetadataContextHolder;
@Mock @Mock
private MetadataLocalProperties metadataLocalProperties; private StaticMetadataManager staticMetadataManager;
@Mock @Mock
private RouterRuleLabelResolver routerRuleLabelResolver; private RouterRuleLabelResolver routerRuleLabelResolver;
@Mock @Mock
@ -105,12 +105,12 @@ public class PolarisLoadBalancerClientFilterTest {
@Test @Test
public void testGenRouterContext() { public void testGenRouterContext() {
PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter( PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter(
loadBalancerClient, loadBalancerProperties, metadataLocalProperties, routerRuleLabelResolver, loadBalancerClient, loadBalancerProperties, staticMetadataManager, routerRuleLabelResolver,
Lists.newArrayList(routerLabelResolver)); Lists.newArrayList(routerLabelResolver));
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("env", "blue"); localMetadata.put("env", "blue");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}"); Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}");
when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString())).thenReturn(expressionLabelKeys); when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString())).thenReturn(expressionLabelKeys);
@ -138,7 +138,7 @@ public class PolarisLoadBalancerClientFilterTest {
@Test @Test
public void testChooseInstanceWithoutRibbon() { public void testChooseInstanceWithoutRibbon() {
PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter( PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter(
loadBalancerClient, loadBalancerProperties, metadataLocalProperties, routerRuleLabelResolver, loadBalancerClient, loadBalancerProperties, staticMetadataManager, routerRuleLabelResolver,
Lists.newArrayList(routerLabelResolver)); Lists.newArrayList(routerLabelResolver));
String url = "/" + calleeService + "/users"; String url = "/" + calleeService + "/users";
@ -152,7 +152,7 @@ public class PolarisLoadBalancerClientFilterTest {
polarisLoadBalancerClientFilter.choose(webExchange); polarisLoadBalancerClientFilter.choose(webExchange);
verify(loadBalancerClient).choose(calleeService); verify(loadBalancerClient).choose(calleeService);
verify(metadataLocalProperties, times(0)).getContent(); verify(staticMetadataManager, times(0)).getMergedStaticMetadata();
} }
@Test @Test
@ -160,12 +160,12 @@ public class PolarisLoadBalancerClientFilterTest {
RibbonLoadBalancerClient ribbonLoadBalancerClient = Mockito.mock(RibbonLoadBalancerClient.class); RibbonLoadBalancerClient ribbonLoadBalancerClient = Mockito.mock(RibbonLoadBalancerClient.class);
PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter( PolarisLoadBalancerClientFilter polarisLoadBalancerClientFilter = new PolarisLoadBalancerClientFilter(
ribbonLoadBalancerClient, loadBalancerProperties, metadataLocalProperties, routerRuleLabelResolver, ribbonLoadBalancerClient, loadBalancerProperties, staticMetadataManager, routerRuleLabelResolver,
Lists.newArrayList(routerLabelResolver)); Lists.newArrayList(routerLabelResolver));
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("env", "blue"); localMetadata.put("env", "blue");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}"); Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}");
when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString())).thenReturn(expressionLabelKeys); when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString())).thenReturn(expressionLabelKeys);
@ -185,6 +185,6 @@ public class PolarisLoadBalancerClientFilterTest {
polarisLoadBalancerClientFilter.choose(webExchange); polarisLoadBalancerClientFilter.choose(webExchange);
verify(ribbonLoadBalancerClient).choose(anyString(), any()); verify(ribbonLoadBalancerClient).choose(anyString(), any());
verify(metadataLocalProperties, times(1)).getContent(); verify(staticMetadataManager, times(1)).getMergedStaticMetadata();
} }
} }

@ -31,7 +31,7 @@ import com.netflix.niws.client.http.RestClient;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.StaticMetadataManager;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancer; import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancer;
import com.tencent.cloud.polaris.router.PolarisRouterContext; import com.tencent.cloud.polaris.router.PolarisRouterContext;
@ -81,7 +81,7 @@ public class PolarisRibbonRoutingFilterTest {
private static MockedStatic<ApplicationContextAwareUtils> mockedApplicationContextAwareUtils; private static MockedStatic<ApplicationContextAwareUtils> mockedApplicationContextAwareUtils;
private static MockedStatic<MetadataContextHolder> mockedMetadataContextHolder; private static MockedStatic<MetadataContextHolder> mockedMetadataContextHolder;
@Mock @Mock
private MetadataLocalProperties metadataLocalProperties; private StaticMetadataManager staticMetadataManager;
@Mock @Mock
private RouterRuleLabelResolver routerRuleLabelResolver; private RouterRuleLabelResolver routerRuleLabelResolver;
@Mock @Mock
@ -122,12 +122,12 @@ public class PolarisRibbonRoutingFilterTest {
@Test @Test
public void testGenRouterContext() { public void testGenRouterContext() {
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(proxyRequestHelper, PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(proxyRequestHelper,
ribbonCommandFactory, metadataLocalProperties, routerRuleLabelResolver, ribbonCommandFactory, staticMetadataManager, routerRuleLabelResolver,
Lists.newArrayList(routerLabelResolver)); Lists.newArrayList(routerLabelResolver));
Map<String, String> localMetadata = new HashMap<>(); Map<String, String> localMetadata = new HashMap<>();
localMetadata.put("env", "blue"); localMetadata.put("env", "blue");
when(metadataLocalProperties.getContent()).thenReturn(localMetadata); when(staticMetadataManager.getMergedStaticMetadata()).thenReturn(localMetadata);
Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}"); Set<String> expressionLabelKeys = Sets.newHashSet("${http.header.k1}", "${http.query.userid}");
when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString())) when(routerRuleLabelResolver.getExpressionLabelKeys(anyString(), anyString(), anyString()))
@ -159,7 +159,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -184,7 +184,7 @@ public class PolarisRibbonRoutingFilterTest {
command.execute(); command.execute();
verify(polarisLoadBalancer).chooseServer(calleeService); verify(polarisLoadBalancer).chooseServer(calleeService);
verify(metadataLocalProperties, times(0)).getContent(); verify(staticMetadataManager, times(0)).getMergedStaticMetadata();
} }
@Test @Test
@ -194,7 +194,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -220,7 +220,7 @@ public class PolarisRibbonRoutingFilterTest {
// RestClient not use loadBalancerKey // RestClient not use loadBalancerKey
verify(polarisLoadBalancer).chooseServer(null); verify(polarisLoadBalancer).chooseServer(null);
verify(metadataLocalProperties, times(0)).getContent(); verify(staticMetadataManager, times(0)).getMergedStaticMetadata();
} }
@Test @Test
@ -230,7 +230,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -255,7 +255,7 @@ public class PolarisRibbonRoutingFilterTest {
command.execute(); command.execute();
verify(polarisLoadBalancer).chooseServer(calleeService); verify(polarisLoadBalancer).chooseServer(calleeService);
verify(metadataLocalProperties, times(0)).getContent(); verify(staticMetadataManager, times(0)).getMergedStaticMetadata();
} }
@Test @Test
@ -265,7 +265,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -290,7 +290,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties, fallbackProvider, clientConfig); zuulProperties, fallbackProvider, clientConfig);
command.execute(); command.execute();
verify(polarisLoadBalancer).chooseServer(routerContext); verify(polarisLoadBalancer).chooseServer(routerContext);
verify(metadataLocalProperties, times(1)).getContent(); verify(staticMetadataManager, times(1)).getMergedStaticMetadata();
} }
@Test @Test
@ -300,7 +300,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -327,7 +327,7 @@ public class PolarisRibbonRoutingFilterTest {
// RestClient not use loadBalancerKey // RestClient not use loadBalancerKey
verify(polarisLoadBalancer).chooseServer(null); verify(polarisLoadBalancer).chooseServer(null);
verify(metadataLocalProperties, times(1)).getContent(); verify(staticMetadataManager, times(1)).getMergedStaticMetadata();
} }
@Test @Test
@ -337,7 +337,7 @@ public class PolarisRibbonRoutingFilterTest {
zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool()); zuulProperties.setThreadPool(new ZuulProperties.HystrixThreadPool());
PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter( PolarisRibbonRoutingFilter polarisRibbonRoutingFilter = new PolarisRibbonRoutingFilter(
new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, metadataLocalProperties, new ProxyRequestHelper(zuulProperties), ribbonCommandFactory, staticMetadataManager,
routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver)); routerRuleLabelResolver, Lists.newArrayList(routerLabelResolver));
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
@ -367,6 +367,6 @@ public class PolarisRibbonRoutingFilterTest {
command.execute(); command.execute();
verify(polarisLoadBalancer).chooseServer(routerContext); verify(polarisLoadBalancer).chooseServer(routerContext);
verify(metadataLocalProperties, times(1)).getContent(); verify(staticMetadataManager, times(1)).getMergedStaticMetadata();
} }
} }

Loading…
Cancel
Save