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

fix ConvertToReqMessage #408

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions protocol/motanProtocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"

motan "github.com/weibocom/motan-go/core"
"github.com/weibocom/motan-go/log"
vlog "github.com/weibocom/motan-go/log"
)

const (
Expand Down Expand Up @@ -689,7 +689,6 @@ func ConvertToReqMessage(request motan.Request, serialize motan.Serialization) (
if rc.Proxy {
req.Header.SetProxy(true)
}
req.Header.SetSerialize(serialize.GetSerialNum())
req.Metadata.Store(MPath, request.GetServiceName())
req.Metadata.Store(MMethod, request.GetMethod())
if request.GetAttachment(MProxyProtocol) == "" {
Expand Down
46 changes: 46 additions & 0 deletions protocol/motanProtocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,52 @@ func TestConvertToRequest(t *testing.T) {
}
}

func TestConvertToReqMessage(t *testing.T) {
// create mock request
request := core.AcquireMotanRequest()
request.RequestID = 12345
request.ServiceName = "testService"
request.Method = "testMethod"
request.MethodDesc = "testMethodDesc"
request.Attachment = core.NewStringMap(0)
request.Attachment.Store(MGroup, "testGroup")
request.Attachment.Store(MProxyProtocol, "")

// set RpcContext
rc := request.GetRPCContext(true)
rc.Serialized = false
rc.Oneway = true
rc.Proxy = true
rc.GzipSize = 1024

// use SimpleSerialization as the serialization param
serialization := &serialize.SimpleSerialization{}
// call ConvertToReqMessage
msg, err := ConvertToReqMessage(request, serialization)

// assert msg
assert.Nil(t, err)
assert.NotNil(t, msg)
assert.Equal(t, request.RequestID, msg.Header.RequestID)
assert.True(t, msg.Header.IsOneWay())
assert.True(t, msg.Header.IsProxy())
assert.Equal(t, serialization.GetSerialNum(), msg.Header.GetSerialize())
assert.Equal(t, "testService", msg.Metadata.LoadOrEmpty(MPath))
assert.Equal(t, "testMethod", msg.Metadata.LoadOrEmpty(MMethod))
assert.Equal(t, "motan2", msg.Metadata.LoadOrEmpty(MProxyProtocol))
assert.Equal(t, "testMethodDesc", msg.Metadata.LoadOrEmpty(MMethodDesc))
assert.Equal(t, "testGroup", msg.Metadata.LoadOrEmpty(MGroup))

// use rc serialize
rc.Serialized = true
rc.SerializeNum = serialize.BreezeNumber
msg, err = ConvertToReqMessage(request, serialization)

assert.Nil(t, err)
assert.NotNil(t, msg)
assert.Equal(t, serialize.BreezeNumber, msg.Header.GetSerialize())
}

func BenchmarkEncodeGzip(b *testing.B) {
DefaultGzipLevel = gzip.BestSpeed
bs := buildBytes(10 * 1024)
Expand Down
Loading