From 665a9629f5b4e19e8298d6969e756d41c5ddffa0 Mon Sep 17 00:00:00 2001 From: watermelo <80680489@qq.com> Date: Fri, 14 Aug 2020 10:26:17 +0800 Subject: [PATCH] Mod: add router tag unit tests scripts --- before_ut.bat | 3 +++ cluster/router/tag/tag_router.go | 32 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/before_ut.bat b/before_ut.bat index 5d2b9e468..7f5cf50e9 100644 --- a/before_ut.bat +++ b/before_ut.bat @@ -36,5 +36,8 @@ xcopy /f "%zkJar%" "cluster/router/chain/zookeeper-4unittest/contrib/fatjar/" md cluster\router\condition\zookeeper-4unittest\contrib\fatjar xcopy /f "%zkJar%" "cluster/router/condition/zookeeper-4unittest/contrib/fatjar/" +mkdir -p cluster/router/tag/zookeeper-4unittest/contrib/fatjar +cp ${zkJar} cluster/router/tag/zookeeper-4unittest/contrib/fatjar + md metadata\report\zookeeper\zookeeper-4unittest\contrib\fatjar xcopy /f "%zkJar%" "metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar/" \ No newline at end of file diff --git a/cluster/router/tag/tag_router.go b/cluster/router/tag/tag_router.go index 1a4b74d48..bd5c35952 100644 --- a/cluster/router/tag/tag_router.go +++ b/cluster/router/tag/tag_router.go @@ -221,29 +221,27 @@ func filterInvokersWithTag(invokers []protocol.Invoker, url *common.URL, invocat if len(result) > 0 || tagRouterRule.Force { return result } - } else { - // dynamic tag group doesn't have any item about the requested app OR it's null after filtered by - // dynamic tag group but force=false. check static tag - filter := func(invoker protocol.Invoker) bool { - return invoker.GetUrl().GetParam(constant.Tagkey, "") == tag - } - result = filterInvoker(invokers, filter) } + // dynamic tag group doesn't have any item about the requested app OR it's null after filtered by + // dynamic tag group but force=false. check static tag + filter := func(invoker protocol.Invoker) bool { + return invoker.GetUrl().GetParam(constant.Tagkey, "") == tag + } + result = filterInvoker(invokers, filter) // If there's no tagged providers that can match the current tagged request. force.tag is set by default // to false, which means it will invoke any providers without a tag unless it's explicitly disallowed. if len(result) > 0 || isForceUseTag(url, invocation) { return result - } else { - // FAILOVER: return all Providers without any tags. - filterAddressNotMatches := func(invoker protocol.Invoker) bool { - url := invoker.GetUrl() - return len(addresses) == 0 || !checkAddressMatch(tagRouterRule.getAddresses(), url.Ip, url.Port) - } - filterTagIsEmpty := func(invoker protocol.Invoker) bool { - return invoker.GetUrl().GetParam(constant.Tagkey, "") == "" - } - return filterInvoker(invokers, filterAddressNotMatches, filterTagIsEmpty) } + // FAILOVER: return all Providers without any tags. + filterAddressNotMatches := func(invoker protocol.Invoker) bool { + url := invoker.GetUrl() + return len(addresses) == 0 || !checkAddressMatch(tagRouterRule.getAddresses(), url.Ip, url.Port) + } + filterTagIsEmpty := func(invoker protocol.Invoker) bool { + return invoker.GetUrl().GetParam(constant.Tagkey, "") == "" + } + return filterInvoker(invokers, filterAddressNotMatches, filterTagIsEmpty) } // isForceUseTag returns whether force use tag -- GitLab