Skip to content
Snippets Groups Projects
Commit 6ee83c77 authored by pantianying's avatar pantianying
Browse files

repair according to code review

parent 3ce09055
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ package tag ...@@ -19,6 +19,7 @@ package tag
import ( import (
perrors "github.com/pkg/errors" perrors "github.com/pkg/errors"
"strconv"
) )
import ( import (
...@@ -67,7 +68,7 @@ func (c *tagRouter) Priority() int64 { ...@@ -67,7 +68,7 @@ func (c *tagRouter) Priority() int64 {
func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker { func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker {
if tag, ok := invocation.Attachments()[constant.Tagkey]; ok { if tag, ok := invocation.Attachments()[constant.Tagkey]; ok {
result := make([]protocol.Invoker, 0) result := make([]protocol.Invoker, 0, 8)
for _, v := range invokers { for _, v := range invokers {
if v.GetUrl().GetParam(constant.Tagkey, "") == tag { if v.GetUrl().GetParam(constant.Tagkey, "") == tag {
result = append(result, v) result = append(result, v)
...@@ -82,8 +83,8 @@ func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocati ...@@ -82,8 +83,8 @@ func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocati
} }
} }
func isForceUseTag(url *common.URL, invocation protocol.Invocation) bool { func isForceUseTag(url *common.URL, invocation protocol.Invocation) bool {
if invocation.AttachmentsByKey(constant.ForceUseTag, url.GetParam(constant.ForceUseTag, "false")) == "true" { if b, e := strconv.ParseBool(invocation.AttachmentsByKey(constant.ForceUseTag, url.GetParam(constant.ForceUseTag, "false"))); e == nil {
return true return b
} }
return false return false
} }
...@@ -19,11 +19,17 @@ package tag ...@@ -19,11 +19,17 @@ package tag
import ( import (
"context" "context"
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation" "github.com/apache/dubbo-go/protocol/invocation"
"github.com/stretchr/testify/assert"
"testing"
) )
type MockInvoker struct { type MockInvoker struct {
...@@ -100,6 +106,10 @@ func TestTagRouter_Route_force(t *testing.T) { ...@@ -100,6 +106,10 @@ func TestTagRouter_Route_force(t *testing.T) {
inv.SetAttachments("dubbo.tag", "guangzhou") inv.SetAttachments("dubbo.tag", "guangzhou")
invRst2 := tagRouter.Route(invokers, &u1, inv) invRst2 := tagRouter.Route(invokers, &u1, inv)
assert.Equal(t, 0, len(invRst2)) assert.Equal(t, 0, len(invRst2))
inv.SetAttachments("dubbo.force.tag", "false")
inv.SetAttachments("dubbo.tag", "guangzhou")
invRst3 := tagRouter.Route(invokers, &u1, inv)
assert.Equal(t, 3, len(invRst3))
} }
func TestTagRouter_Route_noForce(t *testing.T) { func TestTagRouter_Route_noForce(t *testing.T) {
...@@ -129,4 +139,7 @@ func TestTagRouter_Route_noForce(t *testing.T) { ...@@ -129,4 +139,7 @@ func TestTagRouter_Route_noForce(t *testing.T) {
inv.SetAttachments("dubbo.force.tag", "true") inv.SetAttachments("dubbo.force.tag", "true")
invRst1 := tagRouter.Route(invokers, &u1, inv) invRst1 := tagRouter.Route(invokers, &u1, inv)
assert.Equal(t, 0, len(invRst1)) assert.Equal(t, 0, len(invRst1))
inv.SetAttachments("dubbo.force.tag", "false")
invRst2 := tagRouter.Route(invokers, &u1, inv)
assert.Equal(t, 3, len(invRst2))
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment