test_class.file: dubbo-cluster/src/test/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouterTest.java
test_class.identifier: TagRouterTest
test_case.body: @Test
      public void testRoute_matchTag() {
          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?dubbo.tag=red"));
          Invoker<String> yellowInvoker = new MockInvoker<String>(URL.valueOf(
                  "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?dubbo.tag=blue"));
          Invoker<String> defaultInvoker = new MockInvoker<String>(URL.valueOf(
                  "dubbo://10.20.3.4:20880/com.foo.BarService"));
  
          invokers.add(redInvoker);
          invokers.add(yellowInvoker);
          invokers.add(blueInvoker);
          invokers.add(defaultInvoker);
  
          Router tagRouter = new TagRouter();
          List<Invoker<String>> filteredInvokers = tagRouter.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
          Assert.assertTrue(filteredInvokers.contains(redInvoker));
          Assert.assertFalse(filteredInvokers.contains(yellowInvoker));
          Assert.assertFalse(filteredInvokers.contains(blueInvoker));
          Assert.assertFalse(filteredInvokers.contains(defaultInvoker));
      }
test_case.class_method_signature: TagRouterTest.testRoute_matchTag()
test_case.full_signature: @Test public void testRoute_matchTag()
test_case.identifier: testRoute_matchTag
test_case.invocations: setAttachment getContext valueOf valueOf valueOf valueOf add add add add route valueOf getLocalHost assertTrue contains assertFalse contains assertFalse contains assertFalse contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRoute_matchTag()
focal_class.declarator: DEFAULT_PRIORITY = 100
focal_class.modifier: private static final
focal_class.original_string: private static final int DEFAULT_PRIORITY = 100;
focal_class.type: int
focal_class.var_name: DEFAULT_PRIORITY
focal_class.declarator: ROUTER_URL = new URL("tag", Constants.ANYHOST_VALUE, 0, Constants.ANY_VALUE).addParameters(Constants.RUNTIME_KEY, "true")
focal_class.modifier: private static final
focal_class.original_string: private static final URL ROUTER_URL = new URL("tag", Constants.ANYHOST_VALUE, 0, Constants.ANY_VALUE).addParameters(Constants.RUNTIME_KEY, "true");
focal_class.type: URL
focal_class.var_name: ROUTER_URL
focal_class.file: dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/router/tag/TagRouter.java
focal_class.identifier: TagRouter
focal_class.class_method_signature: TagRouter.TagRouter()
focal_class.full_signature: public  TagRouter()
focal_class.identifier: TagRouter
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  TagRouter()
focal_class.class_method_signature: TagRouter.getUrl()
focal_class.full_signature: @Override public URL getUrl()
focal_class.identifier: getUrl
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: URL
focal_class.signature: URL getUrl()
focal_class.class_method_signature: TagRouter.route(List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_class.full_signature: @Override public List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_class.identifier: route
focal_class.modifiers: @Override public
focal_class.parameters: (List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_class.return: List<Invoker<T>>
focal_class.signature: List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_class.superclass: extends AbstractRouter
focal_method.body: @Override
      public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
          // filter
          List<Invoker<T>> result = new ArrayList<Invoker<T>>();
          // Dynamic param
          String tag = RpcContext.getContext().getAttachment(Constants.TAG_KEY);
          // Tag request
          if (!StringUtils.isEmpty(tag)) {
              // Select tag invokers first
              for (Invoker<T> invoker : invokers) {
                  if (tag.equals(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
                      result.add(invoker);
                  }
              }
          }
          // If Constants.REQUEST_TAG_KEY unspecified or no invoker be selected, downgrade to normal invokers
          if (result.isEmpty()) {
              // Only forceTag = true force match, otherwise downgrade
              String forceTag = RpcContext.getContext().getAttachment(Constants.FORCE_USE_TAG);
              if (StringUtils.isEmpty(forceTag) || "false".equals(forceTag)) {
                  for (Invoker<T> invoker : invokers) {
                      if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
                          result.add(invoker);
                      }
                  }
              }
          }
          return result;
      }
focal_method.class_method_signature: TagRouter.route(List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_method.full_signature: @Override public List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_method.identifier: route
focal_method.invocations: getAttachment getContext isEmpty equals getParameter getUrl add isEmpty getAttachment getContext isEmpty equals isEmpty getParameter getUrl add
focal_method.modifiers: @Override public
focal_method.parameters: (List<Invoker<T>> invokers, URL url, Invocation invocation)
focal_method.return: List<Invoker<T>>
focal_method.signature: List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation)