From 9966878139ae07f4125bd7643d63cd4579c47f66 Mon Sep 17 00:00:00 2001 From: xujingfeng Date: Fri, 4 Jan 2019 13:59:24 +0800 Subject: [PATCH] modify the tag key --- .../rpc/cluster/router/tag/TagRouter.java | 2 +- .../rpc/cluster/router/tag/TagRouterTest.java | 32 +++++++++---------- .../com/alibaba/dubbo/common/Constants.java | 5 +-- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java index dad70d333126..cad4c6a75b45 100644 --- a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -60,7 +60,7 @@ public List> route(List> invokers, URL url, Invocation List> result = new ArrayList>(); try { // Dynamic param - String tag = RpcContext.getContext().getAttachment(Constants.REQUEST_TAG_KEY); + String tag = RpcContext.getContext().getAttachment(Constants.TAG_KEY); // Tag request if (!StringUtils.isEmpty(tag)) { // Select tag invokers first diff --git a/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java b/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java index 1cb053c3e48c..1f9d93a6aedd 100644 --- a/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java @@ -55,15 +55,15 @@ public void setUp() throws Exception { @Test public void testRoute_matchTag() { - RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "red"); + RpcContext.getContext().setAttachment(Constants.TAG_KEY, "red"); List> invokers = new ArrayList>(); Invoker redInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + "dubbo://10.20.3.1:20880/com.foo.BarService?dubbo.tag=red")); Invoker yellowInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + "dubbo://10.20.3.2:20880/com.foo.BarService?dubbo.tag=yellow")); Invoker blueInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + "dubbo://10.20.3.3:20880/com.foo.BarService?dubbo.tag=blue")); Invoker defaultInvoker = new MockInvoker(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); @@ -83,15 +83,15 @@ public void testRoute_matchTag() { @Test public void testRoute_matchDefault() { - RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, ""); + RpcContext.getContext().setAttachment(Constants.TAG_KEY, ""); List> invokers = new ArrayList>(); Invoker redInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + "dubbo://10.20.3.1:20880/com.foo.BarService?dubbo.tag=red")); Invoker yellowInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + "dubbo://10.20.3.2:20880/com.foo.BarService?dubbo.tag=yellow")); Invoker blueInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + "dubbo://10.20.3.3:20880/com.foo.BarService?dubbo.tag=blue")); Invoker defaultInvoker = new MockInvoker(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); @@ -111,15 +111,15 @@ public void testRoute_matchDefault() { @Test public void testRoute_requestWithTag_shouldDowngrade() { - RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, "black"); + RpcContext.getContext().setAttachment(Constants.TAG_KEY, "black"); List> invokers = new ArrayList>(); Invoker redInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + "dubbo://10.20.3.1:20880/com.foo.BarService?dubbo.tag=red")); Invoker yellowInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + "dubbo://10.20.3.2:20880/com.foo.BarService?dubbo.tag=yellow")); Invoker blueInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + "dubbo://10.20.3.3:20880/com.foo.BarService?dubbo.tag=blue")); Invoker defaultInvoker = new MockInvoker(URL.valueOf( "dubbo://10.20.3.4:20880/com.foo.BarService")); @@ -139,15 +139,15 @@ public void testRoute_requestWithTag_shouldDowngrade() { @Test public void testRoute_requestWithoutTag_shouldNotDowngrade() { - RpcContext.getContext().setAttachment(Constants.REQUEST_TAG_KEY, ""); + RpcContext.getContext().setAttachment(Constants.TAG_KEY, ""); List> invokers = new ArrayList>(); Invoker redInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.1:20880/com.foo.BarService?tag=red")); + "dubbo://10.20.3.1:20880/com.foo.BarService?dubbo.tag=red")); Invoker yellowInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.2:20880/com.foo.BarService?tag=yellow")); + "dubbo://10.20.3.2:20880/com.foo.BarService?dubbo.tag=yellow")); Invoker blueInvoker = new MockInvoker(URL.valueOf( - "dubbo://10.20.3.3:20880/com.foo.BarService?tag=blue")); + "dubbo://10.20.3.3:20880/com.foo.BarService?dubbo.tag=blue")); invokers.add(redInvoker); invokers.add(yellowInvoker); diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java index c84e74542312..a3eea2eac44b 100644 --- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java @@ -637,10 +637,7 @@ public class Constants { public static final String SERVICE_IMPL_CLASS = "service.classimpl"; - public static final String TAG_KEY = "tag"; - - public static final String REQUEST_TAG_KEY = "request.tag"; - + public static final String TAG_KEY = "dubbo.tag"; /* * private Constants(){ }