diff --git a/protocol/motanProtocol.go b/protocol/motanProtocol.go index 789db413..b5b32ecd 100644 --- a/protocol/motanProtocol.go +++ b/protocol/motanProtocol.go @@ -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 ( @@ -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) == "" { diff --git a/protocol/motanProtocol_test.go b/protocol/motanProtocol_test.go index 81563f16..9195ee48 100644 --- a/protocol/motanProtocol_test.go +++ b/protocol/motanProtocol_test.go @@ -499,6 +499,52 @@ func TestConvertToRequest(t *testing.T) { } } +func TestConvertToReqMessage(t *testing.T) { + // 创建一个模拟的请求 + 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, "") + + // 设置RPC上下文 + rc := request.GetRPCContext(true) + rc.Serialized = false + rc.Oneway = true + rc.Proxy = true + rc.GzipSize = 1024 + + // 使用SimpleSerialization进行序列化 + serialization := &serialize.SimpleSerialization{} + + // 调用ConvertToReqMessage + msg, err := ConvertToReqMessage(request, serialization) + + // 断言 + 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)) + + // 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)