|
|
@ -23,6 +23,7 @@ import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
|
|
|
import com.netflix.client.config.DefaultClientConfigImpl;
|
|
|
|
import com.netflix.client.config.DefaultClientConfigImpl;
|
|
|
@ -52,6 +53,7 @@ import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
|
|
|
|
import com.tencent.polaris.api.pojo.DefaultInstance;
|
|
|
|
import com.tencent.polaris.api.pojo.DefaultInstance;
|
|
|
|
import com.tencent.polaris.api.pojo.DefaultServiceInstances;
|
|
|
|
import com.tencent.polaris.api.pojo.DefaultServiceInstances;
|
|
|
|
import com.tencent.polaris.api.pojo.Instance;
|
|
|
|
import com.tencent.polaris.api.pojo.Instance;
|
|
|
|
|
|
|
|
import com.tencent.polaris.api.pojo.RouteArgument;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceInstances;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceInstances;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.plugins.router.metadata.MetadataRouter;
|
|
|
|
import com.tencent.polaris.plugins.router.metadata.MetadataRouter;
|
|
|
@ -220,13 +222,16 @@ public class PolarisLoadBalancerCompositeRuleTest {
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> routerMetadata = request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA);
|
|
|
|
Set<RouteArgument> routerMetadata = request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, routerMetadata.size());
|
|
|
|
Assert.assertEquals(1, routerMetadata.size());
|
|
|
|
Assert.assertEquals(0, request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
|
|
|
|
Assert.assertEquals(0, request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
|
|
|
|
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
|
|
|
|
Assert.assertEquals(1, request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
|
|
|
|
Assert.assertEquals("false", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)
|
|
|
|
|
|
|
|
.get(RuleBasedRouter.ROUTER_ENABLED));
|
|
|
|
for (RouteArgument routeArgument : request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)) {
|
|
|
|
|
|
|
|
Assert.assertEquals(RuleBasedRouter.ROUTER_ENABLED, routeArgument.getKey());
|
|
|
|
|
|
|
|
Assert.assertEquals("false", routeArgument.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -250,14 +255,22 @@ public class PolarisLoadBalancerCompositeRuleTest {
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> routerMetadata = request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY);
|
|
|
|
Set<RouteArgument> routerMetadata = request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(0, request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA).size());
|
|
|
|
Assert.assertEquals(0, request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA).size());
|
|
|
|
Assert.assertEquals(1, routerMetadata.size());
|
|
|
|
Assert.assertEquals(1, routerMetadata.size());
|
|
|
|
Assert.assertEquals("true", routerMetadata.get(NearbyRouter.ROUTER_ENABLED));
|
|
|
|
|
|
|
|
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
|
|
|
|
for (RouteArgument routeArgument : routerMetadata) {
|
|
|
|
Assert.assertEquals("false", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)
|
|
|
|
Assert.assertEquals(NearbyRouter.ROUTER_ENABLED, routeArgument.getKey());
|
|
|
|
.get(RuleBasedRouter.ROUTER_ENABLED));
|
|
|
|
Assert.assertEquals("true", routeArgument.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (RouteArgument routeArgument : request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)) {
|
|
|
|
|
|
|
|
Assert.assertEquals(RuleBasedRouter.ROUTER_ENABLED, routeArgument.getKey());
|
|
|
|
|
|
|
|
Assert.assertEquals("false", routeArgument.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -281,14 +294,11 @@ public class PolarisLoadBalancerCompositeRuleTest {
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
ProcessRoutersRequest request = compositeRule.buildProcessRoutersBaseRequest(serviceInstances);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
compositeRule.processRouterRequestInterceptors(request, routerContext);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> routerMetadata = request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED);
|
|
|
|
Set<RouteArgument> routerMetadata = request.getRouterArguments(RuleBasedRouter.ROUTER_TYPE_RULE_BASED);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(1, routerMetadata.size());
|
|
|
|
Assert.assertEquals(3, routerMetadata.size());
|
|
|
|
Assert.assertEquals(0, request.getRouterMetadata(MetadataRouter.ROUTER_TYPE_METADATA).size());
|
|
|
|
Assert.assertEquals(0, request.getRouterArguments(MetadataRouter.ROUTER_TYPE_METADATA).size());
|
|
|
|
Assert.assertEquals(0, request.getRouterMetadata(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
|
|
|
|
Assert.assertEquals(0, request.getRouterArguments(NearbyRouter.ROUTER_TYPE_NEAR_BY).size());
|
|
|
|
Assert.assertEquals(1, request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED).size());
|
|
|
|
|
|
|
|
Assert.assertEquals("true", request.getRouterMetadata(RuleBasedRouter.ROUTER_TYPE_RULE_BASED)
|
|
|
|
|
|
|
|
.get(RuleBasedRouter.ROUTER_ENABLED));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|