Skip to content
Snippets Groups Projects
Commit ebece398 authored by fangyincheng's avatar fangyincheng
Browse files

Tst&Mod:add test & formatting code

parent 2565b400
Branches
Tags
No related merge requests found
...@@ -12,11 +12,14 @@ import ( ...@@ -12,11 +12,14 @@ import (
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common"
"github.com/dubbo/go-for-apache-dubbo/common/constant"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
) )
type TestService struct { type TestService struct {
MethodOne func(context.Context, []interface{}, *struct{}) error MethodOne func(context.Context, []interface{}, *struct{}) error
MethodTwo func([]interface{}, *struct{}) error
Echo func([]interface{}, *struct{}) error
} }
func (s *TestService) Service() string { func (s *TestService) Service() string {
...@@ -26,18 +29,30 @@ func (s *TestService) Version() string { ...@@ -26,18 +29,30 @@ func (s *TestService) Version() string {
return "" return ""
} }
type TestServiceInt int
func (s *TestServiceInt) Service() string {
return "com.test.TestServiceInt"
}
func (s *TestServiceInt) Version() string {
return ""
}
func TestProxy_Implement(t *testing.T) { func TestProxy_Implement(t *testing.T) {
invoker := protocol.NewBaseInvoker(common.URL{}) invoker := protocol.NewBaseInvoker(common.URL{})
p := NewProxy(invoker, nil, nil) p := NewProxy(invoker, nil, map[string]string{constant.ASYNC_KEY: "false"})
s := &TestService{MethodOne: func(i context.Context, i2 []interface{}, i3 *struct{}) error { s := &TestService{}
return errors.New("errors")
}}
p.Implement(s) p.Implement(s)
err := p.Get().(*TestService).MethodOne(nil, nil, nil) err := p.Get().(*TestService).MethodOne(nil, nil, nil)
assert.NoError(t, err) assert.NoError(t, err)
err = p.Get().(*TestService).MethodTwo(nil, nil)
assert.NoError(t, err)
err = p.Get().(*TestService).Echo(nil, nil)
assert.NoError(t, err)
// inherit & lowercase // inherit & lowercase
p.rpc = nil
type S1 struct { type S1 struct {
TestService TestService
methodOne func(context.Context, []interface{}, *struct{}) error methodOne func(context.Context, []interface{}, *struct{}) error
...@@ -51,7 +66,14 @@ func TestProxy_Implement(t *testing.T) { ...@@ -51,7 +66,14 @@ func TestProxy_Implement(t *testing.T) {
err = s1.methodOne(nil, nil, nil) err = s1.methodOne(nil, nil, nil)
assert.EqualError(t, err, "errors") assert.EqualError(t, err, "errors")
// no struct
p.rpc = nil
it := TestServiceInt(1)
p.Implement(&it)
assert.Nil(t, p.rpc)
// args number // args number
p.rpc = nil
type S2 struct { type S2 struct {
TestService TestService
MethodOne func([]interface{}) error MethodOne func([]interface{}) error
...@@ -61,6 +83,7 @@ func TestProxy_Implement(t *testing.T) { ...@@ -61,6 +83,7 @@ func TestProxy_Implement(t *testing.T) {
assert.Nil(t, s2.MethodOne) assert.Nil(t, s2.MethodOne)
// returns number // returns number
p.rpc = nil
type S3 struct { type S3 struct {
TestService TestService
MethodOne func(context.Context, []interface{}, *struct{}) (interface{}, error) MethodOne func(context.Context, []interface{}, *struct{}) (interface{}, error)
...@@ -70,6 +93,7 @@ func TestProxy_Implement(t *testing.T) { ...@@ -70,6 +93,7 @@ func TestProxy_Implement(t *testing.T) {
assert.Nil(t, s3.MethodOne) assert.Nil(t, s3.MethodOne)
// returns type // returns type
p.rpc = nil
type S4 struct { type S4 struct {
TestService TestService
MethodOne func(context.Context, []interface{}, *struct{}) interface{} MethodOne func(context.Context, []interface{}, *struct{}) interface{}
...@@ -79,6 +103,7 @@ func TestProxy_Implement(t *testing.T) { ...@@ -79,6 +103,7 @@ func TestProxy_Implement(t *testing.T) {
assert.Nil(t, s4.MethodOne) assert.Nil(t, s4.MethodOne)
// reply type for number 3 // reply type for number 3
p.rpc = nil
type S5 struct { type S5 struct {
TestService TestService
MethodOne func(context.Context, []interface{}, interface{}) error MethodOne func(context.Context, []interface{}, interface{}) error
...@@ -88,6 +113,7 @@ func TestProxy_Implement(t *testing.T) { ...@@ -88,6 +113,7 @@ func TestProxy_Implement(t *testing.T) {
assert.Nil(t, s5.MethodOne) assert.Nil(t, s5.MethodOne)
// reply type for number 2 // reply type for number 2
p.rpc = nil
type S6 struct { type S6 struct {
TestService TestService
MethodOne func([]interface{}, interface{}) error MethodOne func([]interface{}, interface{}) error
......
...@@ -222,7 +222,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { ...@@ -222,7 +222,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
length := len(consumerConfig.References) length := len(consumerConfig.References)
for index := 0; index < length; index++ { for index := 0; index < length; index++ {
con := &consumerConfig.References[index] con := &consumerConfig.References[index]
rpcService := conServices[con.InterfaceName] rpcService := GetConService(con.InterfaceName)
if rpcService == nil { if rpcService == nil {
log.Warn("%s is not exsist!", con.InterfaceName) log.Warn("%s is not exsist!", con.InterfaceName)
continue continue
...@@ -241,7 +241,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { ...@@ -241,7 +241,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
length := len(providerConfig.Services) length := len(providerConfig.Services)
for index := 0; index < length; index++ { for index := 0; index < length; index++ {
pro := &providerConfig.Services[index] pro := &providerConfig.Services[index]
rpcService := proServices[pro.InterfaceName] rpcService := GetProService(pro.InterfaceName)
if rpcService == nil { if rpcService == nil {
log.Warn("%s is not exsist!", pro.InterfaceName) log.Warn("%s is not exsist!", pro.InterfaceName)
continue continue
......
package config package config
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common"
"path/filepath" "path/filepath"
"testing" "testing"
) )
...@@ -9,6 +10,11 @@ import ( ...@@ -9,6 +10,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
import (
"github.com/dubbo/go-for-apache-dubbo/cluster/cluster_impl"
"github.com/dubbo/go-for-apache-dubbo/common/extension"
)
func TestConfigLoader(t *testing.T) { func TestConfigLoader(t *testing.T) {
conPath, err := filepath.Abs("./consumer_config.yml") conPath, err := filepath.Abs("./consumer_config.yml")
assert.NoError(t, err) assert.NoError(t, err)
...@@ -30,3 +36,25 @@ func TestConfigLoader(t *testing.T) { ...@@ -30,3 +36,25 @@ func TestConfigLoader(t *testing.T) {
assert.NotNil(t, providerConfig) assert.NotNil(t, providerConfig)
assert.NotEqual(t, ProviderConfig{}, GetProviderConfig()) assert.NotEqual(t, ProviderConfig{}, GetProviderConfig())
} }
func TestLoad(t *testing.T) {
doInit()
doinit()
SetConService(&MockService{})
SetProService(&MockService{})
extension.SetProtocol("registry", GetProtocol)
extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster)
consumerConfig.References[0].Registries = []ConfigRegistry{"shanghai_reg1"}
refConfigs, svcConfigs := Load()
assert.NotEqual(t, 0, len(refConfigs))
assert.NotEqual(t, 0, len(svcConfigs))
conServices = map[string]common.RPCService{}
proServices = map[string]common.RPCService{}
common.ServiceMap.UnRegister("mock", "MockService")
consumerConfig = nil
providerConfig = nil
}
...@@ -6,7 +6,7 @@ type MockService struct { ...@@ -6,7 +6,7 @@ type MockService struct {
} }
func (*MockService) Service() string { func (*MockService) Service() string {
return "mockservice" return "MockService"
} }
func (*MockService) Version() string { func (*MockService) Version() string {
return "1.0" return "1.0"
......
...@@ -61,7 +61,7 @@ func doInit() { ...@@ -61,7 +61,7 @@ func doInit() {
}, },
References: []ReferenceConfig{ References: []ReferenceConfig{
{ {
InterfaceName: "testInterface", InterfaceName: "MockService",
Protocol: "mock", Protocol: "mock",
Registries: []ConfigRegistry{"shanghai_reg1", "shanghai_reg2", "hangzhou_reg1", "hangzhou_reg2"}, Registries: []ConfigRegistry{"shanghai_reg1", "shanghai_reg2", "hangzhou_reg1", "hangzhou_reg2"},
Cluster: "failover", Cluster: "failover",
......
...@@ -55,7 +55,7 @@ func doinit() { ...@@ -55,7 +55,7 @@ func doinit() {
}, },
Services: []ServiceConfig{ Services: []ServiceConfig{
{ {
InterfaceName: "testInterface", InterfaceName: "MockService",
Protocol: "mock", Protocol: "mock",
Registries: []ConfigRegistry{"shanghai_reg1", "shanghai_reg2", "hangzhou_reg1", "hangzhou_reg2"}, Registries: []ConfigRegistry{"shanghai_reg1", "shanghai_reg2", "hangzhou_reg1", "hangzhou_reg2"},
Cluster: "failover", Cluster: "failover",
......
...@@ -83,38 +83,38 @@ type CallOptions struct { ...@@ -83,38 +83,38 @@ type CallOptions struct {
type CallOption func(*CallOptions) type CallOption func(*CallOptions)
func WithCallRequestTimeout(d time.Duration) CallOption { //func WithCallRequestTimeout(d time.Duration) CallOption {
return func(o *CallOptions) { // return func(o *CallOptions) {
o.RequestTimeout = d // o.RequestTimeout = d
} // }
} //}
//
func WithCallResponseTimeout(d time.Duration) CallOption { //func WithCallResponseTimeout(d time.Duration) CallOption {
return func(o *CallOptions) { // return func(o *CallOptions) {
o.ResponseTimeout = d // o.ResponseTimeout = d
} // }
} //}
//
func WithCallSerialID(s SerialID) CallOption { //func WithCallSerialID(s SerialID) CallOption {
return func(o *CallOptions) { // return func(o *CallOptions) {
o.SerialID = s // o.SerialID = s
} // }
} //}
//
func WithCallMeta_All(callMeta map[interface{}]interface{}) CallOption { //func WithCallMeta_All(callMeta map[interface{}]interface{}) CallOption {
return func(o *CallOptions) { // return func(o *CallOptions) {
o.Meta = callMeta // o.Meta = callMeta
} // }
} //}
func WithCallMeta(k, v interface{}) CallOption { //func WithCallMeta(k, v interface{}) CallOption {
return func(o *CallOptions) { // return func(o *CallOptions) {
if o.Meta == nil { // if o.Meta == nil {
o.Meta = make(map[interface{}]interface{}) // o.Meta = make(map[interface{}]interface{})
} // }
o.Meta[k] = v // o.Meta[k] = v
} // }
} //}
type CallResponse struct { type CallResponse struct {
Opts CallOptions Opts CallOptions
...@@ -210,11 +210,14 @@ func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string ...@@ -210,11 +210,14 @@ func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string
var rsp *PendingResponse var rsp *PendingResponse
if ct != CT_OneWay { if ct != CT_OneWay {
p.Header.Type = hessian.PackageRequest_TwoWay
rsp = NewPendingResponse() rsp = NewPendingResponse()
rsp.reply = reply rsp.reply = reply
rsp.callback = callback rsp.callback = callback
rsp.opts = opts rsp.opts = opts
} }
// todo: it must be PackageRequest because of hessian2, but it is twoway actually
p.Header.Type = hessian.PackageRequest
var ( var (
err error err error
...@@ -281,8 +284,6 @@ func (c *Client) transfer(session getty.Session, pkg *DubboPackage, ...@@ -281,8 +284,6 @@ func (c *Client) transfer(session getty.Session, pkg *DubboPackage,
pkg.Body = []interface{}{} pkg.Body = []interface{}{}
pkg.Header.Type = hessian.PackageHeartbeat pkg.Header.Type = hessian.PackageHeartbeat
pkg.Header.SerialID = byte(S_Dubbo) pkg.Header.SerialID = byte(S_Dubbo)
} else {
pkg.Header.Type = hessian.PackageRequest
} }
pkg.Header.ID = int64(sequence) pkg.Header.ID = int64(sequence)
......
...@@ -3,13 +3,13 @@ package dubbo ...@@ -3,13 +3,13 @@ package dubbo
import ( import (
"context" "context"
"errors" "errors"
"github.com/dubbogo/hessian2"
"sync" "sync"
"testing" "testing"
"time" "time"
) )
import ( import (
"github.com/dubbogo/hessian2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -60,6 +60,11 @@ func TestClient_Call(t *testing.T) { ...@@ -60,6 +60,11 @@ func TestClient_Call(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: "username"}, *user) assert.Equal(t, User{Id: "1", Name: "username"}, *user)
user = &User{}
err = c.Call("127.0.0.1:20000", url, "GetUser0", []interface{}{"1", "username"}, user)
assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: "username"}, *user)
// destroy // destroy
proto.Destroy() proto.Destroy()
} }
...@@ -95,7 +100,7 @@ func InitTest(t *testing.T) (protocol.Protocol, common.URL) { ...@@ -95,7 +100,7 @@ func InitTest(t *testing.T) (protocol.Protocol, common.URL) {
methods, err := common.ServiceMap.Register("dubbo", &UserProvider{}) methods, err := common.ServiceMap.Register("dubbo", &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "GetUser,GetUser1", methods) assert.Equal(t, "GetUser,GetUser0,GetUser1", methods)
// config // config
SetClientConf(ClientConfig{ SetClientConf(ClientConfig{
...@@ -153,6 +158,8 @@ func InitTest(t *testing.T) (protocol.Protocol, common.URL) { ...@@ -153,6 +158,8 @@ func InitTest(t *testing.T) (protocol.Protocol, common.URL) {
assert.NoError(t, err) assert.NoError(t, err)
proto.Export(protocol.NewBaseInvoker(url)) proto.Export(protocol.NewBaseInvoker(url))
time.Sleep(time.Second * 2)
return proto, url return proto, url
} }
...@@ -162,6 +169,12 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User ...@@ -162,6 +169,12 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User
return nil return nil
} }
func (u *UserProvider) GetUser0(req []interface{}, rsp *User) error {
rsp.Id = req[0].(string)
rsp.Name = req[1].(string)
return nil
}
func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error { func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error {
return errors.New("error") return errors.New("error")
} }
......
...@@ -53,17 +53,17 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { ...@@ -53,17 +53,17 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result {
} else { } else {
result.Err = di.client.CallOneway(url.Location, url, inv.MethodName(), inv.Arguments()) result.Err = di.client.CallOneway(url.Location, url, inv.MethodName(), inv.Arguments())
} }
log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest)
} else { } else {
if inv.Reply() == nil { if inv.Reply() == nil {
result.Err = Err_No_Reply result.Err = Err_No_Reply
} else { } else {
result.Err = di.client.Call(url.Location, url, inv.MethodName(), inv.Arguments(), inv.Reply()) result.Err = di.client.Call(url.Location, url, inv.MethodName(), inv.Arguments(), inv.Reply())
result.Rest = inv.Reply() // reply should be set to result.Rest when sync
} }
log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest)
} }
if result.Err == nil {
result.Rest = inv.Reply()
}
log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest)
return &result return &result
} }
......
...@@ -183,11 +183,11 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { ...@@ -183,11 +183,11 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
return return
} }
twoway := true
// not twoway // not twoway
if p.Header.Type&hessian.PackageRequest_TwoWay == 0x00 { if p.Header.Type&hessian.PackageRequest_TwoWay == 0x00 {
twoway = false
h.reply(session, p, hessian.PackageResponse) h.reply(session, p, hessian.PackageResponse)
h.callService(p, nil)
return
} }
invoker := h.exporter.GetInvoker() invoker := h.exporter.GetInvoker()
...@@ -213,6 +213,9 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { ...@@ -213,6 +213,9 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
} }
h.callService(p, nil) h.callService(p, nil)
if !twoway {
return
}
h.reply(session, p, hessian.PackageResponse) h.reply(session, p, hessian.PackageResponse)
} }
......
...@@ -33,7 +33,7 @@ func TestHTTPClient_Call(t *testing.T) { ...@@ -33,7 +33,7 @@ func TestHTTPClient_Call(t *testing.T) {
methods, err := common.ServiceMap.Register("jsonrpc", &UserProvider{}) methods, err := common.ServiceMap.Register("jsonrpc", &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "GetUser,GetUser1", methods) assert.Equal(t, "GetUser,GetUser0,GetUser1", methods)
// Export // Export
proto := GetProtocol() proto := GetProtocol()
...@@ -44,11 +44,9 @@ func TestHTTPClient_Call(t *testing.T) { ...@@ -44,11 +44,9 @@ func TestHTTPClient_Call(t *testing.T) {
"side=provider&timeout=3000&timestamp=1556509797245") "side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
proto.Export(protocol.NewBaseInvoker(url)) proto.Export(protocol.NewBaseInvoker(url))
time.Sleep(time.Second * 2)
client := NewHTTPClient(&HTTPOptions{ client := NewHTTPClient(&HTTPOptions{})
HandshakeTimeout: time.Second,
HTTPTimeout: time.Second,
})
// call GetUser // call GetUser
ctx := context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{ ctx := context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
...@@ -63,6 +61,19 @@ func TestHTTPClient_Call(t *testing.T) { ...@@ -63,6 +61,19 @@ func TestHTTPClient_Call(t *testing.T) {
assert.Equal(t, "1", reply.Id) assert.Equal(t, "1", reply.Id)
assert.Equal(t, "username", reply.Name) assert.Equal(t, "username", reply.Name)
// call GetUser
ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
"X-Proxy-Id": "dubbogo",
"X-Services": url.Path,
"X-Method": "GetUser",
})
req = client.NewRequest(url, "GetUser0", []interface{}{"1", "username"})
reply = &User{}
err = client.Call(ctx, url, req, reply)
assert.NoError(t, err)
assert.Equal(t, "1", reply.Id)
assert.Equal(t, "username", reply.Name)
// call GetUser1 // call GetUser1
ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{ ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
"X-Proxy-Id": "dubbogo", "X-Proxy-Id": "dubbogo",
...@@ -86,6 +97,12 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User ...@@ -86,6 +97,12 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User
return nil return nil
} }
func (u *UserProvider) GetUser0(req []interface{}, rsp *User) error {
rsp.Id = req[0].(string)
rsp.Name = req[1].(string)
return nil
}
func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error { func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error {
return errors.New("error") return errors.New("error")
} }
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
import ( import (
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
) )
import ( import (
...@@ -42,13 +41,11 @@ func (ji *JsonrpcInvoker) Invoke(invocation protocol.Invocation) protocol.Result ...@@ -42,13 +41,11 @@ func (ji *JsonrpcInvoker) Invoke(invocation protocol.Invocation) protocol.Result
"X-Services": url.Path, "X-Services": url.Path,
"X-Method": inv.MethodName(), "X-Method": inv.MethodName(),
}) })
if err := ji.client.Call(ctx, url, req, inv.Reply()); err != nil { result.Err = ji.client.Call(ctx, url, req, inv.Reply())
log.Error("client.Call() return error:%+v", jerrors.ErrorStack(err)) if result.Err == nil {
result.Err = err
} else {
log.Debug("result: %v", inv.Reply())
result.Rest = inv.Reply() result.Rest = inv.Reply()
} }
log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest)
return &result return &result
} }
...@@ -2,7 +2,6 @@ package jsonrpc ...@@ -2,7 +2,6 @@ package jsonrpc
import ( import (
"context" "context"
"github.com/dubbo/go-for-apache-dubbo/protocol/invocation"
"testing" "testing"
"time" "time"
) )
...@@ -14,13 +13,14 @@ import ( ...@@ -14,13 +13,14 @@ import (
import ( import (
"github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common"
"github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol"
"github.com/dubbo/go-for-apache-dubbo/protocol/invocation"
) )
func TestJsonrpcInvoker_Invoke(t *testing.T) { func TestJsonrpcInvoker_Invoke(t *testing.T) {
methods, err := common.ServiceMap.Register("jsonrpc", &UserProvider{}) methods, err := common.ServiceMap.Register("jsonrpc", &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "GetUser,GetUser1", methods) assert.Equal(t, "GetUser,GetUser0,GetUser1", methods)
// Export // Export
proto := GetProtocol() proto := GetProtocol()
...@@ -31,6 +31,7 @@ func TestJsonrpcInvoker_Invoke(t *testing.T) { ...@@ -31,6 +31,7 @@ func TestJsonrpcInvoker_Invoke(t *testing.T) {
"side=provider&timeout=3000&timestamp=1556509797245") "side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
proto.Export(protocol.NewBaseInvoker(url)) proto.Export(protocol.NewBaseInvoker(url))
time.Sleep(time.Second * 2)
client := NewHTTPClient(&HTTPOptions{ client := NewHTTPClient(&HTTPOptions{
HandshakeTimeout: time.Second, HandshakeTimeout: time.Second,
......
...@@ -367,13 +367,24 @@ func serveRequest(ctx context.Context, ...@@ -367,13 +367,24 @@ func serveRequest(ctx context.Context,
replyv := reflect.New(mtype.ReplyType().Elem()) replyv := reflect.New(mtype.ReplyType().Elem())
// call service.method(args) // call service.method(args)
var errMsg string var (
returnValues := mtype.Method().Func.Call([]reflect.Value{ errMsg string
returnValues []reflect.Value
)
if mtype.CtxType() == nil {
returnValues = mtype.Method().Func.Call([]reflect.Value{
svc.Rcvr(),
reflect.ValueOf(argvTmp),
reflect.ValueOf(replyv.Interface()),
})
} else {
returnValues = mtype.Method().Func.Call([]reflect.Value{
svc.Rcvr(), svc.Rcvr(),
mtype.SuiteContext(ctx), mtype.SuiteContext(ctx),
reflect.ValueOf(argvTmp), reflect.ValueOf(argvTmp),
reflect.ValueOf(replyv.Interface()), reflect.ValueOf(replyv.Interface()),
}) })
}
// The return value for the method is an error. // The return value for the method is an error.
if retErr := returnValues[0].Interface(); retErr != nil { if retErr := returnValues[0].Interface(); retErr != nil {
errMsg = retErr.(error).Error() errMsg = retErr.(error).Error()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment