Skip to content
Snippets Groups Projects
Unverified Commit 89e3beea authored by Joe Zou's avatar Joe Zou Committed by GitHub
Browse files

Merge pull request #628 from watermelo/feature/optCodesForProtocolDir

Mod: code linter warnings
parents 25501260 51df26a4
No related branches found
No related tags found
No related merge requests found
Showing
with 106 additions and 97 deletions
...@@ -37,7 +37,13 @@ import ( ...@@ -37,7 +37,13 @@ import (
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
) )
func TestClient_CallOneway(t *testing.T) { const (
mockMethodNameGetUser = "GetUser"
mockMethodNameGetBigPkg = "GetBigPkg"
mockAddress = "127.0.0.1:20000"
)
func TestClientCallOneway(t *testing.T) {
proto, url := InitTest(t) proto, url := InitTest(t)
c := &Client{ c := &Client{
...@@ -50,15 +56,14 @@ func TestClient_CallOneway(t *testing.T) { ...@@ -50,15 +56,14 @@ func TestClient_CallOneway(t *testing.T) {
} }
c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL)) c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
//user := &User{} err := c.CallOneway(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil))
err := c.CallOneway(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil))
assert.NoError(t, err) assert.NoError(t, err)
// destroy // destroy
proto.Destroy() proto.Destroy()
} }
func TestClient_Call(t *testing.T) { func TestClientCall(t *testing.T) {
proto, url := InitTest(t) proto, url := InitTest(t)
c := &Client{ c := &Client{
...@@ -77,50 +82,50 @@ func TestClient_Call(t *testing.T) { ...@@ -77,50 +82,50 @@ func TestClient_Call(t *testing.T) {
) )
user = &User{} user = &User{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetBigPkg", []interface{}{nil}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, mockMethodNameGetBigPkg, []interface{}{nil}, nil), NewResponse(user, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.NotEqual(t, "", user.Id) assert.NotEqual(t, "", user.Id)
assert.NotEqual(t, "", user.Name) assert.NotEqual(t, "", user.Name)
user = &User{} user = &User{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil), NewResponse(user, nil))
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{} user = &User{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser0", []interface{}{"1", nil, "username"}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser0", []interface{}{"1", nil, "username"}, nil), NewResponse(user, nil))
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)
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser1", []interface{}{}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser1", []interface{}{}, nil), NewResponse(user, nil))
assert.NoError(t, err) assert.NoError(t, err)
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser2", []interface{}{}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser2", []interface{}{}, nil), NewResponse(user, nil))
assert.EqualError(t, err, "error") assert.EqualError(t, err, "error")
user2 := []interface{}{} user2 := []interface{}{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser3", []interface{}{}, nil), NewResponse(&user2, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser3", []interface{}{}, nil), NewResponse(&user2, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0]) assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0])
user2 = []interface{}{} user2 = []interface{}{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser4", []interface{}{[]interface{}{"1", "username"}}, nil), NewResponse(&user2, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser4", []interface{}{[]interface{}{"1", "username"}}, nil), NewResponse(&user2, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0]) assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0])
user3 := map[interface{}]interface{}{} user3 := map[interface{}]interface{}{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser5", []interface{}{map[interface{}]interface{}{"id": "1", "name": "username"}}, nil), NewResponse(&user3, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser5", []interface{}{map[interface{}]interface{}{"id": "1", "name": "username"}}, nil), NewResponse(&user3, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, user3) assert.NotNil(t, user3)
assert.Equal(t, &User{Id: "1", Name: "username"}, user3["key"]) assert.Equal(t, &User{Id: "1", Name: "username"}, user3["key"])
user = &User{} user = &User{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser6", []interface{}{0}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser6", []interface{}{0}, nil), NewResponse(user, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, User{Id: "", Name: ""}, *user) assert.Equal(t, User{Id: "", Name: ""}, *user)
user = &User{} user = &User{}
err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser6", []interface{}{1}, nil), NewResponse(user, nil)) err = c.Call(NewRequest(mockAddress, url, "GetUser6", []interface{}{1}, nil), NewResponse(user, nil))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: ""}, *user) assert.Equal(t, User{Id: "1", Name: ""}, *user)
...@@ -128,7 +133,7 @@ func TestClient_Call(t *testing.T) { ...@@ -128,7 +133,7 @@ func TestClient_Call(t *testing.T) {
proto.Destroy() proto.Destroy()
} }
func TestClient_AsyncCall(t *testing.T) { func TestClientAsyncCall(t *testing.T) {
proto, url := InitTest(t) proto, url := InitTest(t)
c := &Client{ c := &Client{
...@@ -144,7 +149,7 @@ func TestClient_AsyncCall(t *testing.T) { ...@@ -144,7 +149,7 @@ func TestClient_AsyncCall(t *testing.T) {
user := &User{} user := &User{}
lock := sync.Mutex{} lock := sync.Mutex{}
lock.Lock() lock.Lock()
err := c.AsyncCall(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil), func(response common.CallbackResponse) { err := c.AsyncCall(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil), func(response common.CallbackResponse) {
r := response.(AsyncCallbackResponse) r := response.(AsyncCallbackResponse)
assert.Equal(t, User{Id: "1", Name: "username"}, *r.Reply.(*Response).reply.(*User)) assert.Equal(t, User{Id: "1", Name: "username"}, *r.Reply.(*Response).reply.(*User))
lock.Unlock() lock.Unlock()
......
...@@ -29,7 +29,7 @@ import ( ...@@ -29,7 +29,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { func TestDubboPackageMarshalAndUnmarshal(t *testing.T) {
pkg := &DubboPackage{} pkg := &DubboPackage{}
pkg.Body = []interface{}{"a"} pkg.Body = []interface{}{"a"}
pkg.Header.Type = hessian.PackageHeartbeat pkg.Header.Type = hessian.PackageHeartbeat
......
...@@ -35,7 +35,7 @@ import ( ...@@ -35,7 +35,7 @@ import (
"github.com/apache/dubbo-go/protocol/invocation" "github.com/apache/dubbo-go/protocol/invocation"
) )
func TestDubboInvoker_Invoke(t *testing.T) { func TestDubboInvokerInvoke(t *testing.T) {
proto, url := InitTest(t) proto, url := InitTest(t)
c := &Client{ c := &Client{
...@@ -51,7 +51,7 @@ func TestDubboInvoker_Invoke(t *testing.T) { ...@@ -51,7 +51,7 @@ func TestDubboInvoker_Invoke(t *testing.T) {
invoker := NewDubboInvoker(url, c) invoker := NewDubboInvoker(url, c)
user := &User{} user := &User{}
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("GetUser"), invocation.WithArguments([]interface{}{"1", "username"}), inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(mockMethodNameGetUser), invocation.WithArguments([]interface{}{"1", "username"}),
invocation.WithReply(user), invocation.WithAttachments(map[string]string{"test_key": "test_value"})) invocation.WithReply(user), invocation.WithAttachments(map[string]string{"test_key": "test_value"}))
// Call // Call
......
...@@ -31,15 +31,19 @@ import ( ...@@ -31,15 +31,19 @@ import (
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
) )
func TestDubboProtocol_Export(t *testing.T) { const (
// Export mockCommonUrl = "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
proto := GetProtocol()
srvConf = &ServerConfig{}
url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245") "side=provider&timeout=3000&timestamp=1556509797245"
)
func TestDubboProtocolExport(t *testing.T) {
// Export
proto := GetProtocol()
srvConf = &ServerConfig{}
url, err := common.NewURL(mockCommonUrl)
assert.NoError(t, err) assert.NoError(t, err)
exporter := proto.Export(protocol.NewBaseInvoker(url)) exporter := proto.Export(protocol.NewBaseInvoker(url))
...@@ -48,11 +52,7 @@ func TestDubboProtocol_Export(t *testing.T) { ...@@ -48,11 +52,7 @@ func TestDubboProtocol_Export(t *testing.T) {
assert.True(t, eq) assert.True(t, eq)
// second service: the same path and the different version // second service: the same path and the different version
url2, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+ url2, err := common.NewURL(mockCommonUrl, common.WithParamsValue(constant.VERSION_KEY, "v1.1"))
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&"+
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"+
"side=provider&timeout=3000&timestamp=1556509797245", common.WithParamsValue(constant.VERSION_KEY, "v1.1"))
assert.NoError(t, err) assert.NoError(t, err)
exporter2 := proto.Export(protocol.NewBaseInvoker(url2)) exporter2 := proto.Export(protocol.NewBaseInvoker(url2))
// make sure url // make sure url
...@@ -74,14 +74,10 @@ func TestDubboProtocol_Export(t *testing.T) { ...@@ -74,14 +74,10 @@ func TestDubboProtocol_Export(t *testing.T) {
assert.False(t, ok) assert.False(t, ok)
} }
func TestDubboProtocol_Refer(t *testing.T) { func TestDubboProtocolRefer(t *testing.T) {
// Refer // Refer
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL(mockCommonUrl)
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
clientConf = &ClientConfig{} clientConf = &ClientConfig{}
invoker := proto.Refer(url) invoker := proto.Refer(url)
......
...@@ -106,7 +106,7 @@ func dubboGreeterSayHelloHandler(srv interface{}, ctx context.Context, ...@@ -106,7 +106,7 @@ func dubboGreeterSayHelloHandler(srv interface{}, ctx context.Context,
Server: srv, Server: srv,
FullMethod: "/helloworld.Greeter/SayHello", FullMethod: "/helloworld.Greeter/SayHello",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(context.Context, interface{}) (interface{}, error) {
result := base.GetProxyImpl().Invoke(context.Background(), invo) result := base.GetProxyImpl().Invoke(context.Background(), invo)
return result.Result(), result.Error() return result.Result(), result.Error()
} }
......
...@@ -33,11 +33,19 @@ import ( ...@@ -33,11 +33,19 @@ import (
"github.com/apache/dubbo-go/protocol/invocation" "github.com/apache/dubbo-go/protocol/invocation"
) )
const (
mockGrpcCommonUrl = "grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl" +
"&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter" +
"&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=" +
"&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown&registry.role=3&remote.timestamp=1576923717&retries=" +
"&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider&timestamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!"
)
func TestInvoke(t *testing.T) { func TestInvoke(t *testing.T) {
go internal.InitGrpcServer() go internal.InitGrpcServer()
defer internal.ShutdownGrpcServer() defer internal.ShutdownGrpcServer()
url, err := common.NewURL("grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown&registry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider&timestamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!") url, err := common.NewURL(mockGrpcCommonUrl)
assert.Nil(t, err) assert.Nil(t, err)
cli := NewClient(url) cli := NewClient(url)
......
...@@ -32,12 +32,12 @@ import ( ...@@ -32,12 +32,12 @@ import (
"github.com/apache/dubbo-go/protocol/grpc/internal" "github.com/apache/dubbo-go/protocol/grpc/internal"
) )
func TestGrpcProtocol_Export(t *testing.T) { func TestGrpcProtocolExport(t *testing.T) {
// Export // Export
addService() addService()
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("grpc://127.0.0.1:40000/GrpcGreeterImpl?accesslog=&app.version=0.0.1&application=BDTService&bean.name=GrpcGreeterImpl&cluster=failover&environment=dev&execute.limit=&execute.limit.rejected.handler=&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&registry.role=3&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&timestamp=1576923717&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100") url, err := common.NewURL(mockGrpcCommonUrl)
assert.NoError(t, err) assert.NoError(t, err)
exporter := proto.Export(protocol.NewBaseInvoker(url)) exporter := proto.Export(protocol.NewBaseInvoker(url))
time.Sleep(time.Second) time.Sleep(time.Second)
...@@ -61,13 +61,13 @@ func TestGrpcProtocol_Export(t *testing.T) { ...@@ -61,13 +61,13 @@ func TestGrpcProtocol_Export(t *testing.T) {
assert.False(t, ok) assert.False(t, ok)
} }
func TestGrpcProtocol_Refer(t *testing.T) { func TestGrpcProtocolRefer(t *testing.T) {
go internal.InitGrpcServer() go internal.InitGrpcServer()
defer internal.ShutdownGrpcServer() defer internal.ShutdownGrpcServer()
time.Sleep(time.Second) time.Sleep(time.Second)
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown&registry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider&timestamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!") url, err := common.NewURL(mockGrpcCommonUrl)
assert.NoError(t, err) assert.NoError(t, err)
invoker := proto.Refer(url) invoker := proto.Refer(url)
......
...@@ -48,7 +48,15 @@ type ( ...@@ -48,7 +48,15 @@ type (
} }
) )
func TestHTTPClient_Call(t *testing.T) { const (
mockJsonCommonUrl = "jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245&bean.name=UserProvider"
)
func TestHTTPClientCall(t *testing.T) {
methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", &UserProvider{}) methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
...@@ -56,11 +64,7 @@ func TestHTTPClient_Call(t *testing.T) { ...@@ -56,11 +64,7 @@ func TestHTTPClient_Call(t *testing.T) {
// Export // Export
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" + url, err := common.NewURL(mockJsonCommonUrl)
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245&bean.name=UserProvider")
assert.NoError(t, err) assert.NoError(t, err)
proto.Export(&proxy_factory.ProxyInvoker{ proto.Export(&proxy_factory.ProxyInvoker{
BaseInvoker: *protocol.NewBaseInvoker(url), BaseInvoker: *protocol.NewBaseInvoker(url),
......
...@@ -124,10 +124,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { ...@@ -124,10 +124,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) {
if param != nil { if param != nil {
switch k := reflect.TypeOf(param).Kind(); k { switch k := reflect.TypeOf(param).Kind(); k {
case reflect.Map: case reflect.Map:
if reflect.TypeOf(param).Key().Kind() == reflect.String { if reflect.TypeOf(param).Key().Kind() == reflect.String && reflect.ValueOf(param).IsNil() {
if reflect.ValueOf(param).IsNil() { param = nil
param = nil
}
} }
case reflect.Slice: case reflect.Slice:
if reflect.ValueOf(param).IsNil() { if reflect.ValueOf(param).IsNil() {
...@@ -137,10 +135,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { ...@@ -137,10 +135,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) {
case reflect.Ptr: case reflect.Ptr:
switch ptrK := reflect.TypeOf(param).Elem().Kind(); ptrK { switch ptrK := reflect.TypeOf(param).Elem().Kind(); ptrK {
case reflect.Map: case reflect.Map:
if reflect.TypeOf(param).Elem().Key().Kind() == reflect.String { if reflect.TypeOf(param).Elem().Key().Kind() == reflect.String && reflect.ValueOf(param).Elem().IsNil() {
if reflect.ValueOf(param).Elem().IsNil() { param = nil
param = nil
}
} }
case reflect.Slice: case reflect.Slice:
if reflect.ValueOf(param).Elem().IsNil() { if reflect.ValueOf(param).Elem().IsNil() {
......
...@@ -30,7 +30,7 @@ type TestData struct { ...@@ -30,7 +30,7 @@ type TestData struct {
Test string Test string
} }
func TestJsonClientCodec_Write(t *testing.T) { func TestJsonClientCodecWrite(t *testing.T) {
cd := &CodecData{ cd := &CodecData{
ID: 1, ID: 1,
Method: "GetUser", Method: "GetUser",
...@@ -46,7 +46,7 @@ func TestJsonClientCodec_Write(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestJsonClientCodec_Write(t *testing.T) {
assert.EqualError(t, err, "unsupported param type: int") assert.EqualError(t, err, "unsupported param type: int")
} }
func TestJsonClientCodec_Read(t *testing.T) { func TestJsonClientCodecRead(t *testing.T) {
codec := newJsonClientCodec() codec := newJsonClientCodec()
codec.pending[1] = "GetUser" codec.pending[1] = "GetUser"
rsp := &TestData{} rsp := &TestData{}
...@@ -60,7 +60,7 @@ func TestJsonClientCodec_Read(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestJsonClientCodec_Read(t *testing.T) {
assert.EqualError(t, err, "{\"code\":-32000,\"message\":\"error\"}") assert.EqualError(t, err, "{\"code\":-32000,\"message\":\"error\"}")
} }
func TestServerCodec_Write(t *testing.T) { func TestServerCodecWrite(t *testing.T) {
codec := newServerCodec() codec := newServerCodec()
a := json.RawMessage([]byte("1")) a := json.RawMessage([]byte("1"))
codec.req = serverRequest{Version: "1.0", Method: "GetUser", ID: &a} codec.req = serverRequest{Version: "1.0", Method: "GetUser", ID: &a}
...@@ -73,7 +73,7 @@ func TestServerCodec_Write(t *testing.T) { ...@@ -73,7 +73,7 @@ func TestServerCodec_Write(t *testing.T) {
assert.Equal(t, "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"Test\":\"test\"},\"error\":{\"code\":-32000,\"message\":\"error\"}}\n", string(data)) assert.Equal(t, "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"Test\":\"test\"},\"error\":{\"code\":-32000,\"message\":\"error\"}}\n", string(data))
} }
func TestServerCodec_Read(t *testing.T) { func TestServerCodecRead(t *testing.T) {
codec := newServerCodec() codec := newServerCodec()
header := map[string]string{} header := map[string]string{}
err := codec.ReadHeader(header, []byte("{\"jsonrpc\":\"2.0\",\"method\":\"GetUser\",\"params\":[\"args\",2],\"id\":1}\n")) err := codec.ReadHeader(header, []byte("{\"jsonrpc\":\"2.0\",\"method\":\"GetUser\",\"params\":[\"args\",2],\"id\":1}\n"))
......
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
"github.com/apache/dubbo-go/protocol/invocation" "github.com/apache/dubbo-go/protocol/invocation"
) )
func TestJsonrpcInvoker_Invoke(t *testing.T) { func TestJsonrpcInvokerInvoke(t *testing.T) {
methods, err := common.ServiceMap.Register("UserProvider", "jsonrpc", &UserProvider{}) methods, err := common.ServiceMap.Register("UserProvider", "jsonrpc", &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
......
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
) )
func TestJsonrpcProtocol_Export(t *testing.T) { func TestJsonrpcProtocolExport(t *testing.T) {
// Export // Export
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
...@@ -65,7 +65,7 @@ func TestJsonrpcProtocol_Export(t *testing.T) { ...@@ -65,7 +65,7 @@ func TestJsonrpcProtocol_Export(t *testing.T) {
assert.False(t, ok) assert.False(t, ok)
} }
func TestJsonrpcProtocol_Refer(t *testing.T) { func TestJsonrpcProtocolRefer(t *testing.T) {
// Refer // Refer
proto := GetProtocol() proto := GetProtocol()
url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
......
...@@ -45,5 +45,5 @@ func (pfw *mockProtocolFilter) Refer(url common.URL) protocol.Invoker { ...@@ -45,5 +45,5 @@ func (pfw *mockProtocolFilter) Refer(url common.URL) protocol.Invoker {
// Destroy will do nothing // Destroy will do nothing
func (pfw *mockProtocolFilter) Destroy() { func (pfw *mockProtocolFilter) Destroy() {
return
} }
...@@ -36,7 +36,7 @@ import ( ...@@ -36,7 +36,7 @@ import (
"github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol"
) )
func TestProtocolFilterWrapper_Export(t *testing.T) { func TestProtocolFilterWrapperExport(t *testing.T) {
filtProto := extension.GetProtocol(FILTER) filtProto := extension.GetProtocol(FILTER)
filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{} filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{}
...@@ -48,7 +48,7 @@ func TestProtocolFilterWrapper_Export(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestProtocolFilterWrapper_Export(t *testing.T) {
assert.True(t, ok) assert.True(t, ok)
} }
func TestProtocolFilterWrapper_Refer(t *testing.T) { func TestProtocolFilterWrapperRefer(t *testing.T) {
filtProto := extension.GetProtocol(FILTER) filtProto := extension.GetProtocol(FILTER)
filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{} filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{}
......
...@@ -50,7 +50,7 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient { ...@@ -50,7 +50,7 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient {
client := resty.New() client := resty.New()
client.SetTransport( client.SetTransport(
&http.Transport{ &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { DialContext: func(_ context.Context, network, addr string) (net.Conn, error) {
c, err := net.DialTimeout(network, addr, restOption.ConnectTimeout) c, err := net.DialTimeout(network, addr, restOption.ConnectTimeout)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
"github.com/apache/dubbo-go/protocol/rest/config" "github.com/apache/dubbo-go/protocol/rest/config"
) )
func TestRestConfigReader_ReadConsumerConfig(t *testing.T) { func TestRestConfigReaderReadConsumerConfig(t *testing.T) {
bs, err := yaml.LoadYMLConfig("./testdata/consumer_config.yml") bs, err := yaml.LoadYMLConfig("./testdata/consumer_config.yml")
assert.NoError(t, err) assert.NoError(t, err)
configReader := NewRestConfigReader() configReader := NewRestConfigReader()
...@@ -40,7 +40,7 @@ func TestRestConfigReader_ReadConsumerConfig(t *testing.T) { ...@@ -40,7 +40,7 @@ func TestRestConfigReader_ReadConsumerConfig(t *testing.T) {
assert.NotEmpty(t, config.GetRestConsumerServiceConfigMap()) assert.NotEmpty(t, config.GetRestConsumerServiceConfigMap())
} }
func TestRestConfigReader_ReadProviderConfig(t *testing.T) { func TestRestConfigReaderReadProviderConfig(t *testing.T) {
bs, err := yaml.LoadYMLConfig("./testdata/provider_config.yml") bs, err := yaml.LoadYMLConfig("./testdata/provider_config.yml")
assert.NoError(t, err) assert.NoError(t, err)
configReader := NewRestConfigReader() configReader := NewRestConfigReader()
......
...@@ -39,7 +39,15 @@ import ( ...@@ -39,7 +39,15 @@ import (
"github.com/apache/dubbo-go/protocol/rest/server/server_impl" "github.com/apache/dubbo-go/protocol/rest/server/server_impl"
) )
func TestRestInvoker_Invoke(t *testing.T) { const (
mockRestCommonUrl = "rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245"
)
func TestRestInvokerInvoke(t *testing.T) {
// Refer // Refer
proto := GetRestProtocol() proto := GetRestProtocol()
defer proto.Destroy() defer proto.Destroy()
...@@ -55,11 +63,7 @@ func TestRestInvoker_Invoke(t *testing.T) { ...@@ -55,11 +63,7 @@ func TestRestInvoker_Invoke(t *testing.T) {
chain.ProcessFilter(request, response) chain.ProcessFilter(request, response)
}) })
url, err := common.NewURL("rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL(mockRestCommonUrl)
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
_, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
......
...@@ -38,14 +38,10 @@ import ( ...@@ -38,14 +38,10 @@ import (
rest_config "github.com/apache/dubbo-go/protocol/rest/config" rest_config "github.com/apache/dubbo-go/protocol/rest/config"
) )
func TestRestProtocol_Refer(t *testing.T) { func TestRestProtocolRefer(t *testing.T) {
// Refer // Refer
proto := GetRestProtocol() proto := GetRestProtocol()
url, err := common.NewURL("rest://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL(mockRestCommonUrl)
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
con := config.ConsumerConfig{ con := config.ConsumerConfig{
ConnectTimeout: 5 * time.Second, ConnectTimeout: 5 * time.Second,
...@@ -71,14 +67,10 @@ func TestRestProtocol_Refer(t *testing.T) { ...@@ -71,14 +67,10 @@ func TestRestProtocol_Refer(t *testing.T) {
assert.Equal(t, 0, invokersLen) assert.Equal(t, 0, invokersLen)
} }
func TestRestProtocol_Export(t *testing.T) { func TestRestProtocolExport(t *testing.T) {
// Export // Export
proto := GetRestProtocol() proto := GetRestProtocol()
url, err := common.NewURL("rest://127.0.0.1:8888/com.ikurento.user.UserProvider?anyhost=true&" + url, err := common.NewURL(mockRestCommonUrl)
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err) assert.NoError(t, err)
_, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{})
assert.NoError(t, err) assert.NoError(t, err)
......
...@@ -170,12 +170,12 @@ func CurrentTimeMillis() int64 { ...@@ -170,12 +170,12 @@ func CurrentTimeMillis() int64 {
// Destroy is used to clean all status // Destroy is used to clean all status
func CleanAllStatus() { func CleanAllStatus() {
delete1 := func(key interface{}, value interface{}) bool { delete1 := func(key, _ interface{}) bool {
methodStatistics.Delete(key) methodStatistics.Delete(key)
return true return true
} }
methodStatistics.Range(delete1) methodStatistics.Range(delete1)
delete2 := func(key interface{}, value interface{}) bool { delete2 := func(key, _ interface{}) bool {
serviceStatistic.Delete(key) serviceStatistic.Delete(key)
return true return true
} }
......
...@@ -30,10 +30,14 @@ import ( ...@@ -30,10 +30,14 @@ import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
) )
const (
mockCommonDubboUrl = "dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider"
)
func TestBeginCount(t *testing.T) { func TestBeginCount(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
BeginCount(url, "test") BeginCount(url, "test")
urlStatus := GetURLStatus(url) urlStatus := GetURLStatus(url)
methodStatus := GetMethodStatus(url, "test") methodStatus := GetMethodStatus(url, "test")
...@@ -47,7 +51,7 @@ func TestBeginCount(t *testing.T) { ...@@ -47,7 +51,7 @@ func TestBeginCount(t *testing.T) {
func TestEndCount(t *testing.T) { func TestEndCount(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
EndCount(url, "test", 100, true) EndCount(url, "test", 100, true)
urlStatus := GetURLStatus(url) urlStatus := GetURLStatus(url)
methodStatus := GetMethodStatus(url, "test") methodStatus := GetMethodStatus(url, "test")
...@@ -60,7 +64,7 @@ func TestEndCount(t *testing.T) { ...@@ -60,7 +64,7 @@ func TestEndCount(t *testing.T) {
func TestGetMethodStatus(t *testing.T) { func TestGetMethodStatus(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
status := GetMethodStatus(url, "test") status := GetMethodStatus(url, "test")
assert.NotNil(t, status) assert.NotNil(t, status)
assert.Equal(t, int32(0), status.total) assert.Equal(t, int32(0), status.total)
...@@ -69,25 +73,25 @@ func TestGetMethodStatus(t *testing.T) { ...@@ -69,25 +73,25 @@ func TestGetMethodStatus(t *testing.T) {
func TestGetUrlStatus(t *testing.T) { func TestGetUrlStatus(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
status := GetURLStatus(url) status := GetURLStatus(url)
assert.NotNil(t, status) assert.NotNil(t, status)
assert.Equal(t, int32(0), status.total) assert.Equal(t, int32(0), status.total)
} }
func Test_beginCount0(t *testing.T) { func TestbeginCount0(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
status := GetURLStatus(url) status := GetURLStatus(url)
beginCount0(status) beginCount0(status)
assert.Equal(t, int32(1), status.active) assert.Equal(t, int32(1), status.active)
} }
func Test_All(t *testing.T) { func TestAll(t *testing.T) {
defer CleanAllStatus() defer CleanAllStatus()
url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") url, _ := common.NewURL(mockCommonDubboUrl)
request(url, "test", 100, false, true) request(url, "test", 100, false, true)
urlStatus := GetURLStatus(url) urlStatus := GetURLStatus(url)
methodStatus := GetMethodStatus(url, "test") methodStatus := GetMethodStatus(url, "test")
......
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