Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: [refer dubbo 2.7.6] attachment type from map[string]stiring to map[string]interface{} #713

Merged
merged 18 commits into from
Sep 7, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package proxy

import (
"context"
hessian "github.com/apache/dubbo-go-hessian2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG. move it to the second import block, pls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"github.com/apache/dubbo-go/protocol/invocation"
"reflect"
"testing"
)
Expand All @@ -40,6 +42,7 @@ type TestService struct {
MethodThree func(int, bool) (interface{}, error)
MethodFour func(int, bool) (*interface{}, error) `dubbo:"methodFour"`
MethodFive func() error
MethodSix func(context.Context, string) (interface{}, error)
Echo func(interface{}, *interface{}) error
}

Expand Down Expand Up @@ -120,3 +123,34 @@ func TestProxyImplement(t *testing.T) {
assert.Nil(t, s3.MethodOne)

}

func TestProxyImplementForContext(t *testing.T) {
invoker := &TestProxyInvoker{
BaseInvoker: *protocol.NewBaseInvoker(common.URL{}),
}
p := NewProxy(invoker, nil, map[string]string{constant.ASYNC_KEY: "false"})
s := &TestService{}
p.Implement(s)
attahments1 := make(map[string]interface{}, 4)
attahments1["k1"] = "v1"
attahments1["k2"] = "v2"
context := context.WithValue(context.Background(), constant.AttachmentKey, attahments1)
r, err := p.Get().(*TestService).MethodSix(context, "xxx")
v1 := r.(map[string]interface{})
assert.NoError(t, err)
assert.Equal(t, v1["TestProxyInvoker"], "TestProxyInvokerValue")
}

type TestProxyInvoker struct {
protocol.BaseInvoker
}

func (bi *TestProxyInvoker) Invoke(context context.Context, inv protocol.Invocation) protocol.Result {
rpcInv := inv.(*invocation.RPCInvocation)
mapV := inv.Attachments()
mapV["TestProxyInvoker"] = "TestProxyInvokerValue"
hessian.ReflectResponse(mapV, rpcInv.Reply())
return &protocol.RPCResult{
Rest: inv.Arguments(),
}
}