Skip to content

Commit

Permalink
modify the tag key
Browse files Browse the repository at this point in the history
  • Loading branch information
xujingfeng committed Jan 4, 2019
1 parent 96d1999 commit 9966878
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
List<Invoker<T>> result = new ArrayList<Invoker<T>>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> redInvoker = new MockInvoker<String>(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<String> yellowInvoker = new MockInvoker<String>(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<String> blueInvoker = new MockInvoker<String>(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<String> defaultInvoker = new MockInvoker<String>(URL.valueOf(
"dubbo://10.20.3.4:20880/com.foo.BarService"));

Expand All @@ -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<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> redInvoker = new MockInvoker<String>(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<String> yellowInvoker = new MockInvoker<String>(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<String> blueInvoker = new MockInvoker<String>(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<String> defaultInvoker = new MockInvoker<String>(URL.valueOf(
"dubbo://10.20.3.4:20880/com.foo.BarService"));

Expand All @@ -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<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> redInvoker = new MockInvoker<String>(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<String> yellowInvoker = new MockInvoker<String>(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<String> blueInvoker = new MockInvoker<String>(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<String> defaultInvoker = new MockInvoker<String>(URL.valueOf(
"dubbo://10.20.3.4:20880/com.foo.BarService"));

Expand All @@ -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<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> redInvoker = new MockInvoker<String>(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<String> yellowInvoker = new MockInvoker<String>(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<String> blueInvoker = new MockInvoker<String>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){ }
Expand Down

0 comments on commit 9966878

Please sign in to comment.